}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
Entity ent = event.getEntity();
if(ent.hasMetadata("NPC")) {
return;
}
boolean tamedWolf = ent instanceof Wolf ? ((Wolf)ent).isTamed() : false;
ClaimedResidence area = Residence.getResidenceManager().getByLoc(ent.getLocation());
/* Living Entities */
if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent attackevent = (EntityDamageByEntityEvent) event;
Entity damager = attackevent.getDamager();
ClaimedResidence srcarea = null;
if (damager != null) {
srcarea = Residence.getResidenceManager().getByLoc(damager.getLocation());
}
boolean srcpvp = true;
if (srcarea != null) {
srcpvp = srcarea.getPermissions().has("pvp", true);
}
ent = attackevent.getEntity();
if ((ent instanceof Player || tamedWolf) && (damager instanceof Player || (damager instanceof Arrow && (((Arrow)damager).getShooter() instanceof Player)))) {
Player attacker = null;
if (damager instanceof Player) {
attacker = (Player) damager;
} else if (damager instanceof Arrow) {
attacker = (Player)((Arrow)damager).getShooter();
}
if(!srcpvp) {
attacker.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("NoPVPZone"));
event.setCancelled(true);
return;
}
/* Check for Player vs Player */
if (area == null) {
/* World PvP */
if (!Residence.getWorldFlags().getPerms(damager.getWorld().getName()).has("pvp", true)) {
attacker.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("WorldPVPDisabled"));
event.setCancelled(true);
}
} else {
/* Normal PvP */
if (!area.getPermissions().has("pvp", true)) {
attacker.sendMessage(ChatColor.RED+Residence.getLanguage().getPhrase("NoPVPZone"));
event.setCancelled(true);
}
}
return;
} else if ((ent instanceof Player || tamedWolf) && (damager instanceof Creeper)) {
if (area == null) {
if (!Residence.getWorldFlags().getPerms(damager.getWorld().getName()).has("creeper", true)) {
event.setCancelled(true);
}
} else {
if (!area.getPermissions().has("creeper", true)) {
event.setCancelled(true);