Protect wolves under certain conditions (#507)

- Protects wolves unless the attacker is being targeted by the wolf.
This commit is contained in:
Shane Bee 2019-04-09 21:20:36 -07:00 committed by RoboMWM
parent 832ec7ed86
commit 522d225548

View File

@ -48,6 +48,7 @@ import org.bukkit.entity.WaterMob;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.Mule;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -988,6 +989,25 @@ public class EntityEventHandler implements Listener
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
return;
}
// disallow players attacking tamed wolves (dogs) unless under attack by said wolf
else if (tameable.getType() == EntityType.WOLF)
{
if (!tameable.getOwner().equals(attacker))
{
if (((Wolf) tameable).getTarget() != null)
{
if (((Wolf) tameable).getTarget() == attacker) return;
}
event.setCancelled(true);
String ownerName = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID).getName();
String message = GriefPrevention.instance.dataStore.getMessage(Messages.NoDamageClaimedEntity, ownerName);
if (attacker.hasPermission("griefprevention.ignoreclaims"))
message += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, message);
return;
}
}
}
}
}