use of com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesCombustFriendlyFireBlockedEvent in project Parties by AlessioDP.
the class BukkitFightListener method onEntityCombustByEntity.
@EventHandler(ignoreCancelled = true)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
if (BukkitConfigParties.ADDITIONAL_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 (attacker != null && !victim.getUniqueId().equals(attacker.getUniqueId())) {
// Friendly fire not allowed here
PartyPlayerImpl ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
PartyPlayerImpl ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
BukkitPartyImpl party = (BukkitPartyImpl) plugin.getPartyManager().getParty(ppAttacker.getPartyId());
if (party != null && party.getId().equals(ppVictim.getPartyId()) && party.isFriendlyFireProtected() && !attacker.hasPermission(PartiesPermission.ADMIN_PROTECTION_BYPASS.toString())) {
// Calling API event
BukkitPartiesCombustFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).prepareCombustFriendlyFireBlockedEvent(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.setCancelled(true);
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_FRIENDLYFIRE_DENIED, "entity combust", attacker.getUniqueId(), victim.getUniqueId()), true);
}
} else
plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY, "entity combust", attacker.getUniqueId(), victim.getUniqueId()), true);
}
}
}
}
Aggregations