use of com.alessiodp.partiesapi.events.PartiesCombustFriendlyFireBlockedEvent in project Parties by AlessioDP.
the class FightListener method onEntityCombustByEntity.
@EventHandler
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player && event.getCombuster() instanceof Projectile && ((Projectile) event.getCombuster()).getShooter() instanceof Player) {
Player victim = (Player) event.getEntity();
Player attacker = (Player) ((Projectile) event.getCombuster()).getShooter();
// Found right attacker
if (!victim.getUniqueId().equals(attacker.getUniqueId()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
// Friendly fire not allowed here
PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
if (!ppVictim.getPartyName().isEmpty() && ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
// Calling API event
PartiesCombustFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesCombustFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
if (!partiesFriendlyFireEvent.isCancelled()) {
// Friendly fire confirmed
PartyEntity party = plugin.getPartyManager().getParty(ppVictim.getPartyName());
ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
party.sendFriendlyFireWarn(ppVictim, ppAttacker);
event.setCancelled(true);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", "entity combust").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", "entity combust").replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
}
}
}
}
Aggregations