Skip to content

Commit

Permalink
new playeffect special data handler, fixes #1859
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 11, 2018
1 parent 9493716 commit c60c204
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
Expand Up @@ -13,4 +13,8 @@ public interface Particle {
boolean isVisible();

String getName();

default Class neededData() {
return null;
}
}
Expand Up @@ -2757,7 +2757,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name PlayEffect
// @Syntax playeffect [effect:<name>] [at:<location>|...] (data:<#.#>) (visibility:<#.#>) (quantity:<#>) (offset:<#.#>,<#.#>,<#.#>) (targets:<player>|...)
// @Syntax playeffect [effect:<name>] [at:<location>|...] (data:<#.#>) (special_data:<data>) (visibility:<#.#>) (quantity:<#>) (offset:<#.#>,<#.#>,<#.#>) (targets:<player>|...)
// @Required 2
// @Stable stable
// @Short Plays a visible or audible effect at the location.
Expand All @@ -2778,6 +2778,9 @@ public void registerCoreMembers() {
// The distinction is in whether you include the (now expected to use) "at:" prefix on your location argument.
// If you do not have this prefix, the system will assume your command is older, and will apply the 1-block height offset.
//
// Some particles will require input to the "special_data" argument. The data input is unique per particle.
// - For REDSTONE particles, the input is of format: <size>|<color>, for example: "1.2|red". Color input is any valid dColor object.
//
// @Tags
// None
//
Expand Down
Expand Up @@ -5,10 +5,7 @@
import net.aufdemrand.denizen.nms.abstracts.ParticleHelper;
import net.aufdemrand.denizen.nms.interfaces.Effect;
import net.aufdemrand.denizen.nms.interfaces.Particle;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dMaterial;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
Expand Down Expand Up @@ -141,6 +138,10 @@ else if (!scriptEntry.hasObject("data")

scriptEntry.addObject("data", arg.asElement());
}
else if (!scriptEntry.hasObject("special_data")
&& arg.matchesOnePrefix("special_data")) {
scriptEntry.addObject("special_data", arg.asElement());
}
else if (!scriptEntry.hasObject("qty")
&& arg.matchesPrimitive(aH.PrimitiveType.Integer)
&& arg.matchesPrefix("qty", "q", "quantity")) {
Expand Down Expand Up @@ -212,6 +213,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element no_offset = scriptEntry.getElement("no_offset");
boolean should_offset = no_offset == null || !no_offset.asBoolean();
dLocation offset = scriptEntry.getdObject("offset");
Element special_data = scriptEntry.getElement("special_data");

// Report to dB
if (scriptEntry.dbCallShouldDebug()) {
Expand All @@ -226,6 +228,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
data.debug() +
qty.debug() +
offset.debug() +
(special_data != null ? special_data.debug() : "") +
(should_offset ? aH.debugObj("note", "Location will be offset 1 block-height upward (see documentation)") : ""));
}

Expand Down Expand Up @@ -273,7 +276,31 @@ else if (particleEffect != null) {
}
}
for (Player player : players) {
particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
Class clazz = particleEffect.neededData();
if (clazz == null) {
particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat());
}
else {
Object dataObject = null;
if (special_data == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing required special data for particle: " + particleEffect.getName());
}
else if (clazz == org.bukkit.Particle.DustOptions.class) {
dList dataList = dList.valueOf(special_data.asString());
if (dataList.size() != 2) {
dB.echoError(scriptEntry.getResidingQueue(), "DustOptions special_data must have 2 list entries for particle: " + particleEffect.getName());
}
else {
float size = aH.getFloatFrom(dataList.get(0));
dColor color = dColor.valueOf(dataList.get(1));
dataObject = new org.bukkit.Particle.DustOptions(color.getColor(), size);
}
}
else {
dB.echoError(scriptEntry.getResidingQueue(), "Unknown particle data type: " + clazz.getCanonicalName() + " for particle: " + particleEffect.getName());
}
particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), dataObject);
}
}
}

Expand Down
Expand Up @@ -16,6 +16,15 @@ public Particle_v1_13_R2(org.bukkit.Particle particle) {
this.particle = particle;
}

@Override
public Class neededData() {
Class clazz = particle.getDataType();
if (clazz == Void.class) {
return null;
}
return clazz;
}

@Override
public void playFor(Player player, Location location, int count, Vector offset, double extra) {
player.spawnParticle(particle, location, count, offset.getX(), offset.getY(), offset.getZ(), extra);
Expand Down

0 comments on commit c60c204

Please sign in to comment.