Search in sources :

Example 1 with PartiesCombustFriendlyFireBlockedEvent

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);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesCombustFriendlyFireBlockedEvent(com.alessiodp.partiesapi.events.PartiesCombustFriendlyFireBlockedEvent) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 PartiesCombustFriendlyFireBlockedEvent (com.alessiodp.partiesapi.events.PartiesCombustFriendlyFireBlockedEvent)1 Player (org.bukkit.entity.Player)1 Projectile (org.bukkit.entity.Projectile)1 EventHandler (org.bukkit.event.EventHandler)1