use of com.alessiodp.partiesapi.events.PartiesPotionsFriendlyFireBlockedEvent in project Parties by AlessioDP.
the class FightListener method onPotionSplash.
@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getPotion().getShooter() instanceof Player) {
Player attacker = (Player) event.getPotion().getShooter();
PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
if (!ppAttacker.getPartyName().isEmpty() && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(attacker.getWorld().getName()))) {
boolean cancel = false;
for (PotionEffect pe : event.getEntity().getEffects()) {
switch(pe.getType().getName().toLowerCase()) {
case "harm":
case "blindness":
case "confusion":
case "poison":
case "slow":
case "slow_digging":
case "weakness":
case "unluck":
cancel = true;
}
if (cancel)
break;
}
if (cancel) {
// Friendly fire not allowed here
PartyEntity party = plugin.getPartyManager().getParty(ppAttacker.getPartyName());
for (LivingEntity e : event.getAffectedEntities()) {
if (e instanceof Player) {
Player victim = (Player) e;
if (!attacker.equals(victim)) {
PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
if (ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
// Calling API event
PartiesPotionsFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesPotionsFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
if (!partiesFriendlyFireEvent.isCancelled()) {
// Friendly fire confirmed
ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
party.sendFriendlyFireWarn(ppVictim, ppAttacker);
event.setIntensity(e, 0);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "potion splash").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "potion splash").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
}
}
}
}
}
}
}
}
Aggregations