diff options
Diffstat (limited to 'EssentialsAntiBuild/src/com/earth2me')
-rw-r--r-- | EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java index d2f46586f..67995c955 100644 --- a/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java +++ b/EssentialsAntiBuild/src/com/earth2me/essentials/antibuild/EssentialsAntiBuildListener.java @@ -7,14 +7,15 @@ import java.util.logging.Level; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.*; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.inventory.CraftItemEvent; -import org.bukkit.event.painting.PaintingBreakByEntityEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; @@ -36,6 +37,10 @@ public class EssentialsAntiBuildListener implements Listener { if (block == null) { + if (ess.getSettings().isDebug()) + { + ess.getLogger().log(Level.INFO, "AntiBuild permission check failed, invalid block."); + } return false; } return metaPermCheck(user, action, block.getTypeId(), block.getData()); @@ -47,7 +52,7 @@ public class EssentialsAntiBuildListener implements Listener return user.isAuthorized(blockPerm); } - private boolean metaPermCheck(final User user, final String action, final int blockId, final byte data) + private boolean metaPermCheck(final User user, final String action, final int blockId, final short data) { final String blockPerm = "essentials.build." + action + "." + blockId; final String dataPerm = blockPerm + ":" + data; @@ -141,20 +146,32 @@ public class EssentialsAntiBuildListener implements Listener } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPaintingBreak(final PaintingBreakByEntityEvent event) + public void onHangingBreak(final HangingBreakByEntityEvent event) { final Entity entity = event.getRemover(); if (entity instanceof Player) { final User user = ess.getUser(entity); - if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build") - && !metaPermCheck(user, "break", Material.PAINTING.getId())) + final EntityType type = event.getEntity().getType(); + final boolean warn = ess.getSettings().warnOnBuildDisallow(); + if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) { - if (ess.getSettings().warnOnBuildDisallow()) + if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING.getId())) { - user.sendMessage(_("antiBuildBreak", Material.PAINTING.toString())); + if (warn) + { + user.sendMessage(_("antiBuildBreak", Material.PAINTING.toString())); + } + event.setCancelled(true); + } + else if(type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME.getId())) + { + if (warn) + { + user.sendMessage(_("antiBuildBreak", Material.ITEM_FRAME.toString())); + } + event.setCancelled(true); } - event.setCancelled(true); } } } @@ -215,7 +232,7 @@ public class EssentialsAntiBuildListener implements Listener if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { - if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getData().getData())) + if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getDurability())) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) @@ -247,7 +264,7 @@ public class EssentialsAntiBuildListener implements Listener if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { - if (!metaPermCheck(user, "craft", item.getTypeId(), item.getData().getData())) + if (!metaPermCheck(user, "craft", item.getTypeId(), item.getDurability())) { event.setCancelled(true); if (ess.getSettings().warnOnBuildDisallow()) @@ -268,7 +285,7 @@ public class EssentialsAntiBuildListener implements Listener if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { - if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getData().getData())) + if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getDurability())) { event.setCancelled(true); event.getItem().setPickupDelay(50); @@ -285,7 +302,7 @@ public class EssentialsAntiBuildListener implements Listener if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) { - if (!metaPermCheck(user, "drop", item.getTypeId(), item.getData().getData())) + if (!metaPermCheck(user, "drop", item.getTypeId(), item.getDurability())) { event.setCancelled(true); user.updateInventory(); |