Search in sources :

Example 1 with PlayerData

use of me.confuser.banmanager.data.PlayerData in project Parties by AlessioDP.

the class BMHook method onPlayerBan.

@EventHandler(ignoreCancelled = true)
public void onPlayerBan(PlayerBannedEvent event) {
    PlayerData pl = event.getBan().getPlayer();
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(pl.getUUID());
    // Spy listener
    if (pp.isSpy())
        plugin.getSpyManager().removeSpy(pp.getPlayerUUID());
    // Party checking
    if (!pp.getPartyName().isEmpty()) {
        PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
        if (party != null) {
            PartyPlayerEntity kickerPp = plugin.getPlayerManager().getPlayer(event.getBan().getActor().getUUID());
            // Calling API event
            PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(pp, party, true, kickerPp);
            Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
            if (!partiesLeaveEvent.isCancelled()) {
                if (party.getLeader().equals(pl.getUUID())) {
                    // Calling Pre API event
                    PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.BAN, pp, kickerPp);
                    Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
                    if (!partiesPreDeleteEvent.isCancelled()) {
                        party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_DISBANDED);
                        party.removeParty();
                        // Calling Post API event
                        PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.BAN, pp, kickerPp);
                        Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
                        LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_LIB_BANMANAGER_BAN.replace("{party}", party.getName()).replace("{player}", pl.getName()), true, ConsoleColor.CYAN);
                    } else {
                        // Event is cancelled, block ban chain
                        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY_GENERIC.replace("{party}", party.getName()), true);
                        return;
                    }
                } else {
                    party.getMembers().remove(pl.getUUID());
                    party.getOnlinePlayers().remove(pl.getPlayer());
                    party.sendBroadcast(pp, Messages.MAINCMD_KICK_BROADCAST);
                    party.updateParty();
                }
            } else
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{player}", pl.getName()).replace("{party}", party.getName()), true);
        }
        pp.cleanupPlayer(true);
    }
}
Also used : PartiesPartyPostDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPartyPreDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartiesPlayerLeaveEvent(com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent) PlayerData(me.confuser.banmanager.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)1 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)1 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)1 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)1 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)1 PlayerData (me.confuser.banmanager.data.PlayerData)1 EventHandler (org.bukkit.event.EventHandler)1