summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsProtect/src/com')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java26
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java112
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java5
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/log4j.properties4
4 files changed, 88 insertions, 59 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
index 06dc03656..0ccf6917f 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
@@ -1,9 +1,11 @@
package com.earth2me.essentials.protect;
import com.earth2me.essentials.protect.data.IProtectedBlock;
+import com.mchange.v2.log.MLevel;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -27,14 +29,20 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
@Override
public void onLoad()
{
- C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
- C3P0logger.setFilter(new Filter()
+ try
+ {
+ // Simple fix for the case that log4j is on the class path by another plugin
+ Class propertyConfiguratorClass = Class.forName("org.apache.log4j.PropertyConfigurator");
+ Properties properties = new Properties();
+ properties.load(this.getClass().getResourceAsStream("log4j.properties"));
+ propertyConfiguratorClass.getMethod("configure", Properties.class).invoke(null, properties);
+ }
+ catch (Exception ex)
{
- public boolean isLoggable(LogRecord lr)
- {
- return lr.getLevel() != Level.INFO;
- }
- });
+ //Ignore me, log4j not found on classloader.
+ }
+ C3P0logger = com.mchange.v2.log.MLog.getLogger(com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.class);
+ C3P0logger.setLevel(MLevel.WARNING);
}
public void onEnable()
@@ -65,7 +73,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
{
final EmergencyListener emListener = new EmergencyListener();
pm.registerEvents(emListener, this);
-
+
for (Player player : getServer().getOnlinePlayers())
{
player.sendMessage("Essentials Protect is in emergency mode. Check your log for errors.");
@@ -89,7 +97,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect
{
return ess;
}
-
+
public Map<ProtectConfig, Boolean> getSettingsBoolean()
{
return settingsBoolean;
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
index ef556c9bd..1ca9519ce 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java
@@ -10,9 +10,9 @@ import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
+import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
-import org.bukkit.event.entity.*;
public class EssentialsProtectEntityListener implements Listener
@@ -38,33 +38,27 @@ public class EssentialsProtectEntityListener implements Listener
}
final User user = ess.getUser(target);
+ final DamageCause cause = event.getCause();
+
if (event instanceof EntityDamageByBlockEvent)
{
- final DamageCause cause = event.getCause();
-
if (prot.getSettingBool(ProtectConfig.disable_contactdmg)
&& cause == DamageCause.CONTACT
- && !(target instanceof Player
- && user.isAuthorized("essentials.protect.damage.contact")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !(target instanceof Player && shouldBeDamaged(user, "contact")))
{
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")))
+ && !(target instanceof Player && shouldBeDamaged(user, "lava")))
{
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")))
+ && !(target instanceof Player && shouldBeDamaged(user, "tnt")))
{
event.setCancelled(true);
return;
@@ -77,48 +71,43 @@ public class EssentialsProtectEntityListener implements Listener
final Entity eAttack = edEvent.getDamager();
final User attacker = ess.getUser(eAttack);
- // PVP Settings
- if (target instanceof Player && eAttack instanceof Player
- && prot.getSettingBool(ProtectConfig.disable_pvp)
- && (!user.isAuthorized("essentials.protect.pvp") || !attacker.isAuthorized("essentials.protect.pvp")))
+ //Creeper explode prevention
+ if (eAttack instanceof Creeper
+ && (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
+ || prot.getSettingBool(ProtectConfig.prevent_creeper_playerdmg))
+ && !(target instanceof Player && shouldBeDamaged(user, "creeper")))
{
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")))
+ if ((event.getEntity() instanceof Fireball || event.getEntity() instanceof SmallFireball)
+ && prot.getSettingBool(ProtectConfig.prevent_fireball_playerdmg)
+ && !(target instanceof Player && shouldBeDamaged(user, "fireball")))
{
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")))
+ if (event.getEntity() instanceof WitherSkull
+ && prot.getSettingBool(ProtectConfig.prevent_witherskull_playerdmg)
+ && !(target instanceof Player && shouldBeDamaged(user, "witherskull")))
{
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")))
+ if (eAttack instanceof TNTPrimed && prot.getSettingBool(ProtectConfig.prevent_tnt_playerdmg)
+ && !(target instanceof Player && shouldBeDamaged(user, "tnt")))
{
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")))
+ // 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;
@@ -126,9 +115,7 @@ public class EssentialsProtectEntityListener implements Listener
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")))
+ && ((prot.getSettingBool(ProtectConfig.disable_projectiles) && !shouldBeDamaged(user, "projectiles"))
|| (((Projectile)edEvent.getDamager()).getShooter() instanceof Player
&& prot.getSettingBool(ProtectConfig.disable_pvp)
&& (!user.isAuthorized("essentials.protect.pvp")
@@ -139,13 +126,11 @@ public class EssentialsProtectEntityListener implements Listener
}
}
- final DamageCause cause = event.getCause();
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")))
+ && !shouldBeDamaged(user, "fall"))
{
event.setCancelled(true);
return;
@@ -153,33 +138,35 @@ public class EssentialsProtectEntityListener implements Listener
if (cause == DamageCause.SUFFOCATION
&& prot.getSettingBool(ProtectConfig.disable_suffocate)
- && !(user.isAuthorized("essentials.protect.damage.suffocation")
- && !user.isAuthorized("essentials.protect.damage.disable")))
+ && !shouldBeDamaged(user, "suffocation"))
{
event.setCancelled(true);
return;
}
- if ((cause == DamageCause.FIRE
- || cause == DamageCause.FIRE_TICK)
+ 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")))
+ && !shouldBeDamaged(user, "fire"))
{
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")))
+ && !shouldBeDamaged(user, "drowning"))
{
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")))
+ && !shouldBeDamaged(user, "lightning"))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (cause == DamageCause.WITHER
+ && prot.getSettingBool(ProtectConfig.disable_wither)
+ && !shouldBeDamaged(user, "wither"))
{
event.setCancelled(true);
return;
@@ -187,6 +174,12 @@ public class EssentialsProtectEntityListener implements Listener
}
}
+ private boolean shouldBeDamaged(final User user, final String type)
+ {
+ return (user.isAuthorized("essentials.protect.damage.".concat(type))
+ && !user.isAuthorized("essentials.protect.damage.disable"));
+ }
+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityExplode(final EntityExplodeEvent event)
{
@@ -206,6 +199,12 @@ public class EssentialsProtectEntityListener implements Listener
}
return;
}
+ if (event.getEntity() instanceof Wither
+ && prot.getSettingBool(ProtectConfig.prevent_wither_spawnexplosion))
+ {
+ event.setCancelled(true);
+ return;
+ }
else if (event.getEntity() instanceof Creeper
&& (prot.getSettingBool(ProtectConfig.prevent_creeper_explosion)
|| prot.getSettingBool(ProtectConfig.prevent_creeper_blockdmg)
@@ -228,6 +227,13 @@ public class EssentialsProtectEntityListener implements Listener
event.setCancelled(true);
return;
}
+ else if ((event.getEntity() instanceof WitherSkull)
+ && prot.getSettingBool(ProtectConfig.prevent_witherskull_explosion))
+ {
+ event.setCancelled(true);
+ return;
+ }
+
// This code will prevent explosions near protected rails, signs or protected chests
// TODO: Use protect db instead of this code
@@ -294,6 +300,7 @@ public class EssentialsProtectEntityListener implements Listener
|| event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
|| event.getReason() == TargetReason.PIG_ZOMBIE_TARGET
|| event.getReason() == TargetReason.RANDOM_TARGET
+ || event.getReason() == TargetReason.DEFEND_VILLAGE
|| event.getReason() == TargetReason.TARGET_ATTACKED_OWNER
|| event.getReason() == TargetReason.OWNER_ATTACKED_TARGET)
&& prot.getSettingBool(ProtectConfig.prevent_entitytarget)
@@ -322,5 +329,10 @@ public class EssentialsProtectEntityListener implements Listener
event.setCancelled(true);
return;
}
+ if (event.getEntityType() == EntityType.WITHER && prot.getSettingBool(ProtectConfig.prevent_wither_blockreplace))
+ {
+ event.setCancelled(true);
+ return;
+ }
}
}
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java
index 31141d7e7..d7f428539 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/ProtectConfig.java
@@ -17,6 +17,7 @@ public enum ProtectConfig
disable_firedmg("protect.disable.firedmg", false),
disable_lightning("protect.disable.lightning", false),
disable_drown("protect.disable.drown", false),
+ disable_wither("protect.disable.wither", false),
disable_weather_storm("protect.disable.weather.storm", false),
disable_weather_lightning("protect.disable.weather.lightning", false),
disable_weather_thunder("protect.disable.weather.thunder", false),
@@ -34,6 +35,10 @@ public enum ProtectConfig
prevent_fireball_explosion("protect.prevent.fireball-explosion", false),
prevent_fireball_fire("protect.prevent.fireball-fire", false),
prevent_fireball_playerdmg("protect.prevent.fireball-playerdamage", false),
+ prevent_witherskull_explosion("protect.prevent.witherskull-explosion", false),
+ prevent_witherskull_playerdmg("protect.prevent.witherskull-playerdamage", false),
+ prevent_wither_spawnexplosion("protect.prevent.wither-spawnexplosion", false),
+ prevent_wither_blockreplace("protect.prevent.wither-blockreplace", false),
prevent_creeper_explosion("protect.prevent.creeper-explosion", true),
prevent_creeper_playerdmg("protect.prevent.creeper-playerdamage", false),
prevent_creeper_blockdmg("protect.prevent.creeper-blockdamage", false),
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/log4j.properties b/EssentialsProtect/src/com/earth2me/essentials/protect/log4j.properties
new file mode 100644
index 000000000..2642ee541
--- /dev/null
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/log4j.properties
@@ -0,0 +1,4 @@
+log4j.rootLogger=INFO, A1
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file