Skip to content

Commit

Permalink
cast: 'no_clear'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 11, 2023
1 parent fc6f4e7 commit 3962553
Showing 1 changed file with 13 additions and 6 deletions.
Expand Up @@ -20,16 +20,16 @@ public class CastCommand extends AbstractCommand {

public CastCommand() {
setName("cast");
setSyntax("cast [<effect>] (remove) (duration:<value>) (amplifier:<#>) (<entity>|...) (no_ambient) (hide_particles) (no_icon)");
setRequiredArguments(1, 8);
setSyntax("cast [<effect>] (remove) (duration:<value>) (amplifier:<#>) (<entity>|...) (no_ambient) (hide_particles) (no_icon) (no_clear)");
setRequiredArguments(1, 9);
isProcedural = false;
}

// <--[command]
// @Name Cast
// @Syntax cast [<effect>] (remove) (duration:<value>) (amplifier:<#>) (<entity>|...) (no_ambient) (hide_particles) (no_icon)
// @Syntax cast [<effect>] (remove) (duration:<value>) (amplifier:<#>) (<entity>|...) (no_ambient) (hide_particles) (no_icon) (no_clear)
// @Required 1
// @Maximum 8
// @Maximum 9
// @Short Casts a potion effect to a list of entities.
// @Synonyms Potion,Magic
// @Group entity
Expand Down Expand Up @@ -57,6 +57,8 @@ public CastCommand() {
//
// Optionally, specify "no_icon" to hide the effect icon in the corner of your screen.
//
// Optionally use "no_clear" to prevent clearing any previous effect instance before adding the new one.
//
// @Tags
// <EntityTag.has_effect[<effect>]>
// <server.potion_effect_types>
Expand Down Expand Up @@ -94,6 +96,10 @@ else if (!scriptEntry.hasObject("ambient")
&& arg.matches("no_ambient")) {
scriptEntry.addObject("ambient", new ElementTag(false));
}
else if (!scriptEntry.hasObject("no_clear")
&& arg.matches("no_clear")) {
scriptEntry.addObject("no_clear", new ElementTag(true));
}
else if (!scriptEntry.hasObject("show_particles")
&& arg.matches("hide_particles")) {
scriptEntry.addObject("show_particles", new ElementTag(false));
Expand Down Expand Up @@ -151,14 +157,15 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag showParticles = scriptEntry.getElement("show_particles");
ElementTag ambient = scriptEntry.getElement("ambient");
ElementTag showIcon = scriptEntry.getElement("show_icon");
ElementTag noClear = scriptEntry.getElement("no_clear");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("targets", entities), db("effect", effect.getName()), db("amplifier", amplifier), duration, ambient, showParticles, showIcon);
Debug.report(scriptEntry, getName(), db("targets", entities), db("effect", effect.getName()), db("amplifier", amplifier), duration, ambient, showParticles, showIcon, noClear);
}
boolean amb = ambient.asBoolean();
boolean showP = showParticles.asBoolean();
boolean icon = showIcon.asBoolean();
for (EntityTag entity : entities) {
if (entity.getLivingEntity().hasPotionEffect(effect)) {
if ((remove || noClear == null || !noClear.asBoolean()) && entity.getLivingEntity().hasPotionEffect(effect)) {
entity.getLivingEntity().removePotionEffect(effect);
}
if (remove) {
Expand Down

0 comments on commit 3962553

Please sign in to comment.