Allow admins to damage pets with /IgnoreClaims.

Also protecting pets from environmental damage which could easily be
caused by griefers.
This commit is contained in:
ryanhamshire 2014-12-17 16:58:57 -08:00
parent 13e3f8fbd6
commit 14b0129c3e
2 changed files with 51 additions and 25 deletions

View File

@ -52,6 +52,7 @@ import org.bukkit.event.entity.EntityBreakDoorEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityInteractEvent;
@ -581,12 +582,19 @@ class EntityEventHandler implements Listener
{ {
Tameable tameable = (Tameable)subEvent.getEntity(); Tameable tameable = (Tameable)subEvent.getEntity();
if(tameable.isTamed() && tameable.getOwner() != null) if(tameable.isTamed() && tameable.getOwner() != null)
{
//limit attacks by players to owners and admins in ignore claims mode
if(attacker != null)
{ {
UUID ownerID = tameable.getOwner().getUniqueId(); UUID ownerID = tameable.getOwner().getUniqueId();
//if the player interacting is the owner, always allow //if the player interacting is the owner, always allow
if(attacker.getUniqueId().equals(ownerID)) return; if(attacker.getUniqueId().equals(ownerID)) return;
//allow for admin override
PlayerData attackerData = this.dataStore.getPlayerData(attacker.getUniqueId());
if(attackerData.ignoreClaims) return;
//otherwise disallow in non-pvp worlds //otherwise disallow in non-pvp worlds
if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(subEvent.getEntity().getLocation().getWorld())) if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(subEvent.getEntity().getLocation().getWorld()))
{ {
@ -601,6 +609,24 @@ class EntityEventHandler implements Listener
return; return;
} }
} }
//also limit damage sources to prevent grief of pets by build (flint/steel, lava buckets, sand...)
else
{
DamageCause cause = event.getCause();
if(cause != null && (
cause == DamageCause.ENTITY_EXPLOSION ||
cause == DamageCause.FALLING_BLOCK ||
cause == DamageCause.FIRE ||
cause == DamageCause.FIRE_TICK ||
cause == DamageCause.LAVA ||
cause == DamageCause.SUFFOCATION))
{
event.setCancelled(true);
return;
}
}
}
} }
Claim cachedClaim = null; Claim cachedClaim = null;

View File

@ -825,6 +825,11 @@ class PlayerEventHandler implements Listener
if(!GriefPrevention.instance.claimsEnabledForWorld(entity.getWorld())) return; if(!GriefPrevention.instance.claimsEnabledForWorld(entity.getWorld())) return;
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
//always allow interactions when player is in ignore claims mode
if(playerData.ignoreClaims) return;
//allow horse protection to be overridden to allow management from other plugins //allow horse protection to be overridden to allow management from other plugins
if (!GriefPrevention.instance.config_claims_protectHorses && entity instanceof Horse) return; if (!GriefPrevention.instance.config_claims_protectHorses && entity instanceof Horse) return;
@ -840,11 +845,6 @@ class PlayerEventHandler implements Listener
} }
} }
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
//always allow interactions when player is in ignore claims mode
if(playerData.ignoreClaims) return;
//don't allow container access during pvp combat //don't allow container access during pvp combat
if((entity instanceof StorageMinecart || entity instanceof PoweredMinecart)) if((entity instanceof StorageMinecart || entity instanceof PoweredMinecart))
{ {