Search in sources :

Example 1 with PartiesPartyPostDeleteEvent

use of com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent in project Parties by AlessioDP.

the class CommandLeave method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    PartyEntity party = commandData.getParty();
    /*
		 * Command starts
		 */
    // Calling API event
    PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(pp, party, false, null);
    Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
    if (!partiesLeaveEvent.isCancelled()) {
        if (party.getLeader().equals(pp.getPlayerUUID())) {
            // Is leader
            // Calling Pre API event
            PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.LEAVE, null, pp);
            Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
            if (!partiesPreDeleteEvent.isCancelled()) {
                // Disbanding party
                pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
                party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_DISBANDED);
                party.removeParty();
                party.callChange();
                // Calling Post API event
                PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.LEAVE, null, pp);
                Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
                LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE_DISBAND.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
            } else
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
        } else {
            party.getMembers().remove(pp.getPlayerUUID());
            party.getOnlinePlayers().remove(commandData.getPlayer());
            pp.cleanupPlayer(true);
            pp.sendMessage(Messages.MAINCMD_LEAVE_LEFT, party);
            party.sendBroadcast(pp, Messages.MAINCMD_LEAVE_BROADCAST);
            party.updateParty();
            party.callChange();
            LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_LEAVE.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
        }
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), 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)

Example 2 with PartiesPartyPostDeleteEvent

use of com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent 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)

Example 3 with PartiesPartyPostDeleteEvent

use of com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent in project Parties by AlessioDP.

the class CommandKick method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    String playerName = commandData.getArgs()[1];
    UUID playerUUID = null;
    // Players conflict handler
    List<PartyPlayer> listPlayers = plugin.getDatabaseManager().getPartyPlayersByName(playerName).join();
    UUID[] playerSelection = new UUID[listPlayers.size()];
    if (listPlayers.size() < 1) {
        // Other player not in party
        pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY_OTHER.replace("%player%", playerName));
        return;
    } else if (listPlayers.size() == 1) {
        // Get the player
        playerUUID = listPlayers.get(0).getPlayerUUID();
    } else {
        // Found multiple players name
        StringBuilder sb = new StringBuilder();
        for (String str : Messages.MAINCMD_KICK_CONFLICT_CONTENT) {
            if (str.contains("%list_players%")) {
                int i = 1;
                for (PartyPlayer pl : listPlayers) {
                    String mojangName = getNameFromMojangAPI(playerName, pl.getPlayerUUID());
                    if (mojangName == null)
                        mojangName = pl.getName();
                    Date date = new Date(pl.getNameTimestamp() * 1000);
                    Time time = new Time(date.getTime());
                    sb.append(Messages.MAINCMD_KICK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", mojangName).replace("%party%", pl.getPartyName()).replace("%date%", date.toString()).replace("%time%", time.toString()) + "\n");
                    playerSelection[i - 1] = pl.getPlayerUUID();
                    i++;
                }
            } else
                sb.append(str + "\n");
        }
        // Selection handling
        if (commandData.getArgs().length == 2) {
            // Print content
            pp.sendMessage(sb.toString());
            return;
        }
        int sel = -1;
        try {
            sel = Integer.parseInt(commandData.getArgs()[2]);
            playerUUID = playerSelection[sel - 1];
        } catch (Exception ex) {
            // Problem with selection, print content
            pp.sendMessage(sb.toString());
            return;
        }
    }
    OfflinePlayer kickedPlayer = Bukkit.getOfflinePlayer(playerUUID);
    PartyPlayerEntity kickedPp = plugin.getPlayerManager().getPlayer(playerUUID);
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    boolean otherParty = false;
    if (party == null || !party.getMembers().contains(kickedPlayer.getUniqueId()) && commandData.havePermission(PartiesPermission.KICK_OTHERS)) {
        // Other party
        otherParty = true;
        party = plugin.getPartyManager().getParty(kickedPp.getPartyName());
        if (party == null) {
            pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY_OTHER, kickedPp);
            return;
        }
    } else {
        // Same party
        if (party == null || !party.getMembers().contains(playerUUID)) {
            pp.sendMessage(Messages.MAINCMD_KICK_PLAYERNOTINPARTY, kickedPp);
            return;
        }
        if (pp.getRank() < kickedPp.getRank() && !commandData.havePermission(PartiesPermission.KICK_OTHERS)) {
            pp.sendMessage(Messages.MAINCMD_KICK_PLAYERHIGHERRANK, kickedPp);
            return;
        }
    }
    /*
		 * Command starts
		 */
    // Calling API event
    PartiesPlayerLeaveEvent partiesLeaveEvent = new PartiesPlayerLeaveEvent(kickedPp, party, otherParty, pp);
    Bukkit.getServer().getPluginManager().callEvent(partiesLeaveEvent);
    if (!partiesLeaveEvent.isCancelled()) {
        if (party.getLeader().equals(kickedPlayer.getUniqueId())) {
            // Leader
            // Calling Pre API event
            PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.LEAVE, kickedPp, pp);
            Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
            if (!partiesPreDeleteEvent.isCancelled()) {
                // Disbanding party
                pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
                party.sendBroadcast(pp, Messages.MAINCMD_KICK_BROADCAST_DISBAND);
                party.removeParty();
                party.callChange();
                // Calling Post API event
                PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.LEAVE, kickedPp, pp);
                Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
                LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_KICK_DISBAND.replace("{player}", kickedPp.getName()).replace("{party}", party.getName()).replace("{sender}", pp.getName()).replace("{other}", Boolean.toString(otherParty)), true);
            } else
                LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
        } else {
            // Normal
            party.getMembers().remove(kickedPlayer.getUniqueId());
            Player kickedPl = kickedPp.getPlayer();
            if (kickedPl != null) {
                // Online
                party.getOnlinePlayers().remove(kickedPl);
                pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
                kickedPp.sendMessage(Messages.MAINCMD_KICK_PLAYERKICKED, pp);
                party.sendBroadcast(kickedPp, Messages.MAINCMD_KICK_BROADCAST);
                kickedPp.cleanupPlayer(true);
                party.callChange();
            } else {
                pp.sendMessage(Messages.MAINCMD_KICK_SENT, kickedPp);
                party.sendBroadcast(kickedPp, Messages.MAINCMD_KICK_BROADCAST);
                kickedPp.cleanupPlayer(true);
            }
            party.updateParty();
            LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_KICK.replace("{player}", kickedPp.getName()).replace("{party}", party.getName()).replace("{sender}", pp.getName()).replace("{other}", Boolean.toString(otherParty)), true);
        }
    } else
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_LEAVEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), true);
}
Also used : PartiesPartyPostDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) Time(java.sql.Time) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) PartiesPlayerLeaveEvent(com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent) Date(java.sql.Date) PartiesPartyPreDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent) OfflinePlayer(org.bukkit.OfflinePlayer) UUID(java.util.UUID)

Example 4 with PartiesPartyPostDeleteEvent

use of com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent in project Parties by AlessioDP.

the class CommandDelete method onCommand.

@Override
public void onCommand(CommandData commandData) {
    PartyPlayerEntity pp = commandData.getPartyPlayer();
    /*
		 * Command handling
		 */
    PartyEntity party = plugin.getPartyManager().getParty(commandData.getArgs()[1]);
    if (party == null) {
        pp.sendMessage(Messages.PARTIES_COMMON_PARTYNOTFOUND.replace("%party%", commandData.getArgs()[1]));
        return;
    }
    boolean isSilent = false;
    if (commandData.getArgs().length == 3) {
        if (commandData.havePermission(PartiesPermission.ADMIN_DELETE_SILENT) && commandData.getArgs()[2].equalsIgnoreCase(ConfigMain.COMMANDS_SUB_SILENT)) {
            isSilent = true;
        } else {
            pp.sendMessage(Messages.MAINCMD_DELETE_WRONGCMD);
            return;
        }
    }
    /*
		 * Command starts
		 */
    // Calling Pre API event
    PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.DELETE, null, pp);
    Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
    if (!partiesPreDeleteEvent.isCancelled()) {
        if (isSilent) {
            pp.sendMessage(Messages.MAINCMD_DELETE_DELETEDSILENTLY, party);
        } else {
            pp.sendMessage(Messages.MAINCMD_DELETE_DELETED, party);
            party.sendBroadcast(pp, Messages.MAINCMD_DELETE_BROADCAST);
        }
        party.removeParty();
        // Calling Post API event
        PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.DELETE, null, pp);
        Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
        LoggerManager.log(LogLevel.BASIC, Constants.DEBUG_CMD_DELETE.replace("{player}", pp.getName()).replace("{party}", party.getName()), true);
    } else {
        LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY.replace("{party}", party.getName()).replace("{player}", pp.getName()), 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)

Example 5 with PartiesPartyPostDeleteEvent

use of com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent in project Parties by AlessioDP.

the class PartyManager method deleteTimedParty.

public void deleteTimedParty(String name, boolean leaderLeft) {
    PartyEntity party = getParty(name);
    if (party != null) {
        // Calling Pre API event
        PartiesPartyPreDeleteEvent partiesPreDeleteEvent = new PartiesPartyPreDeleteEvent(party, PartiesPartyPreDeleteEvent.DeleteCause.TIMEOUT, null, null);
        Bukkit.getServer().getPluginManager().callEvent(partiesPreDeleteEvent);
        if (!partiesPreDeleteEvent.isCancelled()) {
            for (UUID u : plugin.getPlayerManager().getListPartyPlayersToDelete()) {
                if (party.getMembers().contains(u))
                    plugin.getPlayerManager().getListPartyPlayers().remove(u);
            }
            String cause = "empty";
            if (leaderLeft) {
                party.sendBroadcast(plugin.getPlayerManager().getPlayer(party.getLeader()), Messages.MAINCMD_LEAVE_DISBANDED);
                cause = "leader left";
            }
            party.removeParty();
            // Calling Post API event
            // Used to avoid ambiguity with PartiesPartyPostDeleteEvent constructors
            PartyPlayer tempPlayer = new PartyPlayer(UUID.fromString(Constants.FIXED_VALUE_UUID), 0);
            PartiesPartyPostDeleteEvent partiesPostDeleteEvent = new PartiesPartyPostDeleteEvent(party.getName(), PartiesPartyPostDeleteEvent.DeleteCause.TIMEOUT, null, tempPlayer);
            Bukkit.getServer().getPluginManager().callEvent(partiesPostDeleteEvent);
            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_PARTY_DELETE_CAUSE.replace("{party}", party.getName()).replace("{cause}", cause), true);
            if (getListPartiesToDelete().containsKey(name.toLowerCase()))
                getListPartiesToDelete().remove(name.toLowerCase());
        } else {
            LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_DELETEEVENT_DENY_GENERIC.replace("{party}", party.getName()), true);
        }
    }
}
Also used : PartiesPartyPostDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent) PartiesPartyPreDeleteEvent(com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent) PartyPlayer(com.alessiodp.partiesapi.objects.PartyPlayer) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) UUID(java.util.UUID)

Aggregations

PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)5 PartiesPartyPostDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPostDeleteEvent)5 PartiesPartyPreDeleteEvent (com.alessiodp.partiesapi.events.PartiesPartyPreDeleteEvent)5 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)4 PartiesPlayerLeaveEvent (com.alessiodp.partiesapi.events.PartiesPlayerLeaveEvent)3 PartyPlayer (com.alessiodp.partiesapi.objects.PartyPlayer)2 UUID (java.util.UUID)2 Date (java.sql.Date)1 Time (java.sql.Time)1 PlayerData (me.confuser.banmanager.data.PlayerData)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1