summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java228
1 files changed, 127 insertions, 101 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
index b67025cba..117c27a57 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
@@ -67,7 +67,7 @@ public class EssentialsProtectBlockListener extends BlockListener
final List<Block> protect = new ArrayList<Block>();
if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL)
- && settings.getData().getSignsAndRails().isRails()
+ && settings.getData().getSignsAndRails().isProtectRails()
&& user.isAuthorized("essentials.protect"))
{
protect.add(blockPlaced);
@@ -78,7 +78,7 @@ public class EssentialsProtectBlockListener extends BlockListener
}
}
if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN)
- && settings.getData().getSignsAndRails().isSigns()
+ && settings.getData().getSignsAndRails().isProtectSigns()
&& user.isAuthorized("essentials.protect"))
{
protect.add(blockPlaced);
@@ -114,13 +114,13 @@ public class EssentialsProtectBlockListener extends BlockListener
{
final Block block = event.getBlock();
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
- && settings.getData().getSignsAndRails().isRails())
+ && settings.getData().getSignsAndRails().isProtectRails())
{
event.setCancelled(true);
return;
}
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
- && settings.getData().getSignsAndRails().isSigns())
+ && settings.getData().getSignsAndRails().isProtectSigns())
{
event.setCancelled(true);
return;
@@ -174,13 +174,13 @@ public class EssentialsProtectBlockListener extends BlockListener
{
final Block toBlock = event.getToBlock();
if ((toBlock.getType() == Material.RAILS || toBlock.getType() == Material.POWERED_RAIL || toBlock.getType() == Material.DETECTOR_RAIL)
- && settings.getData().getSignsAndRails().isRails())
+ && settings.getData().getSignsAndRails().isProtectRails())
{
event.setCancelled(true);
return;
}
if ((toBlock.getType() == Material.WALL_SIGN || toBlock.getType() == Material.SIGN_POST)
- && settings.getData().getSignsAndRails().isSigns())
+ && settings.getData().getSignsAndRails().isProtectSigns())
{
event.setCancelled(true);
return;
@@ -201,8 +201,7 @@ public class EssentialsProtectBlockListener extends BlockListener
// TODO: Test if this still works
/*
* if (block.getType() == Material.AIR) {
- * event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow)); return;
- }
+ * event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow)); return; }
*/
}
finally
@@ -224,13 +223,13 @@ public class EssentialsProtectBlockListener extends BlockListener
{
final Block block = event.getBlock();
if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
- && settings.getData().getSignsAndRails().isRails())
+ && settings.getData().getSignsAndRails().isProtectRails())
{
event.setCancelled(true);
return;
}
if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
- && settings.getData().getSignsAndRails().isSigns())
+ && settings.getData().getSignsAndRails().isProtectSigns())
{
event.setCancelled(true);
return;
@@ -279,23 +278,36 @@ public class EssentialsProtectBlockListener extends BlockListener
event.setCancelled(true);
return;
}
- final Material type = block.getType();
-
- if (prot.checkProtectionItems(ProtectConfig.alert_on_break, typeId))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
- }
- final IProtectedBlock storage = prot.getStorage();
+ final Material type = block.getType();
- if (user.isAuthorized("essentials.protect.admin"))
- {
- if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
+ if (settings.getData().getAlertOnBreak().contains(type))
+ {
+ prot.getEssentialsConnect().alert(user, type.toString(), _("alertBroke"));
+ }
+ final IProtectedBlock storage = prot.getStorage();
+
+ if (user.isAuthorized("essentials.protect.admin"))
{
- storage.unprotectBlock(block);
- if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
+ if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
{
- final Block below = block.getRelative(BlockFace.DOWN);
- storage.unprotectBlock(below);
+ storage.unprotectBlock(block);
+ if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
+ {
+ final Block below = block.getRelative(BlockFace.DOWN);
+ storage.unprotectBlock(below);
+ }
+ else
+ {
+ for (BlockFace blockFace : faces)
+ {
+ final Block against = block.getRelative(blockFace);
+ storage.unprotectBlock(against);
+ }
+ }
}
else
{
@@ -308,30 +320,30 @@ public class EssentialsProtectBlockListener extends BlockListener
}
else
{
- for (BlockFace blockFace : faces)
+
+ final boolean isProtected = storage.isProtected(block, user.getName());
+ if (isProtected)
{
- final Block against = block.getRelative(blockFace);
- storage.unprotectBlock(against);
+ event.setCancelled(true);
}
- }
- }
- else
- {
-
- final boolean isProtected = storage.isProtected(block, user.getName());
- if (isProtected)
- {
- event.setCancelled(true);
- }
- else
- {
- if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
+ else
{
- storage.unprotectBlock(block);
- if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
+ if (type == Material.WALL_SIGN || type == Material.SIGN_POST || type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL)
{
- final Block below = block.getRelative(BlockFace.DOWN);
- storage.unprotectBlock(below);
+ storage.unprotectBlock(block);
+ if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.SIGN_POST)
+ {
+ final Block below = block.getRelative(BlockFace.DOWN);
+ storage.unprotectBlock(below);
+ }
+ else
+ {
+ for (BlockFace blockFace : faces)
+ {
+ final Block against = block.getRelative(blockFace);
+ storage.unprotectBlock(against);
+ }
+ }
}
else
{
@@ -342,28 +354,89 @@ public class EssentialsProtectBlockListener extends BlockListener
}
}
}
- else
+ }
+ }
+ finally
+ {
+ settings.unlock();
+ }
+ }
+
+ @Override
+ public void onBlockPistonExtend(BlockPistonExtendEvent event)
+ {
+ if (event.isCancelled())
+ {
+ return;
+ }
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
+ {
+ for (Block block : event.getBlocks())
+ {
+ if (settings.getData().getPrevent().getPistonPush().contains(block.getType()))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ 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.DETECTOR_RAIL)
+ && settings.getData().getSignsAndRails().isProtectRails())
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (settings.getData().getSignsAndRails().isProtectSigns())
{
for (BlockFace blockFace : faces)
{
- final Block against = block.getRelative(blockFace);
- storage.unprotectBlock(against);
+ if (blockFace == BlockFace.DOWN)
+ {
+ continue;
+ }
+ final Block sign = block.getRelative(blockFace);
+ if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
+ && sign.getType() == Material.SIGN_POST)
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
+ || blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
+ || blockFace == BlockFace.SELF)
+ && sign.getType() == Material.WALL_SIGN)
+ {
+ event.setCancelled(true);
+ return;
+ }
}
}
}
}
+ finally
+ {
+ settings.unlock();
+ }
}
@Override
- public void onBlockPistonExtend(BlockPistonExtendEvent event)
+ public void onBlockPistonRetract(BlockPistonRetractEvent event)
{
- if (event.isCancelled())
+ if (event.isCancelled() || !event.isSticky())
{
return;
}
- for (Block block : event.getBlocks())
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, block.getTypeId()))
+ final Block block = event.getRetractLocation().getBlock();
+ if (settings.getData().getPrevent().getPistonPush().contains(block.getType()))
{
event.setCancelled(true);
return;
@@ -374,12 +447,12 @@ public class EssentialsProtectBlockListener extends BlockListener
|| block.getType() == Material.POWERED_RAIL
|| block.getRelative(BlockFace.UP).getType() == Material.DETECTOR_RAIL
|| block.getType() == Material.DETECTOR_RAIL)
- && prot.getSettingBool(ProtectConfig.protect_rails))
+ && settings.getData().getSignsAndRails().isProtectRails())
{
event.setCancelled(true);
return;
}
- if (prot.getSettingBool(ProtectConfig.protect_signs))
+ if (settings.getData().getSignsAndRails().isProtectSigns())
{
for (BlockFace blockFace : faces)
{
@@ -405,56 +478,9 @@ public class EssentialsProtectBlockListener extends BlockListener
}
}
}
- }
-
- @Override
- public void onBlockPistonRetract(BlockPistonRetractEvent event)
- {
- if (event.isCancelled() || !event.isSticky())
- {
- return;
- }
- final Block block = event.getRetractLocation().getBlock();
- if (prot.checkProtectionItems(ProtectConfig.blacklist_piston, block.getTypeId()))
- {
- event.setCancelled(true);
- return;
- }
- 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.DETECTOR_RAIL)
- && prot.getSettingBool(ProtectConfig.protect_rails))
- {
- event.setCancelled(true);
- return;
- }
- if (prot.getSettingBool(ProtectConfig.protect_signs))
+ finally
{
- for (BlockFace blockFace : faces)
- {
- if (blockFace == BlockFace.DOWN)
- {
- continue;
- }
- final Block sign = block.getRelative(blockFace);
- if ((blockFace == BlockFace.UP || blockFace == BlockFace.SELF)
- && sign.getType() == Material.SIGN_POST)
- {
- event.setCancelled(true);
- return;
- }
- if ((blockFace == BlockFace.NORTH || blockFace == BlockFace.EAST
- || blockFace == BlockFace.SOUTH || blockFace == BlockFace.WEST
- || blockFace == BlockFace.SELF)
- && sign.getType() == Material.WALL_SIGN)
- {
- event.setCancelled(true);
- return;
- }
- }
+ settings.unlock();
}
}
}