From 8506bebac5e7231e9ea260124fcb97625493c1cc Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Fri, 17 Mar 2023 22:27:40 +0100 Subject: [PATCH] Fix respawn filter parsing being stateful (#1159) Signed-off-by: Pablo Herrera --- .../java/tc/oc/pgm/spawns/SpawnModule.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/spawns/SpawnModule.java b/core/src/main/java/tc/oc/pgm/spawns/SpawnModule.java index a838f74eac..ff35234413 100644 --- a/core/src/main/java/tc/oc/pgm/spawns/SpawnModule.java +++ b/core/src/main/java/tc/oc/pgm/spawns/SpawnModule.java @@ -49,8 +49,6 @@ public SpawnMatchModule createMatchModule(Match match) { public static class Factory implements MapModuleFactory { - private FilterParser filterParser; - @Override public Collection>> getSoftDependencies() { return ImmutableList.of(RegionModule.class, KitModule.class); @@ -64,7 +62,7 @@ public Collection>> 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 spawns = Lists.newArrayList(); @@ -76,15 +74,17 @@ 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 parseRespawnOptions(Document doc) throws InvalidXMLException { + private List parseRespawnOptions(Document doc, FilterParser filterParser) + throws InvalidXMLException { List 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 @@ -92,17 +92,22 @@ private List parseRespawnOptions(Document doc) throws InvalidXML 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 elements, boolean autorespawn, boolean topLevel) + Collection elements, + boolean autorespawn, + boolean topLevel, + FilterParser filterParser) throws InvalidXMLException { Duration delay = DEFAULT_RESPAWN_DELAY; boolean auto = autorespawn;