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);
}
}
}
Aggregations