Skip to content

Commit

Permalink
Destroyable - Remove sparks-match, Add new sparks value 'near'
Browse files Browse the repository at this point in the history
Signed-off-by: arcadeboss <[email protected]>
  • Loading branch information
arcadeboss committed Oct 1, 2024
1 parent 216b7fd commit 46d15ab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
10 changes: 4 additions & 6 deletions core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public DestroyableHealthChange handleBlockChange(
if (deltaHealth < 0) {
touch(player);

if (this.definition.hasSparks()) {
if (this.definition.isSparksActive()) {
Location blockLocation = BlockVectors.center(oldState);
Instant now = Instant.now();

Expand All @@ -356,14 +356,12 @@ public DestroyableHealthChange handleBlockChange(
NMS_HACKS.skipFireworksLaunch(firework);
}

if (this.definition.hasSparksMatch()) {
if (this.definition.isSparksAll()) {
// Players more than 64m away will not see or hear the fireworks, so play sound for them
for (MatchPlayer listener : this.getOwner().getMatch().getPlayers()) {
if (listener.getBukkit().getLocation().distance(blockLocation) > 64) {
listener.playSound(
sound(key("fireworks.blast_far"), Sound.Source.MASTER, 0.75f, 1f));
listener.playSound(
sound(key("fireworks.twinkle_far"), Sound.Source.MASTER, 0.75f, 1f));
listener.playSound(Sounds.OBJECTIVE_FIREWORKS_FAR);
listener.playSound(Sounds.OBJECTIVE_FIREWORKS_TWINKLE);
}
}
}
Expand Down
44 changes: 33 additions & 11 deletions core/src/main/java/tc/oc/pgm/destroyable/DestroyableFactory.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -10,16 +11,37 @@
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);
}
}

protected final Region region;
protected final MaterialMatcher materials;
protected final double destructionRequired;
protected final ImmutableSet<Mode> modeList;
protected final boolean showProgress;
protected final boolean sparks;
protected final boolean sparksMatch;
protected final SparksType sparks;
protected final boolean repairable;

public DestroyableFactory(
Expand All @@ -34,17 +56,17 @@ public DestroyableFactory(
double destructionRequired,
@Nullable ImmutableSet<Mode> modeList,
boolean showProgress,
boolean sparks,
boolean sparksMatch,
boolean repairable) {
String sparks,
boolean repairable,
Element el)
throws InvalidXMLException {
super(id, name, required, showOptions, owner, proximityMetric);
this.region = region;
this.materials = materials;
this.destructionRequired = destructionRequired;
this.modeList = modeList;
this.showProgress = showProgress;
this.sparks = sparks;
this.sparksMatch = sparksMatch;
this.sparks = SparksType.fromString(sparks, el);
this.repairable = repairable;
}

Expand All @@ -68,12 +90,12 @@ public boolean getShowProgress() {
return this.showProgress;
}

public boolean hasSparks() {
return this.sparks;
public boolean isSparksActive() {
return this.sparks != SparksType.SPARKS_NONE;
}

public boolean hasSparksMatch() {
return this.sparksMatch;
public boolean isSparksAll() {
return this.sparks != SparksType.SPARKS_NEAR;
}

public boolean isRepairable() {
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/tc/oc/pgm/destroyable/DestroyableModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ public DestroyableModule parse(MapFactory context, Logger logger, Document doc)

boolean showProgress =
XMLUtils.parseBoolean(destroyableEl.getAttribute("show-progress"), false);
boolean sparks = XMLUtils.parseBoolean(destroyableEl.getAttribute("sparks"), false);
boolean sparksMatch =
XMLUtils.parseBoolean(destroyableEl.getAttribute("sparks-match"), true);
String sparks = destroyableEl.getAttributeValue("sparks") != null
? destroyableEl.getAttributeValue("sparks")
: "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,8 @@ public DestroyableModule parse(MapFactory context, Logger logger, Document doc)
modeSet,
showProgress,
sparks,
sparksMatch,
repairable);
repairable,
destroyableEl);

context.getFeatures().addFeature(destroyableEl, factory);
destroyables.add(factory);
Expand Down

0 comments on commit 46d15ab

Please sign in to comment.