use of com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesPotionsFriendlyFireBlockedEvent in project Parties by AlessioDP.
the class BukkitFightListener method onPotionSplash.
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
if (BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_ENABLE && event.getPotion().getShooter() instanceof Player) {
Player attacker = (Player) event.getPotion().getShooter();
PartyPlayerImpl ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
BukkitPartyImpl party = (BukkitPartyImpl) plugin.getPartyManager().getParty(ppAttacker.getPartyId());
if (party != null && party.isFriendlyFireProtected() && !attacker.hasPermission(PartiesPermission.ADMIN_PROTECTION_BYPASS.toString())) {
boolean cancel = false;
for (PotionEffect pe : event.getEntity().getEffects()) {
switch(CommonUtils.toLowerCase(pe.getType().getName())) {
case "harm":
case "blindness":
case "confusion":
case "poison":
case "slow":
case "slow_digging":
case "weakness":
case "unluck":
cancel = true;
break;
default:
// Do not cancel
break;
}
if (cancel)
break;
}
if (cancel) {
// Friendly fire not allowed here
for (LivingEntity e : event.getAffectedEntities()) {
if (e instanceof Player) {
Player victim = (Player) e;
if (!attacker.equals(victim)) {
PartyPlayerImpl ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
if (ppAttacker.getPartyId() != null && ppAttacker.getPartyId().equals(ppVictim.getPartyId())) {
// Calling API event
BukkitPartiesPotionsFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).preparePartiesPotionsFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
plugin.getEventManager().callEvent(partiesFriendlyFireEvent);
if (!partiesFriendlyFireEvent.isCancelled()) {
// Friendly fire confirmed
User userAttacker = plugin.getPlayer(attacker.getUniqueId());
if (userAttacker != null) {
userAttacker.sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.ADDCMD_PROTECTION_PROTECTED, ppAttacker, party), true);
party.warnFriendlyFire(ppVictim, ppAttacker);
event.setIntensity(e, 0);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_FRIENDLYFIRE_DENIED, "potion splash", attacker.getUniqueId(), victim.getUniqueId()), true);
}
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY, "potion splash", attacker.getUniqueId(), victim.getUniqueId()), true);
}
}
}
}
}
}
}
}
Aggregations