summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2012-01-03 02:51:19 +0100
committersnowleo <schneeleo@gmail.com>2012-01-03 02:51:19 +0100
commit801562ac2c0c64770eeaee5cc5815954cd5af72e (patch)
tree259be8a100c7313656143df3b659c3544f14bb9e /EssentialsProtect
parent869d79ae73e30a034c2c406d84ce41bcd7c2d67a (diff)
downloadEssentials-801562ac2c0c64770eeaee5cc5815954cd5af72e.tar
Essentials-801562ac2c0c64770eeaee5cc5815954cd5af72e.tar.gz
Essentials-801562ac2c0c64770eeaee5cc5815954cd5af72e.tar.lz
Essentials-801562ac2c0c64770eeaee5cc5815954cd5af72e.tar.xz
Essentials-801562ac2c0c64770eeaee5cc5815954cd5af72e.zip
More work on Protect
Diffstat (limited to 'EssentialsProtect')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/BlockBreakPermissions.java43
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/BlockPlacePermissions.java42
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java281
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java25
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java12
5 files changed, 262 insertions, 141 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/BlockBreakPermissions.java b/EssentialsProtect/src/com/earth2me/essentials/protect/BlockBreakPermissions.java
new file mode 100644
index 000000000..74ebe38dc
--- /dev/null
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/BlockBreakPermissions.java
@@ -0,0 +1,43 @@
+package com.earth2me.essentials.protect;
+
+import com.earth2me.essentials.api.IPermission;
+import com.earth2me.essentials.perm.AbstractSuperpermsPermission;
+import java.util.EnumMap;
+import java.util.Locale;
+import java.util.Map;
+import org.bukkit.Material;
+import org.bukkit.permissions.PermissionDefault;
+
+public class BlockBreakPermissions extends AbstractSuperpermsPermission{
+ private static Map<Material,IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
+ private static final String base = "essentials.protect.blockbreak.";
+ private final String permission;
+
+ public static IPermission getPermission(Material mat)
+ {
+ IPermission perm = permissions.get(mat);
+ if (perm == null) {
+ perm = new BlockBreakPermissions(mat.toString().toLowerCase(Locale.ENGLISH));
+ permissions.put(mat, perm);
+ }
+ return perm;
+ }
+
+ private BlockBreakPermissions(String matName)
+ {
+ this.permission = base + matName;
+ }
+
+ @Override
+ public String getPermission()
+ {
+ return this.permission;
+ }
+
+ @Override
+ public PermissionDefault getPermissionDefault()
+ {
+ return PermissionDefault.TRUE;
+ }
+}
+
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/BlockPlacePermissions.java b/EssentialsProtect/src/com/earth2me/essentials/protect/BlockPlacePermissions.java
new file mode 100644
index 000000000..23ce7e053
--- /dev/null
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/BlockPlacePermissions.java
@@ -0,0 +1,42 @@
+package com.earth2me.essentials.protect;
+
+import com.earth2me.essentials.api.IPermission;
+import com.earth2me.essentials.perm.AbstractSuperpermsPermission;
+import java.util.EnumMap;
+import java.util.Locale;
+import java.util.Map;
+import org.bukkit.Material;
+import org.bukkit.permissions.PermissionDefault;
+
+public class BlockPlacePermissions extends AbstractSuperpermsPermission{
+ private static Map<Material,IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
+ private static final String base = "essentials.protect.blockplace.";
+ private final String permission;
+
+ public static IPermission getPermission(Material mat)
+ {
+ IPermission perm = permissions.get(mat);
+ if (perm == null) {
+ perm = new BlockPlacePermissions(mat.toString().toLowerCase(Locale.ENGLISH));
+ permissions.put(mat, perm);
+ }
+ return perm;
+ }
+
+ private BlockPlacePermissions(String matName)
+ {
+ this.permission = base + matName;
+ }
+
+ @Override
+ public String getPermission()
+ {
+ return this.permission;
+ }
+
+ @Override
+ public PermissionDefault getPermissionDefault()
+ {
+ return PermissionDefault.TRUE;
+ }
+}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
index abbbe5939..b67025cba 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java
@@ -32,64 +32,72 @@ public class EssentialsProtectBlockListener extends BlockListener
}
final IUser user = ess.getUser(event.getPlayer());
-
- if (prot.getSettingBool(ProtectConfig.disable_build) && !user.isAuthorized(Permissions.BUILD))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
- return;
- }
+ if (!user.isAuthorized(Permissions.BUILD))
+ {
+ event.setCancelled(true);
+ return;
+ }
- final Block blockPlaced = event.getBlockPlaced();
- final int id = blockPlaced.getTypeId();
+ final Block blockPlaced = event.getBlockPlaced();
+ final int id = blockPlaced.getTypeId();
- if (prot.checkProtectionItems(ProtectConfig.blacklist_placement, id) && !user.isAuthorized("essentials.protect.exemptplacement"))
- {
- event.setCancelled(true);
- return;
- }
+ if (!user.isAuthorized(BlockPlacePermissions.getPermission(blockPlaced.getType())))
+ {
+ event.setCancelled(true);
+ return;
+ }
- if (prot.checkProtectionItems(ProtectConfig.alert_on_placement, id))
- {
- prot.getEssentialsConnect().alert(user, blockPlaced.getType().toString(), _("alertPlaced"));
- }
+ if (settings.getData().getAlertOnPlacement().contains(blockPlaced.getType()))
+ {
+ 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()))
- {
- event.setCancelled(true);
- return;
- }
+ final Block below = blockPlaced.getRelative(BlockFace.DOWN);
+ if ((below.getType() == Material.RAILS || below.getType() == Material.POWERED_RAIL || below.getType() == Material.DETECTOR_RAIL)
+ && settings.getData().getSignsAndRails().isPreventBlockAboveRails()
+ && prot.getStorage().isProtected(below, user.getName()))
+ {
+ event.setCancelled(true);
+ return;
+ }
- final List<Block> protect = new ArrayList<Block>();
- if ((blockPlaced.getType() == Material.RAILS || blockPlaced.getType() == Material.POWERED_RAIL || blockPlaced.getType() == Material.DETECTOR_RAIL)
- && prot.getSettingBool(ProtectConfig.protect_rails)
- && user.isAuthorized("essentials.protect"))
- {
- protect.add(blockPlaced);
- if (prot.getSettingBool(ProtectConfig.protect_below_rails)
- && !prot.getStorage().isProtected(blockPlaced.getRelative(BlockFace.DOWN), user.getName()))
+ 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()
+ && user.isAuthorized("essentials.protect"))
{
- protect.add(blockPlaced.getRelative(BlockFace.DOWN));
+ protect.add(blockPlaced);
+ if (settings.getData().getSignsAndRails().isBlockBelow()
+ && !prot.getStorage().isProtected(blockPlaced.getRelative(BlockFace.DOWN), user.getName()))
+ {
+ protect.add(blockPlaced.getRelative(BlockFace.DOWN));
+ }
}
- }
- if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN)
- && prot.getSettingBool(ProtectConfig.protect_signs)
- && user.isAuthorized("essentials.protect"))
- {
- protect.add(blockPlaced);
- 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()))
+ if ((blockPlaced.getType() == Material.SIGN_POST || blockPlaced.getType() == Material.WALL_SIGN)
+ && settings.getData().getSignsAndRails().isSigns()
+ && user.isAuthorized("essentials.protect"))
{
- protect.add(event.getBlockAgainst());
+ protect.add(blockPlaced);
+ if (settings.getData().getSignsAndRails().isBlockBelow()
+ && event.getBlockAgainst().getType() != Material.SIGN_POST
+ && event.getBlockAgainst().getType() != Material.WALL_SIGN
+ && !prot.getStorage().isProtected(event.getBlockAgainst(), user.getName()))
+ {
+ protect.add(event.getBlockAgainst());
+ }
+ }
+ for (Block block : protect)
+ {
+ prot.getStorage().protectBlock(block, user.getName());
}
}
- for (Block block : protect)
+ finally
{
- prot.getStorage().protectBlock(block, user.getName());
+ settings.unlock();
}
}
@@ -100,47 +108,56 @@ public class EssentialsProtectBlockListener extends BlockListener
{
return;
}
- final Block block = event.getBlock();
- if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
- && prot.getSettingBool(ProtectConfig.protect_rails))
- {
- event.setCancelled(true);
- return;
- }
- if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
- && prot.getSettingBool(ProtectConfig.protect_signs))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
- return;
- }
- if (event.getBlock().getType() == Material.OBSIDIAN
- || event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN)
- {
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_portal_creation));
- return;
- }
+ final Block block = event.getBlock();
+ if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
+ && settings.getData().getSignsAndRails().isRails())
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
+ && settings.getData().getSignsAndRails().isSigns())
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (event.getBlock().getType() == Material.OBSIDIAN
+ || event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.OBSIDIAN)
+ {
+ event.setCancelled(settings.getData().getPrevent().isPortalCreation());
+ return;
+ }
- if (event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD))
- {
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_fire_spread));
- return;
- }
+ if (event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD))
+ {
+ event.setCancelled(settings.getData().getPrevent().isFirespread());
+ return;
+ }
- if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL))
- {
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_flint_fire));
- return;
- }
+ if (event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) && event.getPlayer() != null)
+ {
+ event.setCancelled(ess.getUser(event.getPlayer()).isAuthorized(Permissions.USEFLINTSTEEL));
+ return;
+ }
- if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LAVA))
- {
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lava_fire_spread));
- return;
+ if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LAVA))
+ {
+ event.setCancelled(settings.getData().getPrevent().isLavaFirespread());
+ return;
+ }
+ if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
+ {
+ event.setCancelled(settings.getData().getPrevent().isLightningFirespread());
+ return;
+ }
}
- if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING))
+ finally
{
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lightning_fire_spread));
- return;
+ settings.unlock();
}
}
@@ -151,37 +168,46 @@ public class EssentialsProtectBlockListener extends BlockListener
{
return;
}
- final Block toBlock = event.getToBlock();
- if ((toBlock.getType() == Material.RAILS || toBlock.getType() == Material.POWERED_RAIL || toBlock.getType() == Material.DETECTOR_RAIL)
- && prot.getSettingBool(ProtectConfig.protect_rails))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
- return;
- }
- if ((toBlock.getType() == Material.WALL_SIGN || toBlock.getType() == Material.SIGN_POST)
- && prot.getSettingBool(ProtectConfig.protect_signs))
- {
- event.setCancelled(true);
- return;
- }
+ final Block toBlock = event.getToBlock();
+ if ((toBlock.getType() == Material.RAILS || toBlock.getType() == Material.POWERED_RAIL || toBlock.getType() == Material.DETECTOR_RAIL)
+ && settings.getData().getSignsAndRails().isRails())
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if ((toBlock.getType() == Material.WALL_SIGN || toBlock.getType() == Material.SIGN_POST)
+ && settings.getData().getSignsAndRails().isSigns())
+ {
+ event.setCancelled(true);
+ return;
+ }
- final Block block = event.getBlock();
- if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)
- {
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_flow));
- return;
- }
+ final Block block = event.getBlock();
+ if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER)
+ {
+ event.setCancelled(settings.getData().getPrevent().isWaterFlow());
+ return;
+ }
- if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
- {
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_lava_flow));
- return;
+ if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
+ {
+ event.setCancelled(settings.getData().getPrevent().isLavaFlow());
+ return;
+ }
+ // TODO: Test if this still works
+ /*
+ * if (block.getType() == Material.AIR) {
+ * event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow)); return;
+ }
+ */
}
-
- if (block.getType() == Material.AIR)
+ finally
{
- event.setCancelled(prot.getSettingBool(ProtectConfig.prevent_water_bucket_flow));
- return;
+ settings.unlock();
}
}
@@ -192,22 +218,32 @@ public class EssentialsProtectBlockListener extends BlockListener
{
return;
}
- final Block block = event.getBlock();
- if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL) && prot.getSettingBool(ProtectConfig.protect_rails))
- {
- event.setCancelled(true);
- return;
- }
- if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
- && prot.getSettingBool(ProtectConfig.protect_signs))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
- return;
+ final Block block = event.getBlock();
+ if ((block.getType() == Material.RAILS || block.getType() == Material.POWERED_RAIL || block.getType() == Material.DETECTOR_RAIL)
+ && settings.getData().getSignsAndRails().isRails())
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if ((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)
+ && settings.getData().getSignsAndRails().isSigns())
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (settings.getData().getPrevent().isFirespread())
+ {
+ event.setCancelled(true);
+ return;
+ }
}
- if (prot.getSettingBool(ProtectConfig.prevent_fire_spread))
+ finally
{
- event.setCancelled(true);
- return;
+ settings.unlock();
}
}
private final static BlockFace[] faces = new BlockFace[]
@@ -230,7 +266,7 @@ public class EssentialsProtectBlockListener extends BlockListener
}
final IUser user = ess.getUser(event.getPlayer());
- if (prot.getSettingBool(ProtectConfig.disable_build) && !user.isAuthorized(Permissions.BUILD))
+ if (!user.isAuthorized(Permissions.BUILD))
{
event.setCancelled(true);
return;
@@ -238,8 +274,7 @@ public class EssentialsProtectBlockListener extends BlockListener
final Block block = event.getBlock();
final int typeId = block.getTypeId();
- if (prot.checkProtectionItems(ProtectConfig.blacklist_break, typeId)
- && !user.isAuthorized("essentials.protect.exemptbreak"))
+ if (!user.isAuthorized(BlockBreakPermissions.getPermission(block.getType())))
{
event.setCancelled(true);
return;
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index 41b4a69a5..05e062b0b 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -145,43 +145,38 @@ public class EssentialsProtectEntityListener extends EntityListener
if (target instanceof Player)
{
if (cause == DamageCause.FALL
- && prot.getSettingBool(ProtectConfig.disable_fall)
- && !(user.isAuthorized("essentials.protect.damage.fall")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_FALL)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.SUFFOCATION
- && prot.getSettingBool(ProtectConfig.disable_suffocate)
- && !(user.isAuthorized("essentials.protect.damage.suffocation")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_SUFFOCATION)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
{
event.setCancelled(true);
return;
}
if ((cause == DamageCause.FIRE
|| cause == DamageCause.FIRE_TICK)
- && prot.getSettingBool(ProtectConfig.disable_firedmg)
- && !(user.isAuthorized("essentials.protect.damage.fire")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_FIRE)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.DROWNING
- && prot.getSettingBool(ProtectConfig.disable_drown)
- && !(user.isAuthorized("essentials.protect.damage.drowning")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_DROWNING)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
{
event.setCancelled(true);
return;
}
if (cause == DamageCause.LIGHTNING
- && prot.getSettingBool(ProtectConfig.disable_lightning)
- && !(user.isAuthorized("essentials.protect.damage.lightning")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_LIGHTNING)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
{
event.setCancelled(true);
return;
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java b/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java
index 0fedc33cf..20826bf36 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java
@@ -9,9 +9,15 @@ import org.bukkit.permissions.PermissionDefault;
public enum Permissions implements IPermission
{
- BUILD,
- PREVENTDAMAGE_FALL,
- PREVENTDAMAGE_NONE
+ BUILD(PermissionDefault.TRUE),
+ INTERACT(PermissionDefault.TRUE),
+ USEFLINTSTEEL(PermissionDefault.TRUE),
+ PREVENTDAMAGE_FALL(PermissionDefault.FALSE),
+ PREVENTDAMAGE_SUFFOCATION(PermissionDefault.FALSE),
+ PREVENTDAMAGE_FIRE(PermissionDefault.FALSE),
+ PREVENTDAMAGE_DROWNING(PermissionDefault.FALSE),
+ PREVENTDAMAGE_LIGHTNING(PermissionDefault.FALSE),
+ PREVENTDAMAGE_NONE(PermissionDefault.FALSE)
;
private static final String base = "essentials.protect.";
private final String permission;