Search in sources :

Example 1 with BukkitPartiesCombustFriendlyFireBlockedEvent

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);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.alessiodp.core.common.user.User) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) BukkitPartyPlayerImpl(com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl) BukkitPartiesCombustFriendlyFireBlockedEvent(com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesCombustFriendlyFireBlockedEvent) BukkitPartyImpl(com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl) BukkitEventManager(com.alessiodp.parties.bukkit.events.BukkitEventManager) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Aggregations

User (com.alessiodp.core.common.user.User)1 BukkitPartiesCombustFriendlyFireBlockedEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesCombustFriendlyFireBlockedEvent)1 BukkitEventManager (com.alessiodp.parties.bukkit.events.BukkitEventManager)1 BukkitPartyImpl (com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl)1 BukkitPartyPlayerImpl (com.alessiodp.parties.bukkit.players.objects.BukkitPartyPlayerImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 Player (org.bukkit.entity.Player)1 Projectile (org.bukkit.entity.Projectile)1 EventHandler (org.bukkit.event.EventHandler)1