From 4e9a9d211d8e87eefba62cd759310e742b3fca17 Mon Sep 17 00:00:00 2001 From: mcmonkey Date: Tue, 19 Feb 2019 01:29:40 -0800 Subject: [PATCH] add source_once to hurt command, fixes #1917 --- .../denizen/scripts/commands/BukkitCommandRegistry.java | 1 + .../denizen/scripts/commands/entity/HurtCommand.java | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java b/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java index 447795a334..1d37f4920d 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java @@ -1864,6 +1864,7 @@ public void registerCoreMembers() { // You may also optionally specify a damage cause to fire a proper damage event with the given cause, // only doing the damage if the event wasn't cancelled. Calculates the 'final damage' rather // than using the raw damage input number. See <@link language damage cause> for damage causes. + // To make the source only be included in the initial damage event, and not the application of damage, specify 'source_once'. // // @Tags // diff --git a/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java b/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java index da1c1d7fef..221d7030d4 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/scripts/commands/entity/HurtCommand.java @@ -43,6 +43,10 @@ else if (!scriptEntry.hasObject("cause") && arg.matchesEnum(EntityDamageEvent.DamageCause.values())) { scriptEntry.addObject("cause", arg.asElement()); } + else if (!scriptEntry.hasObject("source_once") + && arg.matchesOne("source_once")) { + scriptEntry.addObject("source_once", new Element(true)); + } else { arg.reportUnhandled(); } @@ -76,11 +80,13 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { dEntity source = (dEntity) scriptEntry.getObject("source"); Element amountElement = scriptEntry.getElement("amount"); Element cause = scriptEntry.getElement("cause"); + Element source_once = scriptEntry.getElement("source_once"); if (scriptEntry.dbCallShouldDebug()) { dB.report(scriptEntry, getName(), amountElement.debug() + aH.debugList("entities", entities) + + (source_once == null ? "" : source_once.debug()) + (cause == null ? "" : cause.debug()) + (source == null ? "" : source.debug())); @@ -107,7 +113,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { Bukkit.getPluginManager().callEvent(ede); if (!ede.isCancelled()) { entity.getLivingEntity().setLastDamageCause(ede); - if (source == null) { + if (source == null || (source_once != null && source_once.asBoolean())) { entity.getLivingEntity().damage(ede.getFinalDamage()); } else {