Skip to content

Commit

Permalink
add source_once to hurt command, fixes #1917
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 19, 2019
1 parent 32f4a70 commit 4e9a9d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
// <e@entity.health>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()));

Expand All @@ -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 {
Expand Down

0 comments on commit 4e9a9d2

Please sign in to comment.