diff options
author | snowleo <schneeleo@gmail.com> | 2011-08-27 20:39:54 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-08-27 20:39:54 +0200 |
commit | 322ecdb9fccedc2d4d8f553ac55d4573848e51b3 (patch) | |
tree | 1f6af86675228e1e3b26c7a3e95b47aefb993652 /EssentialsProtect | |
parent | 033babd586d0d2319ce0a4d0ed88dc740ea2a59a (diff) | |
download | Essentials-322ecdb9fccedc2d4d8f553ac55d4573848e51b3.tar Essentials-322ecdb9fccedc2d4d8f553ac55d4573848e51b3.tar.gz Essentials-322ecdb9fccedc2d4d8f553ac55d4573848e51b3.tar.lz Essentials-322ecdb9fccedc2d4d8f553ac55d4573848e51b3.tar.xz Essentials-322ecdb9fccedc2d4d8f553ac55d4573848e51b3.zip |
Less use of Craftbukkit code, so less things will break on MC update.
Added try/catch around the tnt and creeper protection code. The event will now always canceled, even if our fake explosion code fails.
Diffstat (limited to 'EssentialsProtect')
-rw-r--r-- | EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java | 98 |
1 files changed, 52 insertions, 46 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index 8dd3335f5..f28fd1185 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -4,6 +4,8 @@ import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; import java.util.HashSet; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import net.minecraft.server.ChunkPosition; import net.minecraft.server.Packet60Explosion; import org.bukkit.Location; @@ -12,9 +14,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.entity.CraftFireball; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.entity.CraftTNTPrimed; import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; import org.bukkit.entity.Fireball; @@ -38,13 +37,13 @@ public class EssentialsProtectEntityListener extends EntityListener { private final transient IProtect prot; private final transient IEssentials ess; - + public EssentialsProtectEntityListener(final IProtect prot) { this.prot = prot; this.ess = prot.getEssentials(); } - + @Override public void onEntityDamage(final EntityDamageEvent event) { @@ -57,7 +56,7 @@ public class EssentialsProtectEntityListener extends EntityListener if (event instanceof EntityDamageByBlockEvent) { final DamageCause cause = event.getCause(); - + if (prot.getSettingBool(ProtectConfig.disable_contactdmg) && cause == DamageCause.CONTACT && !(target instanceof Player @@ -86,7 +85,7 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + if (event instanceof EntityDamageByEntityEvent) { final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event; @@ -111,7 +110,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg) && !(target instanceof Player && user.isAuthorized("essentials.protect.damage.creeper") @@ -120,7 +119,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (eAttack instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg) && !(target instanceof Player && user.isAuthorized("essentials.protect.damage.fireball") @@ -129,7 +128,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg) && !(target instanceof Player && user.isAuthorized("essentials.protect.damage.tnt") @@ -138,7 +137,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (edEvent.getDamager() instanceof Projectile && target instanceof Player && ((prot.getSettingBool(ProtectConfig.disable_projectiles) @@ -153,7 +152,7 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + final DamageCause cause = event.getCause(); if (target instanceof Player) { @@ -165,7 +164,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); return; } - + if (cause == DamageCause.SUFFOCATION && prot.getSettingBool(ProtectConfig.disable_suffocate) && !(user.isAuthorized("essentials.protect.damage.suffocation") @@ -201,7 +200,7 @@ public class EssentialsProtectEntityListener extends EntityListener } } } - + @Override public void onEntityExplode(final EntityExplodeEvent event) { @@ -216,43 +215,50 @@ public class EssentialsProtectEntityListener extends EntityListener || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg) || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight))) { - final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); - final Player[] players = ess.getServer().getOnlinePlayers(); - final Set<ChunkPosition> blocksUnderPlayers = new HashSet<ChunkPosition>(players.length); - final Location loc = event.getLocation(); - for (Player player : players) + try { - if (player.getWorld().equals(loc.getWorld())) + final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); + final Player[] players = ess.getServer().getOnlinePlayers(); + final Set<ChunkPosition> blocksUnderPlayers = new HashSet<ChunkPosition>(players.length); + final Location loc = event.getLocation(); + for (Player player : players) { - blocksUnderPlayers.add( - new ChunkPosition( - player.getLocation().getBlockX(), - player.getLocation().getBlockY() - 1, - player.getLocation().getBlockZ())); + if (player.getWorld().equals(loc.getWorld())) + { + blocksUnderPlayers.add( + new ChunkPosition( + player.getLocation().getBlockX(), + player.getLocation().getBlockY() - 1, + player.getLocation().getBlockZ())); + } } - } - ChunkPosition cp; - for (Block block : event.blockList()) - { - cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); - if (!blocksUnderPlayers.contains(cp)) + ChunkPosition cp; + for (Block block : event.blockList()) { - set.add(cp); + cp = new ChunkPosition(block.getX(), block.getY(), block.getZ()); + if (!blocksUnderPlayers.contains(cp)) + { + set.add(cp); + } } + + ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, + new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set)); + } + catch (Throwable ex) + { + Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex); } - - ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0D, ((CraftWorld)loc.getWorld()).getHandle().worldProvider.dimension, - new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set)); event.setCancelled(true); return; } - else if (event.getEntity() instanceof CraftTNTPrimed + else if (event.getEntity() instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)) { event.setCancelled(true); return; } - else if (event.getEntity() instanceof CraftFireball + else if (event.getEntity() instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion)) { event.setCancelled(true); @@ -264,10 +270,10 @@ public class EssentialsProtectEntityListener extends EntityListener for (Block block : event.blockList()) { if ((block.getRelative(BlockFace.UP).getType() == Material.RAILS - || block.getType() == Material.RAILS - || block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL - || block.getType() == Material.POWERED_RAIL - || block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL + || block.getType() == Material.RAILS + || block.getRelative(BlockFace.UP).getType() == Material.POWERED_RAIL + || block.getType() == Material.POWERED_RAIL + || block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL || block.getType() == Material.DETECTOR_RAIL) && prot.getSettingBool(ProtectConfig.protect_rails)) { @@ -288,11 +294,11 @@ public class EssentialsProtectEntityListener extends EntityListener } } } - + @Override public void onCreatureSpawn(final CreatureSpawnEvent event) { - if (event.getEntity() instanceof CraftPlayer) + if (event.getEntity() instanceof Player) { return; } @@ -310,7 +316,7 @@ public class EssentialsProtectEntityListener extends EntityListener event.setCancelled(true); } } - + @Override public void onEntityTarget(final EntityTargetEvent event) { @@ -336,11 +342,11 @@ public class EssentialsProtectEntityListener extends EntityListener return; } } - + @Override public void onExplosionPrime(ExplosionPrimeEvent event) { - if (event.getEntity() instanceof CraftFireball + if (event.getEntity() instanceof Fireball && prot.getSettingBool(ProtectConfig.prevent_fireball_fire)) { event.setFire(false); |