Skip to content

Commit

Permalink
Fix respawn filter parsing being stateful (#1159)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Mar 17, 2023
1 parent 979d99a commit 8506beb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions core/src/main/java/tc/oc/pgm/spawns/SpawnModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public SpawnMatchModule createMatchModule(Match match) {

public static class Factory implements MapModuleFactory<SpawnModule> {

private FilterParser filterParser;

@Override
public Collection<Class<? extends MapModule<?>>> getSoftDependencies() {
return ImmutableList.of(RegionModule.class, KitModule.class);
Expand All @@ -64,7 +62,7 @@ public Collection<Class<? extends MapModule<?>>> getWeakDependencies() {
@Override
public SpawnModule parse(MapFactory factory, Logger logger, Document doc)
throws InvalidXMLException {
this.filterParser = factory.getFilters();
FilterParser filterParser = factory.getFilters();
SpawnParser parser = new SpawnParser(factory, new PointParser(factory));
List<Spawn> spawns = Lists.newArrayList();

Expand All @@ -76,33 +74,40 @@ public SpawnModule parse(MapFactory factory, Logger logger, Document doc)
throw new InvalidXMLException("map must have a single default spawn", doc);
}

return new SpawnModule(parser.getDefaultSpawn(), spawns, parseRespawnOptions(doc));
return new SpawnModule(
parser.getDefaultSpawn(), spawns, parseRespawnOptions(doc, filterParser));
}

private List<RespawnOptions> parseRespawnOptions(Document doc) throws InvalidXMLException {
private List<RespawnOptions> parseRespawnOptions(Document doc, FilterParser filterParser)
throws InvalidXMLException {
List<RespawnOptions> respawnOptions = Lists.newArrayList();

for (Element elRespawn :
XMLUtils.flattenElements(doc.getRootElement(), "respawns", "respawn")) {
respawnOptions.add(getRespawnOptions(elRespawn));
respawnOptions.add(getRespawnOptions(elRespawn, filterParser));
}
// Parse root children respawn elements, Keeps old syntax and gives a default spawn if all
// others fail
respawnOptions.add(
getRespawnOptions(
doc.getRootElement().getChildren("respawn"),
doc.getRootElement().getChild("autorespawn") != null,
true));
true,
filterParser));

return respawnOptions;
}

private RespawnOptions getRespawnOptions(Element element) throws InvalidXMLException {
return getRespawnOptions(Collections.singleton(element), false, false);
private RespawnOptions getRespawnOptions(Element element, FilterParser filterParser)
throws InvalidXMLException {
return getRespawnOptions(Collections.singleton(element), false, false, filterParser);
}

protected RespawnOptions getRespawnOptions(
Collection<Element> elements, boolean autorespawn, boolean topLevel)
Collection<Element> elements,
boolean autorespawn,
boolean topLevel,
FilterParser filterParser)
throws InvalidXMLException {
Duration delay = DEFAULT_RESPAWN_DELAY;
boolean auto = autorespawn;
Expand Down

0 comments on commit 8506beb

Please sign in to comment.