Search in sources :

Example 1 with BukkitPartiesFishHookFriendlyFireBlockedEvent

use of com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFishHookFriendlyFireBlockedEvent in project Parties by AlessioDP.

the class BukkitFightListener method onPlayerFish.

@EventHandler(ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) {
    if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY && event.getCaught() != null && event.getCaught() instanceof Player && BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_ENABLE && BukkitConfigParties.ADDITIONAL_FRIENDLYFIRE_PREVENT_FISH_HOOK) {
        // Friendly fire not allowed here
        PartyPlayerImpl ppVictim = plugin.getPlayerManager().getPlayer(event.getCaught().getUniqueId());
        PartyPlayerImpl ppAttacker = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
        BukkitPartyImpl party = (BukkitPartyImpl) plugin.getPartyManager().getParty(ppAttacker.getPartyId());
        if (party != null && party.getId().equals(ppVictim.getPartyId()) && party.isFriendlyFireProtected() && !event.getPlayer().hasPermission(PartiesPermission.ADMIN_PROTECTION_BYPASS.toString())) {
            // Calling API event
            BukkitPartiesFishHookFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).preparePartiesFishHookFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
            plugin.getEventManager().callEvent(partiesFriendlyFireEvent);
            if (!partiesFriendlyFireEvent.isCancelled()) {
                // Friendly fire confirmed
                User userAttacker = plugin.getPlayer(event.getPlayer().getUniqueId());
                if (userAttacker != null) {
                    userAttacker.sendMessage(plugin.getMessageUtils().convertPlaceholders(BukkitMessages.ADDCMD_PROTECTION_PROTECTED, ppAttacker, party), true);
                    party.warnFriendlyFire(ppVictim, ppAttacker);
                    try {
                        event.getHook().remove();
                        event.setCancelled(true);
                        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_FRIENDLYFIRE_DENIED, "fish hook", ppAttacker.getPlayerUUID(), ppVictim.getPlayerUUID()), true);
                    } catch (NoSuchMethodError ignored) {
                        // Hook remove not supported in this version
                        plugin.getLoggerManager().logError(PartiesConstants.DEBUG_FRIENDLYFIRE_FISH_NOT_SUPPORTED);
                    }
                }
            } else
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY, "fish hook", ppAttacker.getPlayerUUID(), ppVictim.getPlayerUUID()), 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) BukkitPartiesFishHookFriendlyFireBlockedEvent(com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFishHookFriendlyFireBlockedEvent) BukkitPartyImpl(com.alessiodp.parties.bukkit.parties.objects.BukkitPartyImpl) BukkitEventManager(com.alessiodp.parties.bukkit.events.BukkitEventManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

User (com.alessiodp.core.common.user.User)1 BukkitPartiesFishHookFriendlyFireBlockedEvent (com.alessiodp.parties.api.events.bukkit.unique.BukkitPartiesFishHookFriendlyFireBlockedEvent)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 EventHandler (org.bukkit.event.EventHandler)1