Skip to content

Commit

Permalink
pre-initialize match state filters
Browse files Browse the repository at this point in the history
Signed-off-by: KingSimon <[email protected]>
  • Loading branch information
KingOfSquares committed Dec 20, 2020
1 parent d7b1e82 commit edc9769
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
21 changes: 6 additions & 15 deletions core/src/main/java/tc/oc/pgm/filters/FilterParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.jdom2.Element;
import tc.oc.pgm.api.filter.Filter;
import tc.oc.pgm.api.map.factory.MapFactory;
import tc.oc.pgm.api.match.MatchPhase;
import tc.oc.pgm.api.player.PlayerRelation;
import tc.oc.pgm.classes.ClassModule;
import tc.oc.pgm.classes.PlayerClass;
Expand Down Expand Up @@ -481,28 +480,20 @@ public Filter parseMatchFinished(Element el) throws InvalidXMLException {

private Filter parseMatchPhaseFilter(String matchState, Element el) throws InvalidXMLException {

MatchPhase matchPhase = null;

switch (matchState) {
case "running":
matchPhase = MatchPhase.RUNNING;
break;
return MatchPhaseFilter.RUNNING;
case "finished":
matchPhase = MatchPhase.FINISHED;
break;
return MatchPhaseFilter.FINISHED;
case "starting":
matchPhase = MatchPhase.STARTING;
break;
return MatchPhaseFilter.STARTING;
case "idle":
matchPhase = MatchPhase.IDLE;
break;
return MatchPhaseFilter.IDLE;
case "started":
return AnyFilter.of(
new MatchPhaseFilter(MatchPhase.RUNNING), new MatchPhaseFilter(MatchPhase.FINISHED));
return MatchPhaseFilter.STARTED;
}
if (matchPhase == null) throw new InvalidXMLException("Invalid or no match state found", el);

return new MatchPhaseFilter(matchPhase);
throw new InvalidXMLException("Invalid or no match state found", el);
}

// Methods for parsing QueryModifiers
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/tc/oc/pgm/filters/MatchPhaseFilter.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package tc.oc.pgm.filters;

import tc.oc.pgm.api.filter.Filter;
import tc.oc.pgm.api.filter.query.MatchQuery;
import tc.oc.pgm.api.match.MatchPhase;

public class MatchPhaseFilter extends TypedFilter<MatchQuery> {

public static final MatchPhaseFilter RUNNING = new MatchPhaseFilter(MatchPhase.RUNNING);
public static final MatchPhaseFilter FINISHED = new MatchPhaseFilter(MatchPhase.FINISHED);
public static final MatchPhaseFilter STARTING = new MatchPhaseFilter(MatchPhase.STARTING);
public static final MatchPhaseFilter IDLE = new MatchPhaseFilter(MatchPhase.IDLE);
public static final Filter STARTED =
AnyFilter.of(
new MatchPhaseFilter(MatchPhase.RUNNING), new MatchPhaseFilter(MatchPhase.FINISHED));

private final MatchPhase matchPhase;

public MatchPhaseFilter(MatchPhase matchPhase) {
Expand Down

0 comments on commit edc9769

Please sign in to comment.