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
commit5ab7edb941df7d8778306aad938e9a201f9de14d (patch)
treecfa4a499f39fe4d2a9ae0573a2fc7f9a657e5a90 /EssentialsProtect/src/com/earth2me/essentials
parent68335ba3a246f3d946ae5ce438d4dba4789d626d (diff)
downloadEssentials-5ab7edb941df7d8778306aad938e9a201f9de14d.tar
Essentials-5ab7edb941df7d8778306aad938e9a201f9de14d.tar.gz
Essentials-5ab7edb941df7d8778306aad938e9a201f9de14d.tar.lz
Essentials-5ab7edb941df7d8778306aad938e9a201f9de14d.tar.xz
Essentials-5ab7edb941df7d8778306aad938e9a201f9de14d.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;
+ }
}