Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroyable - Add new sparks parameter value of "near" #1405

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 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,12 +356,13 @@ public DestroyableHealthChange handleBlockChange(
NMS_HACKS.skipFireworksLaunch(firework);
}

// Players more than 64m away will not see or hear the fireworks, so just play the sound
// for them
for (MatchPlayer listener : this.getOwner().getMatch().getPlayers()) {
if (listener.getBukkit().getLocation().distance(blockLocation) > 64) {
listener.playSound(Sounds.OBJECTIVE_FIREWORKS_FAR);
listener.playSound(Sounds.OBJECTIVE_FIREWORKS_TWINKLE);
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(Sounds.OBJECTIVE_FIREWORKS_FAR);
listener.playSound(Sounds.OBJECTIVE_FIREWORKS_TWINKLE);
}
}
}
}
Expand Down
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,15 +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 SparksType sparks;
protected final boolean repairable;

public DestroyableFactory(
Expand All @@ -33,15 +56,17 @@ public DestroyableFactory(
double destructionRequired,
@Nullable ImmutableSet<Mode> modeList,
boolean showProgress,
boolean sparks,
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.sparks = SparksType.fromString(sparks, el);
this.repairable = repairable;
}

Expand All @@ -65,8 +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 isSparksAll() {
return this.sparks != SparksType.SPARKS_NEAR;
}

public boolean isRepairable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +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);
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 @@ -147,7 +149,8 @@ public DestroyableModule parse(MapFactory context, Logger logger, Document doc)
modeSet,
showProgress,
sparks,
repairable);
repairable,
destroyableEl);

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