From b3438f7a84cd91a0c45f342e220638e763272410 Mon Sep 17 00:00:00 2001 From: arcadeboss Date: Thu, 3 Oct 2024 02:14:25 +0000 Subject: [PATCH] Sparks - Review updates Signed-off-by: arcadeboss --- .../pgm/destroyable/DestroyableFactory.java | 35 +++++-------------- .../oc/pgm/destroyable/DestroyableModule.java | 9 +++-- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/destroyable/DestroyableFactory.java b/core/src/main/java/tc/oc/pgm/destroyable/DestroyableFactory.java index eef0844027..d7184af2db 100644 --- a/core/src/main/java/tc/oc/pgm/destroyable/DestroyableFactory.java +++ b/core/src/main/java/tc/oc/pgm/destroyable/DestroyableFactory.java @@ -1,7 +1,6 @@ package tc.oc.pgm.destroyable; import com.google.common.collect.ImmutableSet; -import org.jdom2.Element; import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.feature.FeatureInfo; import tc.oc.pgm.api.region.Region; @@ -11,29 +10,13 @@ import tc.oc.pgm.modes.Mode; import tc.oc.pgm.teams.TeamFactory; import tc.oc.pgm.util.material.MaterialMatcher; -import tc.oc.pgm.util.xml.InvalidXMLException; @FeatureInfo(name = "destroyable") public class DestroyableFactory extends ProximityGoalDefinition { public static enum SparksType { - SPARKS_ALL("true"), - SPARKS_NONE("false"), - SPARKS_NEAR("near"); - - private final String name; - - private SparksType(String name) { - this.name = name; - } - - public static SparksType fromString(String name, Element el) throws InvalidXMLException { - for (SparksType i : SparksType.values()) { - if (i.name.equalsIgnoreCase(name)) { - return i; - } - } - throw new InvalidXMLException("Unknown Destroyable sparks type: " + name, el); - } + FALSE, // none + NEAR, // normal sparks + TRUE; // normal/far sparks } protected final Region region; @@ -56,17 +39,15 @@ public DestroyableFactory( double destructionRequired, @Nullable ImmutableSet modeList, boolean showProgress, - String sparks, - boolean repairable, - Element el) - throws InvalidXMLException { + SparksType sparks, + boolean repairable) { super(id, name, required, showOptions, owner, proximityMetric); this.region = region; this.materials = materials; this.destructionRequired = destructionRequired; this.modeList = modeList; this.showProgress = showProgress; - this.sparks = SparksType.fromString(sparks, el); + this.sparks = sparks; this.repairable = repairable; } @@ -91,11 +72,11 @@ public boolean getShowProgress() { } public boolean isSparksActive() { - return this.sparks != SparksType.SPARKS_NONE; + return this.sparks != SparksType.FALSE; } public boolean isSparksAll() { - return this.sparks != SparksType.SPARKS_NEAR; + return this.sparks == SparksType.TRUE; } public boolean isRepairable() { diff --git a/core/src/main/java/tc/oc/pgm/destroyable/DestroyableModule.java b/core/src/main/java/tc/oc/pgm/destroyable/DestroyableModule.java index 7f81cfa6e0..165cfdbf7a 100644 --- a/core/src/main/java/tc/oc/pgm/destroyable/DestroyableModule.java +++ b/core/src/main/java/tc/oc/pgm/destroyable/DestroyableModule.java @@ -18,6 +18,7 @@ import tc.oc.pgm.api.match.MatchModule; import tc.oc.pgm.api.region.Region; import tc.oc.pgm.blockdrops.BlockDropsModule; +import tc.oc.pgm.destroyable.DestroyableFactory.SparksType; import tc.oc.pgm.goals.GoalMatchModule; import tc.oc.pgm.goals.ProximityMetric; import tc.oc.pgm.goals.ShowOptions; @@ -127,9 +128,8 @@ public DestroyableModule parse(MapFactory context, Logger logger, Document doc) boolean showProgress = XMLUtils.parseBoolean(destroyableEl.getAttribute("show-progress"), false); - String sparks = destroyableEl.getAttributeValue("sparks") != null - ? destroyableEl.getAttributeValue("sparks") - : "false"; + SparksType sparks = XMLUtils.parseEnum( + Node.fromAttr(destroyableEl, "sparks"), SparksType.class, SparksType.FALSE); boolean repairable = XMLUtils.parseBoolean(destroyableEl.getAttribute("repairable"), true); ShowOptions options = ShowOptions.parse(context.getFilters(), destroyableEl); Boolean required = XMLUtils.parseBoolean(destroyableEl.getAttribute("required"), null); @@ -149,8 +149,7 @@ public DestroyableModule parse(MapFactory context, Logger logger, Document doc) modeSet, showProgress, sparks, - repairable, - destroyableEl); + repairable); context.getFeatures().addFeature(destroyableEl, factory); destroyables.add(factory);