summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2012-01-10 00:36:09 +0100
committersnowleo <schneeleo@gmail.com>2012-01-10 00:36:09 +0100
commitd64c73fc51817b3698510b7eea0cdfa274a58c63 (patch)
tree0bc93405243133606e61cd1d1bbfadec4003abf4 /EssentialsProtect
parent92abba0f25014ff64a94b27a0e00b2ef6e83fa0b (diff)
downloadEssentials-d64c73fc51817b3698510b7eea0cdfa274a58c63.tar
Essentials-d64c73fc51817b3698510b7eea0cdfa274a58c63.tar.gz
Essentials-d64c73fc51817b3698510b7eea0cdfa274a58c63.tar.lz
Essentials-d64c73fc51817b3698510b7eea0cdfa274a58c63.tar.xz
Essentials-d64c73fc51817b3698510b7eea0cdfa274a58c63.zip
Finished Protect, Essentials should build now.
Diffstat (limited to 'EssentialsProtect')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java79
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java228
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java406
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java88
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectWeatherListener.java50
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/ItemUsePermissions.java42
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java11
7 files changed, 513 insertions, 391 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java
index 6f724ac87..b208b5e43 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsConnect.java
@@ -72,54 +72,59 @@ public class EssentialsConnect
{
protect.getStorage().onPluginDeactivation();
}
-
- /*for (ProtectConfig protectConfig : ProtectConfig.values())
- {
- if (protectConfig.isList())
- {
- protect.getSettingsList().put(protectConfig, ess.getSettings().getProtectList(protectConfig.getConfigName()));
- }
- else if (protectConfig.isString())
- {
- protect.getSettingsString().put(protectConfig, ess.getSettings().getProtectString(protectConfig.getConfigName()));
- }
- else
- {
- protect.getSettingsBoolean().put(protectConfig, ess.getSettings().getProtectBoolean(protectConfig.getConfigName(), protectConfig.getDefaultValueBoolean()));
- }
- }*/
+ /*
+ * for (ProtectConfig protectConfig : ProtectConfig.values()) { if (protectConfig.isList()) {
+ * protect.getSettingsList().put(protectConfig,
+ * ess.getSettings().getProtectList(protectConfig.getConfigName())); } else if (protectConfig.isString()) {
+ * protect.getSettingsString().put(protectConfig,
+ * ess.getSettings().getProtectString(protectConfig.getConfigName())); } else {
+ * protect.getSettingsBoolean().put(protectConfig,
+ * ess.getSettings().getProtectBoolean(protectConfig.getConfigName(),
+ * protectConfig.getDefaultValueBoolean())); }
+ *
+ * }
+ */
- if (protect.getSettingString(ProtectConfig.datatype).equalsIgnoreCase("mysql"))
+ ProtectHolder settings = protect.getSettings();
+ settings.acquireReadLock();
+ try
{
- try
+ if (settings.getData().getDbtype().equalsIgnoreCase("mysql"))
{
- protect.setStorage(new ProtectedBlockMySQL(
- protect.getSettingString(ProtectConfig.mysqlDB),
- protect.getSettingString(ProtectConfig.dbUsername),
- protect.getSettingString(ProtectConfig.dbPassword)));
+ try
+ {
+ protect.setStorage(new ProtectedBlockMySQL(
+ settings.getData().getDburl(),
+ settings.getData().getDbuser(),
+ settings.getData().getDbpassword()));
+ }
+ catch (PropertyVetoException ex)
+ {
+ LOGGER.log(Level.SEVERE, null, ex);
+ }
}
- catch (PropertyVetoException ex)
- {
- LOGGER.log(Level.SEVERE, null, ex);
- }
- }
- else
- {
- try
+ else
{
- protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db"));
+ try
+ {
+ protect.setStorage(new ProtectedBlockSQLite("jdbc:sqlite:plugins/Essentials/EssentialsProtect.db"));
+ }
+ catch (PropertyVetoException ex)
+ {
+ LOGGER.log(Level.SEVERE, null, ex);
+ }
}
- catch (PropertyVetoException ex)
+ /*if (protect.getSettingBool(ProtectConfig.memstore))
{
- LOGGER.log(Level.SEVERE, null, ex);
- }
+ protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect));
+ }*/
+
}
- if (protect.getSettingBool(ProtectConfig.memstore))
+ finally
{
- protect.setStorage(new ProtectedBlockMemory(protect.getStorage(), protect));
+ settings.unlock();
}
-
}
}
}
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();
}
}
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index 05e062b0b..99b0c72e7 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -3,7 +3,6 @@ package com.earth2me.essentials.protect;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.craftbukkit.FakeExplosion;
-import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -20,6 +19,7 @@ public class EssentialsProtectEntityListener extends EntityListener
public EssentialsProtectEntityListener(final IProtect prot)
{
+ super();
this.prot = prot;
this.ess = prot.getEssentialsConnect().getEssentials();
}
@@ -31,228 +31,219 @@ public class EssentialsProtectEntityListener extends EntityListener
{
return;
}
- final Entity target = event.getEntity();
-
- if (target instanceof Villager && prot.getSettingBool(ProtectConfig.prevent_villager_death))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
- return;
- }
-
- final IUser user = target instanceof Player ? ess.getUser((Player)target) : null;
- if (event instanceof EntityDamageByBlockEvent)
- {
- final DamageCause cause = event.getCause();
+ final Entity target = event.getEntity();
- if (prot.getSettingBool(ProtectConfig.disable_contactdmg)
- && cause == DamageCause.CONTACT
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.contact")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ if (target instanceof Villager && settings.getData().getPrevent().isVillagerDeath())
{
event.setCancelled(true);
return;
}
- if (prot.getSettingBool(ProtectConfig.disable_lavadmg)
- && cause == DamageCause.LAVA
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.lava")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+
+ final IUser user = target instanceof Player ? ess.getUser((Player)target) : null;
+ if (target instanceof Player && event instanceof EntityDamageByBlockEvent)
{
- event.setCancelled(true);
- return;
+ final DamageCause cause = event.getCause();
+
+ if (cause == DamageCause.CONTACT
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_CONTACT)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (cause == DamageCause.LAVA
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_LAVADAMAGE)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (cause == DamageCause.BLOCK_EXPLOSION
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_TNT)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
}
- if (prot.getSettingBool(ProtectConfig.prevent_tnt_explosion)
- && cause == DamageCause.BLOCK_EXPLOSION
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.tnt")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+
+ if (target instanceof Player && event instanceof EntityDamageByEntityEvent)
{
- event.setCancelled(true);
- return;
- }
- }
+ final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
+ final Entity eAttack = edEvent.getDamager();
+ final IUser attacker = eAttack instanceof Player ? ess.getUser((Player)eAttack) : null;
- if (event instanceof EntityDamageByEntityEvent)
- {
- final EntityDamageByEntityEvent edEvent = (EntityDamageByEntityEvent)event;
- final Entity eAttack = edEvent.getDamager();
- final IUser attacker = eAttack instanceof Player ? ess.getUser((Player)eAttack) : null;
+ // PVP Settings
+ if (target instanceof Player && eAttack instanceof Player
+ && (!user.isAuthorized(Permissions.PVP) || !attacker.isAuthorized(Permissions.PVP)))
+ {
+ event.setCancelled(true);
+ return;
+ }
- // PVP Settings
- if (target instanceof Player && eAttack instanceof Player
- && prot.getSettingBool(ProtectConfig.disable_pvp)
- && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp")))
- {
- event.setCancelled(true);
- return;
- }
+ //Creeper explode prevention
+ if (eAttack instanceof Creeper && settings.getData().getPrevent().isCreeperExplosion()
+ || (user.isAuthorized(Permissions.PREVENTDAMAGE_CREEPER)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
- //Creeper explode prevention
- if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.creeper")
- && !user.isAuthorized("essentials.protect.damage.disable")))
- {
- event.setCancelled(true);
- return;
- }
+ if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_FIREBALL)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
- if (eAttack instanceof Creeper && prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.creeper")
- && !user.isAuthorized("essentials.protect.damage.disable")))
- {
- event.setCancelled(true);
- return;
- }
+ if (eAttack instanceof TNTPrimed
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_TNT)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
- if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
- && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.fireball")
- && !user.isAuthorized("essentials.protect.damage.disable")))
- {
- event.setCancelled(true);
- return;
+ if (edEvent.getDamager() instanceof Projectile
+ && ((user.isAuthorized(Permissions.PREVENTDAMAGE_PROJECTILES)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE))
+ || (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
+ && (!user.isAuthorized(Permissions.PVP)
+ || !ess.getUser((Player)((Projectile)edEvent.getDamager()).getShooter()).isAuthorized(Permissions.PVP)))))
+ {
+ event.setCancelled(true);
+ return;
+ }
}
- if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.tnt")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ final DamageCause cause = event.getCause();
+ if (target instanceof Player)
{
- event.setCancelled(true);
- return;
- }
+ if (cause == DamageCause.FALL
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_FALL)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
- if (edEvent.getDamager() instanceof Projectile
- && target instanceof Player
- && ((prot.getSettingBool(ProtectConfig.disable_projectiles)
- && !(user.isAuthorized("essentials.protect.damage.projectiles")
- && !user.isAuthorized("essentials.protect.damage.disable")))
- || (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
- && prot.getSettingBool(ProtectConfig.disable_pvp)
- && (!user.isAuthorized("essentials.protect.pvp")
- || !ess.getUser((Player)((Projectile)edEvent.getDamager()).getShooter()).isAuthorized("essentials.protect.pvp")))))
- {
- event.setCancelled(true);
- return;
+ if (cause == DamageCause.SUFFOCATION
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_SUFFOCATION)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if ((cause == DamageCause.FIRE
+ || cause == DamageCause.FIRE_TICK)
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_FIRE)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (cause == DamageCause.DROWNING
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_DROWNING)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (cause == DamageCause.LIGHTNING
+ && (user.isAuthorized(Permissions.PREVENTDAMAGE_LIGHTNING)
+ && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ {
+ event.setCancelled(true);
+ return;
+ }
}
}
+ finally
+ {
+ settings.unlock();
+ }
+ }
- final DamageCause cause = event.getCause();
- if (target instanceof Player)
+ @Override
+ public void onEntityExplode(final EntityExplodeEvent event)
+ {
+ if (event.isCancelled())
{
- if (cause == DamageCause.FALL
- && (user.isAuthorized(Permissions.PREVENTDAMAGE_FALL)
- && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
- {
- event.setCancelled(true);
- return;
- }
+ return;
+ }
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
+ {
+ final int maxHeight = settings.getData().getCreeperMaxHeight();
- if (cause == DamageCause.SUFFOCATION
- && (user.isAuthorized(Permissions.PREVENTDAMAGE_SUFFOCATION)
- && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ if (event.getEntity() instanceof EnderDragon
+ && settings.getData().getPrevent().isEnderdragonBlockdamage())
{
event.setCancelled(true);
return;
}
- if ((cause == DamageCause.FIRE
- || cause == DamageCause.FIRE_TICK)
- && (user.isAuthorized(Permissions.PREVENTDAMAGE_FIRE)
- && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ else if (event.getEntity() instanceof Creeper
+ && (settings.getData().getPrevent().isCreeperExplosion()
+ || settings.getData().getPrevent().isCreeperBlockdamage()
+ || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight)))
{
+ //Nicccccccccce plaaacccccccccce..
+ FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers());
event.setCancelled(true);
return;
}
- if (cause == DamageCause.DROWNING
- && (user.isAuthorized(Permissions.PREVENTDAMAGE_DROWNING)
- && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ else if (event.getEntity() instanceof TNTPrimed
+ && settings.getData().getPrevent().isTntExplosion())
{
event.setCancelled(true);
return;
}
- if (cause == DamageCause.LIGHTNING
- && (user.isAuthorized(Permissions.PREVENTDAMAGE_LIGHTNING)
- && !user.isAuthorized(Permissions.PREVENTDAMAGE_NONE)))
+ else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
+ && settings.getData().getPrevent().isFireballExplosion())
{
event.setCancelled(true);
return;
}
- }
- }
-
- @Override
- public void onEntityExplode(final EntityExplodeEvent event)
- {
- if (event.isCancelled())
- {
- return;
- }
- final int maxHeight = ess.getSettings().getProtectCreeperMaxHeight();
+ // This code will prevent explosions near protected rails, signs or protected chests
+ // TODO: Use protect db instead of this code
- if (event.getEntity() instanceof EnderDragon
- && prot.getSettingBool(ProtectConfig.prevent_enderdragon_blockdmg))
- {
- if (prot.getSettingBool(ProtectConfig.enderdragon_fakeexplosions))
+ for (Block block : event.blockList())
{
- FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers());
+ 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 ((block.getType() == Material.WALL_SIGN
+ || block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
+ || block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
+ || block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
+ || block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
+ || block.getType() == Material.SIGN_POST
+ || block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
+ && settings.getData().getSignsAndRails().isProtectSigns())
+ {
+ event.setCancelled(true);
+ return;
+ }
}
- event.setCancelled(true);
- return;
- }
- else if (event.getEntity() instanceof Creeper
- && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
- || prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
- || (maxHeight >= 0 && event.getLocation().getBlockY() > maxHeight)))
- {
- //Nicccccccccce plaaacccccccccce..
- FakeExplosion.createExplosion(event, ess.getServer(), ess.getServer().getOnlinePlayers());
- event.setCancelled(true);
- return;
- }
- else if (event.getEntity() instanceof TNTPrimed
- && prot.getSettingBool(ProtectConfig.prevent_tnt_explosion))
- {
- event.setCancelled(true);
- return;
}
- else if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
- && prot.getSettingBool(ProtectConfig.prevent_fireball_explosion))
+ finally
{
- event.setCancelled(true);
- return;
- }
- // This code will prevent explosions near protected rails, signs or protected chests
- // TODO: Use protect db instead of this code
-
- for (Block block : event.blockList())
- {
- 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 ((block.getType() == Material.WALL_SIGN
- || block.getRelative(BlockFace.NORTH).getType() == Material.WALL_SIGN
- || block.getRelative(BlockFace.EAST).getType() == Material.WALL_SIGN
- || block.getRelative(BlockFace.SOUTH).getType() == Material.WALL_SIGN
- || block.getRelative(BlockFace.WEST).getType() == Material.WALL_SIGN
- || block.getType() == Material.SIGN_POST
- || block.getRelative(BlockFace.UP).getType() == Material.SIGN_POST)
- && prot.getSettingBool(ProtectConfig.protect_signs))
- {
- event.setCancelled(true);
- return;
- }
+ settings.unlock();
}
}
@@ -272,25 +263,26 @@ public class EssentialsProtectEntityListener extends EntityListener
{
return;
}
- final String creatureName = creature.toString().toLowerCase(Locale.ENGLISH);
- if (creatureName == null || creatureName.isEmpty())
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- return;
+ final Boolean prevent = settings.getData().getPrevent().getSpawn().get(creature);
+ if (prevent != null && prevent)
+ {
+ event.setCancelled(true);
+ }
}
- if (ess.getSettings().getProtectPreventSpawn(creatureName))
+ finally
{
- event.setCancelled(true);
+ settings.unlock();
}
}
@Override
public void onEntityTarget(final EntityTargetEvent event)
{
- if (event.isCancelled())
- {
- return;
- }
- if (!(event.getTarget() instanceof Player))
+ if (event.isCancelled() || !(event.getTarget() instanceof Player))
{
return;
}
@@ -301,8 +293,7 @@ public class EssentialsProtectEntityListener extends EntityListener
|| event.getReason() == TargetReason.RANDOM_TARGET
|| event.getReason() == TargetReason.TARGET_ATTACKED_OWNER
|| event.getReason() == TargetReason.OWNER_ATTACKED_TARGET)
- && prot.getSettingBool(ProtectConfig.prevent_entitytarget)
- && !user.isAuthorized("essentials.protect.entitytarget.bypass"))
+ && user.isAuthorized(Permissions.ENTITYTARGET))
{
event.setCancelled(true);
return;
@@ -310,26 +301,43 @@ public class EssentialsProtectEntityListener extends EntityListener
}
@Override
- public void onExplosionPrime(ExplosionPrimeEvent event)
+ public void onExplosionPrime(final ExplosionPrimeEvent event)
{
- if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
- && prot.getSettingBool(ProtectConfig.prevent_fireball_fire))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setFire(false);
+ if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
+ && settings.getData().getPrevent().isFireballFire())
+ {
+ event.setFire(false);
+ }
+ }
+ finally
+ {
+ settings.unlock();
}
}
@Override
- public void onEndermanPickup(EndermanPickupEvent event)
+ public void onEndermanPickup(final EndermanPickupEvent event)
{
if (event.isCancelled())
{
return;
}
- if (prot.getSettingBool(ProtectConfig.prevent_enderman_pickup))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
- return;
+ if (settings.getData().getPrevent().isEndermanPickup())
+ {
+ event.setCancelled(true);
+ }
+ }
+ finally
+ {
+ settings.unlock();
}
}
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java
index a3f13a428..5e6da11cc 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectPlayerListener.java
@@ -28,62 +28,70 @@ public class EssentialsProtectPlayerListener extends PlayerListener
// Do not return if cancelled, because the interact event has 2 cancelled states.
final IUser user = ess.getUser(event.getPlayer());
- if (event.hasItem()
- && (event.getItem().getType() == Material.WATER_BUCKET
- || event.getItem().getType() == Material.LAVA_BUCKET)
- && prot.getSettingBool(ProtectConfig.disable_build) && !user.canBuild())
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- if (ess.getSettings().warnOnBuildDisallow())
+ if (event.hasItem()
+ && (event.getItem().getType() == Material.WATER_BUCKET
+ || event.getItem().getType() == Material.LAVA_BUCKET)
+ && !user.isAuthorized(Permissions.BUILD))
{
- user.sendMessage(_("buildAlert"));
+ if (settings.getData().isWarnOnBuildDisallow())
+ {
+ user.sendMessage(_("buildAlert"));
+ }
+ event.setCancelled(true);
+ return;
}
- event.setCancelled(true);
- return;
- }
- if (prot.getSettingBool(ProtectConfig.disable_use) && !user.canBuild())
- {
- if (ess.getSettings().warnOnBuildDisallow())
+ if (!user.isAuthorized(Permissions.INTERACT))
{
- user.sendMessage(_("buildAlert"));
+ if (settings.getData().isWarnOnBuildDisallow())
+ {
+ user.sendMessage(_("buildAlert"));
+ }
+ event.setCancelled(true);
+ return;
}
- event.setCancelled(true);
- return;
- }
- final ItemStack item = event.getItem();
- if (item != null
- && prot.checkProtectionItems(ProtectConfig.blacklist_usage, item.getTypeId())
- && !user.isAuthorized("essentials.protect.exemptusage"))
- {
- event.setCancelled(true);
- return;
- }
+ final ItemStack item = event.getItem();
+ if (item != null
+ && !user.isAuthorized(ItemUsePermissions.getPermission(item.getType())))
+ {
+ event.setCancelled(true);
+ return;
+ }
- if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK)
- {
- final StringBuilder stringBuilder = new StringBuilder();
- boolean first = true;
- final Block blockClicked = event.getClickedBlock();
- for (String owner : prot.getStorage().getOwners(blockClicked))
+ if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK)
{
- if (!first)
+ final StringBuilder stringBuilder = new StringBuilder();
+ boolean first = true;
+ final Block blockClicked = event.getClickedBlock();
+ for (String owner : prot.getStorage().getOwners(blockClicked))
+ {
+ if (!first)
+ {
+ stringBuilder.append(", ");
+ }
+ first = false;
+ stringBuilder.append(owner);
+ }
+ final String ownerNames = stringBuilder.toString();
+ if (ownerNames != null && !ownerNames.isEmpty())
{
- stringBuilder.append(", ");
+ user.sendMessage(_("protectionOwner", ownerNames));
}
- first = false;
- stringBuilder.append(owner);
}
- final String ownerNames = stringBuilder.toString();
- if (ownerNames != null && !ownerNames.isEmpty())
+ if (item != null
+ && settings.getData().getAlertOnUse().contains(item.getType()))
{
- user.sendMessage(_("protectionOwner", ownerNames));
+ prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
}
}
- if (item != null
- && prot.checkProtectionItems(ProtectConfig.alert_on_use, item.getTypeId()))
+ finally
{
- prot.getEssentialsConnect().alert(user, item.getType().toString(), _("alertUsed"));
+ settings.unlock();
}
}
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectWeatherListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectWeatherListener.java
index e81efc72b..4097275dd 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectWeatherListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectWeatherListener.java
@@ -18,33 +18,59 @@ public class EssentialsProtectWeatherListener extends WeatherListener
@Override
public void onWeatherChange(final WeatherChangeEvent event)
{
- if (!event.isCancelled()
- && prot.getSettingBool(ProtectConfig.disable_weather_storm)
- && event.toWeatherState())
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
+ if (!event.isCancelled()
+ && settings.getData().isDisableStorm()
+ && event.toWeatherState())
+ {
+ event.setCancelled(true);
+ }
+ }
+ finally
+ {
+ settings.unlock();
}
-
}
@Override
public void onLightningStrike(final LightningStrikeEvent event)
{
- if (!event.isCancelled()
- && prot.getSettingBool(ProtectConfig.disable_weather_lightning))
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
{
- event.setCancelled(true);
+ if (!event.isCancelled()
+ && settings.getData().isDisableLighting())
+ {
+ event.setCancelled(true);
+ }
+ }
+ finally
+ {
+ settings.unlock();
}
}
@Override
public void onThunderChange(final ThunderChangeEvent event)
{
- if (!event.isCancelled()
- && prot.getSettingBool(ProtectConfig.disable_weather_thunder)
- && event.toThunderState())
+ final ProtectHolder settings = prot.getSettings();
+ settings.acquireReadLock();
+ try
+ {
+ if (!event.isCancelled()
+ && settings.getData().isDisableThunder()
+ && event.toThunderState())
+ {
+ event.setCancelled(true);
+ }
+ }
+ finally
{
- event.setCancelled(true);
+ settings.unlock();
}
}
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ItemUsePermissions.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ItemUsePermissions.java
new file mode 100644
index 000000000..258a93761
--- /dev/null
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ItemUsePermissions.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 ItemUsePermissions extends AbstractSuperpermsPermission{
+ private static Map<Material,IPermission> permissions = new EnumMap<Material, IPermission>(Material.class);
+ private static final String base = "essentials.protect.itemuse.";
+ private final String permission;
+
+ public static IPermission getPermission(Material mat)
+ {
+ IPermission perm = permissions.get(mat);
+ if (perm == null) {
+ perm = new ItemUsePermissions(mat.toString().toLowerCase(Locale.ENGLISH));
+ permissions.put(mat, perm);
+ }
+ return perm;
+ }
+
+ private ItemUsePermissions(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/Permissions.java b/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java
index 20826bf36..61ac1b295 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/Permissions.java
@@ -12,13 +12,20 @@ public enum Permissions implements IPermission
BUILD(PermissionDefault.TRUE),
INTERACT(PermissionDefault.TRUE),
USEFLINTSTEEL(PermissionDefault.TRUE),
+ PVP(PermissionDefault.TRUE),
+ ENTITYTARGET(PermissionDefault.TRUE),
PREVENTDAMAGE_FALL(PermissionDefault.FALSE),
+ PREVENTDAMAGE_CREEPER(PermissionDefault.FALSE),
+ PREVENTDAMAGE_CONTACT(PermissionDefault.FALSE),
+ PREVENTDAMAGE_FIREBALL(PermissionDefault.FALSE),
+ PREVENTDAMAGE_PROJECTILES(PermissionDefault.FALSE),
+ PREVENTDAMAGE_LAVADAMAGE(PermissionDefault.FALSE),
+ PREVENTDAMAGE_TNT(PermissionDefault.FALSE),
PREVENTDAMAGE_SUFFOCATION(PermissionDefault.FALSE),
PREVENTDAMAGE_FIRE(PermissionDefault.FALSE),
PREVENTDAMAGE_DROWNING(PermissionDefault.FALSE),
PREVENTDAMAGE_LIGHTNING(PermissionDefault.FALSE),
- PREVENTDAMAGE_NONE(PermissionDefault.FALSE)
- ;
+ PREVENTDAMAGE_NONE(PermissionDefault.FALSE);
private static final String base = "essentials.protect.";
private final String permission;
private final PermissionDefault defaultPerm;