Added permissions to bypass EssentialsProtect damage protection.

As admin you want to disable this with
- -essentials.protect.damage.*

New permissions:
essentials.protect.damage.contact
essentials.protect.damage.lava
essentials.protect.damage.tnt
essentials.protect.damage.creeper
essentials.protect.damage.projectiles
essentials.protect.damage.fall
essentials.protect.damage.suffocation
essentials.protect.damage.fire
essentials.protect.damage.drowning
essentials.protect.damage.lightning

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1476 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-05-15 12:10:24 +00:00
parent 32989d56b6
commit a0b5e8d0f8
3 changed files with 72 additions and 43 deletions

View File

@ -139,6 +139,7 @@ groups:
default: false
permissions:
- '*'
- -essentials.protect.damage.*
inheritance:
- semiadmin
info:

View File

@ -43,22 +43,31 @@ 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")))
{
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")))
{
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")))
{
event.setCancelled(true);
return;
@ -89,13 +98,17 @@ 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")))
{
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")))
{
event.setCancelled(true);
return;
@ -105,40 +118,47 @@ 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"))
{
event.setCancelled(EssentialsProtect.playerSettings.get("protect.disable.projectiles"));
event.setCancelled(true);
return;
}
}
DamageCause cause = event.getCause();
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")))
{
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")))
{
event.setCancelled(true);
return;
}
if (EssentialsProtect.playerSettings.get("protect.disable.firedmg") && (cause == DamageCause.FIRE
|| cause == DamageCause.FIRE_TICK))
|| cause == DamageCause.FIRE_TICK)
&& !(Essentials.getStatic().getUser(casualty).isAuthorized("essentials.protect.damage.fire")))
{
event.setCancelled(true);
return;
}
if (EssentialsProtect.playerSettings.get("protect.disable.drown") && cause == DamageCause.DROWNING)
if (EssentialsProtect.playerSettings.get("protect.disable.drown") && cause == DamageCause.DROWNING
&& !(Essentials.getStatic().getUser(casualty).isAuthorized("essentials.protect.damage.drowning")))
{
event.setCancelled(true);
return;
}
if (EssentialsProtect.playerSettings.get("protect.disable.lightning") && cause == DamageCause.LIGHTNING)
if (EssentialsProtect.playerSettings.get("protect.disable.lightning") && cause == DamageCause.LIGHTNING
&& !(Essentials.getStatic().getUser(casualty).isAuthorized("essentials.protect.damage.lightning")))
{
event.setCancelled(true);
return;
@ -149,7 +169,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..
@ -183,7 +206,7 @@ public class EssentialsProtectEntityListener extends EntityListener
}
((CraftServer)parent.getServer()).getHandle().a(loc.getX(), loc.getY(), loc.getZ(), 64.0D,
new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set));
new Packet60Explosion(loc.getX(), loc.getY(), loc.getZ(), 3.0f, set));
event.setCancelled(true);
return;
}
@ -205,20 +228,21 @@ public class EssentialsProtectEntityListener extends EntityListener
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"))
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)) {
if (EssentialsBlockListener.protectedBlocks.contains(block.getType())
&& EssentialsBlockListener.isBlockProtected(block))
{
event.setCancelled(true);
return;
}
@ -228,8 +252,14 @@ public class EssentialsProtectEntityListener extends EntityListener
@Override
public void onCreatureSpawn(CreatureSpawnEvent event)
{
if (event.getEntity() instanceof CraftPlayer) return;
if (event.isCancelled()) return;
if (event.getEntity() instanceof CraftPlayer)
{
return;
}
if (event.isCancelled())
{
return;
}
String creatureName = event.getCreatureType().toString().toLowerCase();
if (creatureName == null || creatureName.isEmpty())
{
@ -242,22 +272,21 @@ public class EssentialsProtectEntityListener extends EntityListener
}
@Override
public void onEntityTarget(EntityTargetEvent event) {
if (!(event.getTarget() instanceof Player)) {
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;
}
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;
}
}
}

View File

@ -3,7 +3,6 @@ package com.earth2me.essentials.protect;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;