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 | |
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.
10 files changed, 82 insertions, 89 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java index 91c4bdce4..ce97726dc 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java @@ -1,13 +1,10 @@ package com.earth2me.essentials; import java.util.List; -import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityListener; @@ -52,16 +49,12 @@ public class EssentialsEntityListener extends EntityListener } } } - if (event instanceof EntityDamageEvent || event instanceof EntityDamageByBlockEvent || event instanceof EntityDamageByProjectileEvent) + if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) { - - if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled()) - { - CraftPlayer player = (CraftPlayer)event.getEntity(); - player.getHandle().fireTicks = 0; - player.setRemainingAir(player.getMaximumAir()); - event.setCancelled(true); - } + final Player player = (Player)event.getEntity(); + player.setFireTicks(0); + player.setRemainingAir(player.getMaximumAir()); + event.setCancelled(true); } } diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java index 9aee4033c..3f0f89af2 100644 --- a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java +++ b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java @@ -3,7 +3,6 @@ package com.earth2me.essentials; import java.util.HashMap; import java.util.Map; import org.bukkit.Location; -import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Item; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -130,7 +129,7 @@ public final class InventoryWorkaround // More than a single stack! if (item.getAmount() > item.getType().getMaxStackSize()) { - cinventory.setItem(firstFree, new CraftItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability())); + cinventory.setItem(firstFree, new ItemStack(item.getTypeId(), item.getType().getMaxStackSize(), item.getDurability())); item.setAmount(item.getAmount() - item.getType().getMaxStackSize()); } else diff --git a/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java index bdd453266..90c66aa35 100644 --- a/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java +++ b/Essentials/src/com/earth2me/essentials/TNTExplodeListener.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; 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; @@ -52,6 +54,7 @@ public class TNTExplodeListener extends EntityListener implements Runnable { return; } + try { final Set<ChunkPosition> set = new HashSet<ChunkPosition>(event.blockList().size()); final Player[] players = ess.getServer().getOnlinePlayers(); final List<ChunkPosition> blocksUnderPlayers = new ArrayList<ChunkPosition>(players.length); @@ -72,6 +75,9 @@ public class TNTExplodeListener extends EntityListener implements Runnable } } ((CraftServer)ess.getServer()).getHandle().sendPacketNearby(loc.getX(), loc.getY(), loc.getZ(), 64.0, ((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); + } event.setCancelled(true); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java index 15f5910af..926c219c1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java @@ -6,8 +6,7 @@ import com.earth2me.essentials.Util; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.block.CraftCreatureSpawner; -import org.bukkit.entity.CreatureType; +import org.bukkit.block.CreatureSpawner; public class Commandspawner extends EssentialsCommand @@ -45,7 +44,7 @@ public class Commandspawner extends EssentialsCommand user.sendMessage(Util.i18n("invalidMob")); return; } - new CraftCreatureSpawner(target).setCreatureType(mob.getType()); + ((CreatureSpawner)target.getState()).setCreatureType(mob.getType()); user.sendMessage(Util.format("setSpawner", mob.name)); } catch (Throwable ex) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 17081e349..4cef00de6 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -8,16 +8,13 @@ import com.earth2me.essentials.Mob.MobException; import com.earth2me.essentials.TargetBlock; import com.earth2me.essentials.Util; import java.util.Random; -import net.minecraft.server.EntityWolf; -import net.minecraft.server.PathEntity; import org.bukkit.DyeColor; -import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.entity.CraftCreeper; -import org.bukkit.craftbukkit.entity.CraftSheep; -import org.bukkit.craftbukkit.entity.CraftSlime; -import org.bukkit.craftbukkit.entity.CraftWolf; +import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; +import org.bukkit.entity.Sheep; +import org.bukkit.entity.Slime; +import org.bukkit.entity.Wolf; public class Commandspawnmob extends EssentialsCommand @@ -190,7 +187,7 @@ public class Commandspawnmob extends EssentialsCommand { try { - ((CraftSlime)spawned).setSize(Integer.parseInt(data)); + ((Slime)spawned).setSize(Integer.parseInt(data)); } catch (Exception e) { @@ -204,11 +201,11 @@ public class Commandspawnmob extends EssentialsCommand if (data.equalsIgnoreCase("random")) { Random rand = new Random(); - ((CraftSheep)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]); + ((Sheep)spawned).setColor(DyeColor.values()[rand.nextInt(DyeColor.values().length)]); } else { - ((CraftSheep)spawned).setColor(DyeColor.valueOf(data.toUpperCase())); + ((Sheep)spawned).setColor(DyeColor.valueOf(data.toUpperCase())); } } catch (Exception e) @@ -218,21 +215,18 @@ public class Commandspawnmob extends EssentialsCommand } if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("tamed")) { - EntityWolf wolf = ((CraftWolf)spawned).getHandle(); + Wolf wolf = ((Wolf)spawned); wolf.setTamed(true); - wolf.setPathEntity((PathEntity)null); + wolf.setOwner(user); wolf.setSitting(true); - wolf.health = 20; - wolf.setOwnerName(user.getName()); - wolf.world.a(wolf, (byte)7); } if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("angry")) { - ((CraftWolf)spawned).setAngry(true); + ((Wolf)spawned).setAngry(true); } if ("Creeper".equalsIgnoreCase(type) && data.equalsIgnoreCase("powered")) { - ((CraftCreeper)spawned).setPowered(true); + ((Creeper)spawned).setPowered(true); } } } diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 1bd1d6184..f4109b3bb 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -11,7 +11,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.inventory.ItemStack; @@ -456,7 +455,7 @@ public class EssentialsSign public BlockSign(final Block block) { this.block = block; - this.sign = new CraftSign(block); + this.sign = (Sign)block.getState(); } public final String getLine(final int index) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java index eb6163d20..7320f27a4 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -7,7 +7,6 @@ import java.util.logging.Logger; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; @@ -48,7 +47,7 @@ public class SignBlockListener extends BlockListener final int mat = block.getTypeId(); if (mat == Material.SIGN_POST.getId() || mat == Material.WALL_SIGN.getId()) { - final Sign csign = new CraftSign(block); + final Sign csign = (Sign)block.getState(); for (Signs signs : Signs.values()) { final EssentialsSign sign = signs.getSign(); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java index a97c234fa..5d7900508 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java @@ -4,7 +4,6 @@ import com.earth2me.essentials.IEssentials; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerListener; @@ -39,7 +38,7 @@ public class SignPlayerListener extends PlayerListener { return; } - final Sign csign = new CraftSign(block); + final Sign csign = (Sign)block.getState(); for (Signs signs : Signs.values()) { final EssentialsSign sign = signs.getSign(); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index f9957e646..8ecf34e01 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -15,7 +15,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; -import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.inventory.ItemStack; @@ -204,7 +203,7 @@ public class SignProtection extends EssentialsSign { if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN) { - final Sign sign = new CraftSign(b); + final Sign sign = (Sign)b.getState(); if (sign.getLine(0).equalsIgnoreCase("§1[Protection]")) { return true; @@ -218,7 +217,7 @@ public class SignProtection extends EssentialsSign { if (a.getType() == Material.SIGN_POST || a.getType() == Material.WALL_SIGN) { - final Sign sign = new CraftSign(a); + final Sign sign = (Sign)a.getState(); if (sign.getLine(0).equalsIgnoreCase("§1[Protection]")) { return true; 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); |