diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityDamagedScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityDamagedScriptEvent.java index e6eb12ec41..0f3ee6cd1d 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityDamagedScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/entity/EntityDamagedScriptEvent.java @@ -2,6 +2,7 @@ import com.denizenscript.denizen.objects.EntityTag; import com.denizenscript.denizen.objects.ItemTag; +import com.denizenscript.denizen.objects.LocationTag; import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizen.events.BukkitScriptEvent; import com.denizenscript.denizencore.objects.core.ElementTag; @@ -10,11 +11,13 @@ import com.denizenscript.denizencore.scripts.ScriptEntryData; import com.denizenscript.denizencore.utilities.CoreUtilities; import com.denizenscript.denizen.utilities.BukkitImplDeprecations; +import org.bukkit.block.Block; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.potion.PotionEffectType; @@ -41,6 +44,7 @@ public class EntityDamagedScriptEvent extends BukkitScriptEvent implements Liste // // @Switch with: to only process the event when the item used to cause damage (in the damager's hand) is a specified item. // @Switch type: to only run if the entity damaged matches the entity input. + // @Switch block: to only run if the damage came from a block that matches the given material or location matcher. // // @Cancellable true // @@ -49,6 +53,7 @@ public class EntityDamagedScriptEvent extends BukkitScriptEvent implements Liste // @Context // returns the EntityTag that was damaged. // returns the EntityTag damaging the other entity, if any. + // returns the LocationTag of a block that damaged the entity, if any. // returns an ElementTag of reason the entity was damaged - see <@link language damage cause> for causes. // returns an ElementTag(Decimal) of the amount of damage dealt. // returns an ElementTag(Decimal) of the amount of damage dealt, after armor is calculated. @@ -88,7 +93,7 @@ public EntityDamagedScriptEvent() { registerCouldMatcher(" damaged (by <'cause'>)"); registerCouldMatcher(" damaged by "); registerCouldMatcher(" damages "); - registerSwitches("with", "type"); + registerSwitches("with", "type", "blocker"); } @@ -147,6 +152,19 @@ public boolean matches(ScriptPath path) { if (!runWithCheck(path, held)) { return false; } + String blockMatcher = path.switches.get("block"); + if (blockMatcher != null) { + if (!(event instanceof EntityDamageByBlockEvent)) { + return false; + } + Block block = ((EntityDamageByBlockEvent) event).getDamager(); + if (block == null) { + return false; + } + if (!new LocationTag(block.getLocation()).tryAdvancedMatcher(blockMatcher)) { + return false; + } + } return super.matches(path); } @@ -219,6 +237,14 @@ public ObjectTag getContext(String name) { return damager.getDenizenObject(); } break; + case "damager_block": + if (event instanceof EntityDamageByBlockEvent) { + Block block = ((EntityDamageByBlockEvent) event).getDamager(); + if (block != null) { + return new LocationTag(block.getLocation()); + } + } + break; case "projectile": if (projectile != null) { return projectile.getDenizenObject();