summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me/essentials
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2012-01-16 01:55:04 +0100
committersnowleo <schneeleo@gmail.com>2012-01-16 01:55:04 +0100
commit91563e9dca63e8a850be0ac5accb70d10efa8b3d (patch)
tree1ecb0767064ed6bf15554630074eb2b61a456f1a /EssentialsProtect/src/com/earth2me/essentials
parent359ea194b8d5348b5d2f0b3c67f83ee7a6539513 (diff)
downloadEssentials-91563e9dca63e8a850be0ac5accb70d10efa8b3d.tar
Essentials-91563e9dca63e8a850be0ac5accb70d10efa8b3d.tar.gz
Essentials-91563e9dca63e8a850be0ac5accb70d10efa8b3d.tar.lz
Essentials-91563e9dca63e8a850be0ac5accb70d10efa8b3d.tar.xz
Essentials-91563e9dca63e8a850be0ac5accb70d10efa8b3d.zip
Optimize Break in Protect
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java62
1 files changed, 58 insertions, 4 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
index 03ad19cb4..a1d16af25 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
@@ -56,7 +56,7 @@ public class EssentialsProtectBlockListener extends BlockListener
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;
@@ -69,7 +69,7 @@ public class EssentialsProtectBlockListener extends BlockListener
{
protect.add(blockPlaced);
if (prot.getSettingBool(ProtectConfig.protect_below_rails)
- && !prot.getStorage().isProtected(blockPlaced.getRelative(BlockFace.DOWN), user.getName()))
+ && !isProtected(blockPlaced.getRelative(BlockFace.DOWN), user))
{
protect.add(blockPlaced.getRelative(BlockFace.DOWN));
}
@@ -82,7 +82,7 @@ public class EssentialsProtectBlockListener extends BlockListener
if (prot.getSettingBool(ProtectConfig.protect_against_signs)
&& event.getBlockAgainst().getType() != Material.SIGN_POST
&& event.getBlockAgainst().getType() != Material.WALL_SIGN
- && !prot.getStorage().isProtected(event.getBlockAgainst(), user.getName()))
+ && !isProtected(event.getBlockAgainst(), user))
{
protect.add(event.getBlockAgainst());
}
@@ -283,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);
@@ -422,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;
+ }
}