diff options
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java')
-rw-r--r-- | EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java | 83 |
1 files changed, 67 insertions, 16 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index 8717825b3..a1d16af25 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -1,22 +1,15 @@ package com.earth2me.essentials.protect; +import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; import com.earth2me.essentials.protect.data.IProtectedBlock; import java.util.ArrayList; import java.util.List; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockFromToEvent; -import org.bukkit.event.block.BlockIgniteEvent; -import org.bukkit.event.block.BlockListener; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.*; public class EssentialsProtectBlockListener extends BlockListener @@ -27,7 +20,7 @@ public class EssentialsProtectBlockListener extends BlockListener public EssentialsProtectBlockListener(final IProtect parent) { this.prot = parent; - this.ess = prot.getEssentials(); + this.ess = prot.getEssentialsConnect().getEssentials(); } @Override @@ -57,13 +50,13 @@ public class EssentialsProtectBlockListener extends BlockListener if (prot.checkProtectionItems(ProtectConfig.alert_on_placement, id)) { - prot.alert(user, blockPlaced.getType().toString(), Util.i18n("alertPlaced")); + prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced")); } final Block below = blockPlaced.getRelative(BlockFace.DOWN); if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL) && prot.getSettingBool(ProtectConfig.prevent_block_on_rail) - && prot.getStorage().isProtected(below, user.getName())) + && isProtected(below, user)) { event.setCancelled(true); return; @@ -75,7 +68,8 @@ public class EssentialsProtectBlockListener extends BlockListener && user.isAuthorized("essentials.protect")) { protect.add(blockPlaced); - if (prot.getSettingBool(ProtectConfig.protect_below_rails)) + if (prot.getSettingBool(ProtectConfig.protect_below_rails) + && !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user)) { protect.add(blockPlaced.getRelative(BlockFace.DOWN)); } @@ -85,7 +79,10 @@ public class EssentialsProtectBlockListener extends BlockListener && user.isAuthorized("essentials.protect")) { protect.add(blockPlaced); - if (prot.getSettingBool(ProtectConfig.protect_against_signs)) + if (prot.getSettingBool(ProtectConfig.protect_against_signs) + && event.getBlockAgainst().getType() != Material.SIGN_POST + && event.getBlockAgainst().getType() != Material.WALL_SIGN + && !isProtected(event.getBlockAgainst(), user)) { protect.add(event.getBlockAgainst()); } @@ -251,7 +248,7 @@ public class EssentialsProtectBlockListener extends BlockListener if (prot.checkProtectionItems(ProtectConfig.alert_on_break, typeId)) { - prot.alert(user, type.toString(), Util.i18n("alertBroke")); + prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke")); } final IProtectedBlock storage = prot.getStorage(); @@ -286,7 +283,7 @@ public class EssentialsProtectBlockListener extends BlockListener else { - final boolean isProtected = storage.isProtected(block, user.getName()); + final boolean isProtected = isProtected(block, user); if (isProtected) { event.setCancelled(true); @@ -425,4 +422,58 @@ public class EssentialsProtectBlockListener extends BlockListener } } } + + private boolean isProtected(final Block block, final User user) + { + final Material type = block.getType(); + if (prot.getSettingBool(ProtectConfig.protect_signs)) + { + if (type == Material.WALL_SIGN || type == Material.SIGN_POST) + { + return prot.getStorage().isProtected(block, user.getName()); + } + if (prot.getSettingBool(ProtectConfig.protect_against_signs)) + { + final Block up = block.getRelative(BlockFace.UP); + if (up != null && up.getType() == Material.SIGN_POST) + { + return prot.getStorage().isProtected(block, user.getName()); + } + final BlockFace[] directions = new BlockFace[] + { + BlockFace.NORTH, + BlockFace.EAST, + BlockFace.SOUTH, + BlockFace.WEST + }; + for (BlockFace blockFace : directions) + { + final Block signblock = block.getRelative(blockFace); + if (signblock.getType() == Material.WALL_SIGN) + { + final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign)signblock.getState().getData(); + if (signMat != null && signMat.getFacing() == blockFace) + { + return prot.getStorage().isProtected(block, user.getName()); + } + } + } + } + } + if (prot.getSettingBool(ProtectConfig.protect_rails)) { + if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL) + { + return prot.getStorage().isProtected(block, user.getName()); + } + if (prot.getSettingBool(ProtectConfig.protect_below_rails)) + { + final Block up = block.getRelative(BlockFace.UP); + if (up != null && (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)) + { + return prot.getStorage().isProtected(block, user.getName()); + } + } + } + return false; + } } |