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;
@ -538,7 +539,7 @@ class EntityEventHandler implements Listener
//don't track in worlds where claims are not enabled //don't track in worlds where claims are not enabled
if(!GriefPrevention.instance.claimsEnabledForWorld(event.getEntity().getWorld())) return; if(!GriefPrevention.instance.claimsEnabledForWorld(event.getEntity().getWorld())) return;
//if the damaged entity is a claimed item frame or armor stand, the damager needs to be a player with container trust in the claim //if the damaged entity is a claimed item frame or armor stand, the damager needs to be a player with container trust in the claim
if(subEvent.getEntityType() == EntityType.ITEM_FRAME || subEvent.getEntityType() == EntityType.ARMOR_STAND) if(subEvent.getEntityType() == EntityType.ITEM_FRAME || subEvent.getEntityType() == EntityType.ARMOR_STAND)
{ {
//decide whether it's claimed //decide whether it's claimed
@ -582,24 +583,49 @@ 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)
{ {
UUID ownerID = tameable.getOwner().getUniqueId(); //limit attacks by players to owners and admins in ignore claims mode
if(attacker != null)
{
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;
//otherwise disallow in non-pvp worlds //allow for admin override
if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(subEvent.getEntity().getLocation().getWorld())) PlayerData attackerData = this.dataStore.getPlayerData(attacker.getUniqueId());
{ if(attackerData.ignoreClaims) return;
OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID);
String ownerName = owner.getName(); //otherwise disallow in non-pvp worlds
if(ownerName == null) ownerName = "someone"; if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(subEvent.getEntity().getLocation().getWorld()))
String message = GriefPrevention.instance.dataStore.getMessage(Messages.NoDamageClaimedEntity, ownerName); {
if(attacker.hasPermission("griefprevention.ignoreclaims")) OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID);
message += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement); String ownerName = owner.getName();
GriefPrevention.sendMessage(attacker, TextMode.Err, message); if(ownerName == null) ownerName = "someone";
event.setCancelled(true); String message = GriefPrevention.instance.dataStore.getMessage(Messages.NoDamageClaimedEntity, ownerName);
return; if(attacker.hasPermission("griefprevention.ignoreclaims"))
} message += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
GriefPrevention.sendMessage(attacker, TextMode.Err, message);
event.setCancelled(true);
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;
}
}
} }
} }

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))
{ {