diff options
author | ementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-05 19:09:29 +0000 |
---|---|---|
committer | ementalo <ementalo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-06-05 19:09:29 +0000 |
commit | 3c05ce0d634af8799c34e695167028e44bbe7b19 (patch) | |
tree | 863272e79205946586b108ce71ec8192e475e1c9 /EssentialsProtect/src/com/earth2me/essentials | |
parent | c6ab274f2e8436c06473c42e285eab69eaa5d5ad (diff) | |
download | Essentials-3c05ce0d634af8799c34e695167028e44bbe7b19.tar Essentials-3c05ce0d634af8799c34e695167028e44bbe7b19.tar.gz Essentials-3c05ce0d634af8799c34e695167028e44bbe7b19.tar.lz Essentials-3c05ce0d634af8799c34e695167028e44bbe7b19.tar.xz Essentials-3c05ce0d634af8799c34e695167028e44bbe7b19.zip |
[trunk] Protect, more merges
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1586 e251c2fe-e539-e718-e476-b85c1f46cddb
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials')
3 files changed, 124 insertions, 18 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java index b3daf4e0b..4518544ee 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java @@ -50,8 +50,6 @@ public class EssentialsProtect extends JavaPlugin implements IConf public void onEnable() { - - ess = Essentials.getStatic(); ess.getDependancyChecker().checkProtectDependancies(); PluginManager pm = this.getServer().getPluginManager(); @@ -90,7 +88,6 @@ public class EssentialsProtect extends JavaPlugin implements IConf { genSettings.clear(); dataSettings.clear(); - blockListener = null; playerListener = null; entityListener = null; diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java index f3c7968aa..4029e273f 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectBlockListener.java @@ -110,6 +110,13 @@ public class EssentialsProtectBlockListener extends BlockListener event.setCancelled(true); return; } + if (event.getBlock().getType() == Material.OBSIDIAN || + event.getBlock().getFace(BlockFace.DOWN).getType() == Material.OBSIDIAN) + { + event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.portal-creation")); + return; + } + if ((event.getCause().equals(BlockIgniteEvent.IgniteCause.SPREAD))) { event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.fire-spread")); @@ -127,6 +134,11 @@ public class EssentialsProtectBlockListener extends BlockListener event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.lava-fire-spread")); return; } + if (event.getCause().equals(BlockIgniteEvent.IgniteCause.LIGHTNING)) + { + event.setCancelled(EssentialsProtect.guardSettings.get("protect.prevent.lightning-fire-spread")); + return; + } } @Override diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java index f82ee9c7a..ab49944d2 100644 --- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java +++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtectEntityListener.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.protect;
import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.EssentialsBlockListener;
import com.earth2me.essentials.User;
import java.util.ArrayList;
import java.util.HashSet;
@@ -8,7 +9,9 @@ import java.util.List; import net.minecraft.server.ChunkPosition;
import net.minecraft.server.Packet60Explosion;
import org.bukkit.Location;
+import org.bukkit.Material;
import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
@@ -25,6 +28,8 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
public class EssentialsProtectEntityListener extends EntityListener
@@ -39,22 +44,34 @@ public class EssentialsProtectEntityListener extends EntityListener @Override
public void onEntityDamage(EntityDamageEvent event)
{
- if (event.isCancelled()) return;
+ if (event.isCancelled())
+ {
+ return;
+ }
if (event instanceof EntityDamageByBlockEvent)
{
DamageCause cause = event.getCause();
- if (EssentialsProtect.playerSettings.get("protect.disable.contactdmg") && cause == DamageCause.CONTACT)
+ if (EssentialsProtect.playerSettings.get("protect.disable.contactdmg") && cause == DamageCause.CONTACT
+ && !(event.getEntity() instanceof Player
+ && Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.contact")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
}
- if (EssentialsProtect.playerSettings.get("protect.disable.lavadmg") && cause == DamageCause.LAVA)
+ if (EssentialsProtect.playerSettings.get("protect.disable.lavadmg") && cause == DamageCause.LAVA
+ && !(event.getEntity() instanceof Player
+ && Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.lava")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
}
- if (EssentialsProtect.guardSettings.get("protect.prevent.tnt-explosion") && cause == DamageCause.BLOCK_EXPLOSION)
+ if (EssentialsProtect.guardSettings.get("protect.prevent.tnt-explosion") && cause == DamageCause.BLOCK_EXPLOSION
+ && !(event.getEntity() instanceof Player
+ && Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.tnt")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
@@ -85,13 +102,19 @@ public class EssentialsProtectEntityListener extends EntityListener //Creeper explode prevention
if (eAttack != null && eAttack instanceof Monster)
{
- if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion"))
+ if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-explosion")
+ && !(event.getEntity() instanceof Player
+ && Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.creeper")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
}
- if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-playerdamage"))
+ if (eAttack instanceof Creeper && EssentialsProtect.guardSettings.get("protect.prevent.creeper-playerdamage")
+ && !(event.getEntity() instanceof Player
+ && Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.creeper")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
@@ -101,9 +124,12 @@ public class EssentialsProtectEntityListener extends EntityListener if (event instanceof EntityDamageByProjectileEvent)
{
- if (event.getEntity() instanceof Player)
+ if (event.getEntity() instanceof Player
+ && EssentialsProtect.playerSettings.get("protect.disable.projectiles")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.projectiles")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable"))
{
- event.setCancelled(EssentialsProtect.playerSettings.get("protect.disable.projectiles"));
+ event.setCancelled(true);
return;
}
}
@@ -112,24 +138,39 @@ public class EssentialsProtectEntityListener extends EntityListener Entity casualty = event.getEntity();
if (casualty instanceof Player)
{
- if (EssentialsProtect.playerSettings.get("protect.disable.fall") && cause == DamageCause.FALL)
+ if (EssentialsProtect.playerSettings.get("protect.disable.fall") && cause == DamageCause.FALL
+ && !(Essentials.getStatic().getUser(casualty).isAuthorized("essentials.protect.damage.fall")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
}
- if (EssentialsProtect.playerSettings.get("protect.disable.suffocate") && cause == DamageCause.SUFFOCATION)
+ if (EssentialsProtect.playerSettings.get("protect.disable.suffocate") && cause == DamageCause.SUFFOCATION
+ && !(Essentials.getStatic().getUser(casualty).isAuthorized("essentials.protect.damage.suffocation")
+ && !Essentials.getStatic().getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
}
if (EssentialsProtect.playerSettings.get("protect.disable.firedmg") && (cause == DamageCause.FIRE
- || cause == DamageCause.FIRE_TICK))
+ || cause == DamageCause.FIRE_TICK)
+ && !(parent.ess.getUser(casualty).isAuthorized("essentials.protect.damage.fire")
+ && !parent.ess.getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (EssentialsProtect.playerSettings.get("protect.disable.drown") && cause == DamageCause.DROWNING
+ && !(parent.ess.getUser(casualty).isAuthorized("essentials.protect.damage.drowning")
+ && !parent.ess.getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
}
- if (EssentialsProtect.playerSettings.get("protect.disable.drown") && cause == DamageCause.DROWNING)
+ if (EssentialsProtect.playerSettings.get("protect.disable.lightning") && cause == DamageCause.LIGHTNING
+ && !(parent.ess.getUser(casualty).isAuthorized("essentials.protect.damage.lightning")
+ && !parent.ess.getUser(event.getEntity()).isAuthorized("essentials.protect.damage.disable")))
{
event.setCancelled(true);
return;
@@ -140,7 +181,10 @@ public class EssentialsProtectEntityListener extends EntityListener @Override
public void onEntityExplode(EntityExplodeEvent event)
{
- if (event.isCancelled()) return;
+ if (event.isCancelled())
+ {
+ return;
+ }
if (event.getEntity() instanceof LivingEntity)
{
//Nicccccccccce plaaacccccccccce..
@@ -188,13 +232,48 @@ public class EssentialsProtectEntityListener extends EntityListener 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.getType() == Material.RAILS || block.getFace(BlockFace.UP).getType() == Material.RAILS) && EssentialsProtect.genSettings.get("protect.protect.rails"))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if ((block.getType() == Material.WALL_SIGN
+ || block.getFace(BlockFace.NORTH).getType() == Material.WALL_SIGN
+ || block.getFace(BlockFace.EAST).getType() == Material.WALL_SIGN
+ || block.getFace(BlockFace.SOUTH).getType() == Material.WALL_SIGN
+ || block.getFace(BlockFace.WEST).getType() == Material.WALL_SIGN
+ || block.getType() == Material.SIGN_POST
+ || block.getFace(BlockFace.UP).getType() == Material.SIGN_POST)
+ && EssentialsProtect.genSettings.get("protect.protect.signs"))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (EssentialsBlockListener.protectedBlocks.contains(block.getType())
+ && EssentialsBlockListener.isBlockProtected(block))
+ {
+ event.setCancelled(true);
+ return;
+ }
+ }
}
@Override
public void onCreatureSpawn(CreatureSpawnEvent event)
{
- if (event.getEntity() instanceof CraftPlayer || event.isCancelled()){ return;}
- final String creatureName = event.getCreatureType().toString().toLowerCase();
+ if (event.getEntity() instanceof CraftPlayer)
+ {
+ return;
+ }
+ if (event.isCancelled())
+ {
+ return;
+ }
+ String creatureName = event.getCreatureType().toString().toLowerCase();
if (creatureName == null || creatureName.isEmpty())
{
return;
@@ -202,6 +281,24 @@ public class EssentialsProtectEntityListener extends EntityListener if (EssentialsProtect.guardSettings.get("protect.prevent.spawn." + creatureName))
{
event.setCancelled(true);
+ }
+ }
+
+ @Override
+ public void onEntityTarget(EntityTargetEvent event)
+ {
+ if (!(event.getTarget() instanceof Player))
+ {
+ return;
+ }
+ User user = Essentials.getStatic().getUser(event.getTarget());
+ if ((event.getReason() == TargetReason.CLOSEST_PLAYER
+ || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY
+ || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET)
+ && EssentialsProtect.guardSettings.get("protect.prevent.entitytarget")
+ && !user.isAuthorized("essentials.protect.entitytarget.bypass"))
+ {
+ event.setCancelled(true);
return;
}
}
|