diff --git a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java index 69d01a42..53cdc1db 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java @@ -23,14 +23,12 @@ import com.sk89q.worldguard.bukkit.WorldConfiguration; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.cause.Cause; +import com.sk89q.worldguard.bukkit.event.DelegateEvent; import com.sk89q.worldguard.bukkit.event.DelegateEvents; import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent; import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent; import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent; -import com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent; -import com.sk89q.worldguard.bukkit.event.entity.DestroyEntityEvent; -import com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent; -import com.sk89q.worldguard.bukkit.event.entity.UseEntityEvent; +import com.sk89q.worldguard.bukkit.event.entity.*; import com.sk89q.worldguard.bukkit.event.inventory.UseItemEvent; import com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonExtendKey; import com.sk89q.worldguard.bukkit.listener.debounce.BlockPistonRetractKey; @@ -741,9 +739,14 @@ public void onPotionSplash(PotionSplashEvent event) { // Fire entity interaction event if (!event.isCancelled()) { int blocked = 0; + boolean hasDamageEffect = Materials.hasDamageEffect(potion.getEffects()); for (LivingEntity affected : event.getAffectedEntities()) { - if (Events.fireAndTestCancel(new DamageEntityEvent(event, cause, affected))) { + DelegateEvent delegate = hasDamageEffect + ? new DamageEntityEvent(event, cause, affected) : + new UseEntityEvent(event, cause, affected); + + if (Events.fireAndTestCancel(delegate)) { event.setIntensity(affected, 0); blocked++; } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java b/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java index 8ec9f4ef..09ae55c4 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java @@ -27,10 +27,11 @@ import org.bukkit.entity.EntityType; import org.bukkit.material.Dye; import org.bukkit.material.MaterialData; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import javax.annotation.Nullable; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * Material utility class. @@ -42,6 +43,7 @@ public final class Materials { private static final BiMap ENTITY_ITEMS = HashBiMap.create(); private static final Map MATERIAL_FLAGS = new HashMap(); + private static final Set DAMAGE_EFFECTS = new HashSet(); static { ENTITY_ITEMS.put(EntityType.PAINTING, Material.PAINTING); @@ -407,6 +409,30 @@ public final class Materials { MATERIAL_FLAGS.put(Material.RECORD_10, 0); MATERIAL_FLAGS.put(Material.RECORD_11, 0); MATERIAL_FLAGS.put(Material.RECORD_12, 0); + + //DAMAGE_EFFECTS.add(PotionEffectType.ABSORPTION); + DAMAGE_EFFECTS.add(PotionEffectType.BLINDNESS); + DAMAGE_EFFECTS.add(PotionEffectType.CONFUSION); + //DAMAGE_EFFECTS.add(PotionEffectType.DAMAGE_RESISTANCE); + //DAMAGE_EFFECTS.add(PotionEffectType.FAST_DIGGING); + //DAMAGE_EFFECTS.add(PotionEffectType.FIRE_RESISTANCE); + DAMAGE_EFFECTS.add(PotionEffectType.HARM); + //DAMAGE_EFFECTS.add(PotionEffectType.HEAL); + //DAMAGE_EFFECTS.add(PotionEffectType.HEALTH_BOOST); + DAMAGE_EFFECTS.add(PotionEffectType.HUNGER); + //DAMAGE_EFFECTS.add(PotionEffectType.INCREASE_DAMAGE); + //DAMAGE_EFFECTS.add(PotionEffectType.INVISIBILITY); + //DAMAGE_EFFECTS.add(PotionEffectType.JUMP); + //DAMAGE_EFFECTS.add(PotionEffectType.NIGHT_VISION); + DAMAGE_EFFECTS.add(PotionEffectType.POISON); + //DAMAGE_EFFECTS.add(PotionEffectType.REGENERATION); + //DAMAGE_EFFECTS.add(PotionEffectType.SATURATION); + DAMAGE_EFFECTS.add(PotionEffectType.SLOW); + DAMAGE_EFFECTS.add(PotionEffectType.SLOW_DIGGING); + //DAMAGE_EFFECTS.add(PotionEffectType.SPEED); + //DAMAGE_EFFECTS.add(PotionEffectType.WATER_BREATHING); + DAMAGE_EFFECTS.add(PotionEffectType.WEAKNESS); + DAMAGE_EFFECTS.add(PotionEffectType.WITHER); } private Materials() { @@ -662,4 +688,21 @@ public static boolean isConsideredBuildingIfUsed(Material type) { return type == Material.SAPLING; } + /** + * Test whether a list of potion effects contains one or more potion + * effects used for doing damage. + * + * @param effects A collection of effects + * @return True if at least one damage effect exists + */ + public static boolean hasDamageEffect(Collection effects) { + for (PotionEffect effect : effects) { + if (DAMAGE_EFFECTS.contains(effect.getType())) { + return true; + } + } + + return false; + } + }