From da80d3536a5b4fb9272cd24a250caeb422cc57e7 Mon Sep 17 00:00:00 2001 From: Dark Arc Date: Fri, 2 Nov 2012 16:04:39 -0400 Subject: [PATCH] Fixes WORLDGUARD-2253 Players who are not in god mode will once again receive damage in PVP areas from Ender Pearls. --- .../bukkit/WorldGuardEntityListener.java | 95 +++++++------------ 1 file changed, 35 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index 4a82b6d7..74a0728b 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -18,53 +18,6 @@ */ package com.sk89q.worldguard.bukkit; -import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector; - -import java.util.Set; - -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.entity.Creature; -import org.bukkit.entity.Creeper; -import org.bukkit.entity.EnderDragon; -import org.bukkit.entity.Enderman; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Fireball; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.entity.Tameable; -import org.bukkit.entity.Wither; -import org.bukkit.entity.WitherSkull; -import org.bukkit.entity.Wolf; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.CreeperPowerEvent; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageByBlockEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDamageEvent.DamageCause; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntityInteractEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.bukkit.event.entity.PigZapEvent; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.entity.PotionSplashEvent; -import org.bukkit.inventory.ItemStack; - import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldguard.LocalPlayer; @@ -74,6 +27,22 @@ import com.sk89q.worldguard.protection.events.DisallowedPVPEvent; import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.*; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.inventory.ItemStack; + +import java.util.Set; + +import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector; /** * Listener for entity related events. @@ -186,6 +155,8 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) { } private void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + + if (event.getDamage() < 1) return; if (event.getDamager() instanceof Projectile) { onEntityDamageByProjectile(event); return; @@ -344,24 +315,13 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) { ConfigurationManager cfg = plugin.getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(player.getWorld()); + // Check Invincible if (isInvincible(player)) { event.setCancelled(true); return; } - if (attacker != null && attacker instanceof Player) { - if (wcfg.useRegions) { - Vector pt = toVector(defender.getLocation()); - Vector pt2 = toVector(attacker.getLocation()); - RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld()); - - if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer) - || !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) { - tryCancelPVPEvent((Player) attacker, player, event); - return; - } - } - } + // Check Mob if (attacker != null && attacker instanceof Skeleton) { if (wcfg.disableMobDamage) { event.setCancelled(true); @@ -377,6 +337,21 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) { } } } + + // Check Player + if (event.getDamager() instanceof EnderPearl) return; + if (attacker != null && attacker instanceof Player) { + if (wcfg.useRegions) { + Vector pt = toVector(defender.getLocation()); + Vector pt2 = toVector(attacker.getLocation()); + RegionManager mgr = plugin.getGlobalRegionManager().get(player.getWorld()); + + if (!mgr.getApplicableRegions(pt).allows(DefaultFlag.PVP, localPlayer) + || !mgr.getApplicableRegions(pt2).allows(DefaultFlag.PVP, plugin.wrapPlayer((Player) attacker))) { + tryCancelPVPEvent((Player) attacker, player, event); + } + } + } } }