Skip to content

Commit

Permalink
Sparks - Review updates
Browse files Browse the repository at this point in the history
Signed-off-by: arcadeboss <[email protected]>
  • Loading branch information
arcadeboss committed Oct 3, 2024
1 parent 46d15ab commit b3438f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
35 changes: 8 additions & 27 deletions core/src/main/java/tc/oc/pgm/destroyable/DestroyableFactory.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -56,17 +39,15 @@ public DestroyableFactory(
double destructionRequired,
@Nullable ImmutableSet<Mode> 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;
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit b3438f7

Please sign in to comment.