Search in sources :

Example 1 with IPartyPreDeleteEvent

use of com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent in project Parties by AlessioDP.

the class CommandLeave method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    PartyImpl party = ((PartiesCommandData) commandData).getParty();
    // Command handling
    // Calling API event
    IPlayerPreLeaveEvent partiesPreLeaveEvent = getPlugin().getEventManager().preparePlayerPreLeaveEvent(partyPlayer, party, LeaveCause.LEAVE, partyPlayer);
    getPlugin().getEventManager().callEvent(partiesPreLeaveEvent);
    if (!partiesPreLeaveEvent.isCancelled()) {
        if (party.getLeader() != null && party.getLeader().equals(sender.getUUID())) {
            // Is leader
            boolean mustDelete = true;
            // Check if leader can be changed
            if (ConfigParties.GENERAL_MEMBERS_ON_PARTY_LEAVE_CHANGE_LEADER && party.getMembers().size() > 1) {
                PartyPlayerImpl newLeader = party.findNewLeader();
                if (newLeader != null) {
                    // Found a new leader
                    mustDelete = false;
                    party.changeLeader(newLeader);
                    party.removeMember(partyPlayer, LeaveCause.LEAVE, partyPlayer);
                    sendMessage(sender, partyPlayer, Messages.MAINCMD_LEAVE_LEFT, party);
                    party.broadcastMessage(Messages.MAINCMD_LEAVE_LEADER_CHANGED, newLeader);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_LEAVE_LEADER_CHANGE, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", newLeader.getName()), true);
                }
            }
            if (mustDelete) {
                // Calling Pre API event
                IPartyPreDeleteEvent partiesPreDeleteEvent = getPlugin().getEventManager().preparePartyPreDeleteEvent(party, DeleteCause.LEAVE, null, partyPlayer);
                getPlugin().getEventManager().callEvent(partiesPreDeleteEvent);
                if (!partiesPreDeleteEvent.isCancelled()) {
                    // Disbanding party
                    sendMessage(sender, partyPlayer, Messages.MAINCMD_LEAVE_LEFT, party);
                    party.broadcastMessage(Messages.MAINCMD_LEAVE_DISBANDED, partyPlayer);
                    // Remove player for execute event
                    party.removeMember(partyPlayer, LeaveCause.LEAVE, partyPlayer);
                    party.delete(DeleteCause.LEAVE, partyPlayer, partyPlayer);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_LEAVE, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", true), true);
                } else
                    plugin.getLoggerManager().log(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY, party.getId(), sender.getName(), sender.getUUID().toString()), true);
            }
        } else {
            party.removeMember(partyPlayer, LeaveCause.LEAVE, partyPlayer);
            sendMessage(sender, partyPlayer, Messages.MAINCMD_LEAVE_LEFT, party);
            party.broadcastMessage(Messages.MAINCMD_LEAVE_BROADCAST, partyPlayer);
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_LEAVE, partyPlayer.getName(), party.getId(), false), true);
        }
    } else
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_LEAVEEVENT_DENY, sender.getUUID().toString(), party.getId()), true);
}
Also used : User(com.alessiodp.core.common.user.User) IPartyPreDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) IPlayerPreLeaveEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreLeaveEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 2 with IPartyPreDeleteEvent

use of com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent in project Parties by AlessioDP.

the class CommandDelete method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    PartyImpl party = getPlugin().getPartyManager().getParty(commandData.getArgs()[1]);
    if (party == null) {
        sendMessage(sender, partyPlayer, 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_MISC_SILENT)) {
            isSilent = true;
        } else {
            sendMessage(sender, ((PartiesCommandData) commandData).getPartyPlayer(), Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", getSyntaxForUser(sender)));
            return;
        }
    }
    // Command starts
    // Calling Pre API event
    IPartyPreDeleteEvent partiesPreDeleteEvent = getPlugin().getEventManager().preparePartyPreDeleteEvent(party, DeleteCause.DELETE, null, partyPlayer);
    getPlugin().getEventManager().callEvent(partiesPreDeleteEvent);
    if (!partiesPreDeleteEvent.isCancelled()) {
        if (isSilent) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_DELETE_DELETEDSILENTLY, party);
        } else {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_DELETE_DELETED, party);
            party.broadcastMessage(Messages.MAINCMD_DELETE_BROADCAST, partyPlayer);
        }
        party.delete(DeleteCause.DELETE, null, partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_DELETE, sender.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY, party.getId(), sender.getName(), sender.getUUID().toString()), true);
    }
}
Also used : User(com.alessiodp.core.common.user.User) IPartyPreDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 3 with IPartyPreDeleteEvent

use of com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent in project Parties by AlessioDP.

the class PartyManager method removePlayerTimedOut.

public void removePlayerTimedOut(PartyPlayerImpl player, PartyImpl party) {
    boolean mustDelete = false;
    // Calling Pre API event
    IPlayerPreLeaveEvent partiesPreLeaveEvent = plugin.getEventManager().preparePlayerPreLeaveEvent(player, party, LeaveCause.TIMEOUT, null);
    plugin.getEventManager().callEvent(partiesPreLeaveEvent);
    if (!partiesPreLeaveEvent.isCancelled()) {
        if (party.getLeader() != null && party.getLeader().equals(player.getPlayerUUID())) {
            mustDelete = true;
            // Leader
            if (ConfigParties.GENERAL_MEMBERS_ON_PARTY_LEAVE_CHANGE_LEADER || ConfigParties.GENERAL_MEMBERS_ON_LEAVE_SERVER_CHANGE_LEADER) {
                // Change leader due to player leave
                boolean foundNewLeader = findNewPartyLeader(party);
                if (foundNewLeader) {
                    // Do not delete the party anymore
                    mustDelete = false;
                }
            }
        }
        if (party.getOnlineMembers(true).size() == 0) {
            mustDelete = true;
        }
        if (party.isFixed()) {
            mustDelete = false;
        }
        if (mustDelete) {
            // Calling Pre API event
            IPartyPreDeleteEvent partiesPreDeleteEvent = plugin.getEventManager().preparePartyPreDeleteEvent(party, DeleteCause.TIMEOUT, player, null);
            plugin.getEventManager().callEvent(partiesPreDeleteEvent);
            if (!partiesPreDeleteEvent.isCancelled()) {
                // Delete party
                party.delete(DeleteCause.TIMEOUT, player, player);
                // Calling Post API Delete event
                IPartyPostDeleteEvent partiesPostDeleteEvent = plugin.getEventManager().preparePartyPostDeleteEvent(party, DeleteCause.TIMEOUT, player, null);
                plugin.getScheduler().runAsync(() -> plugin.getEventManager().callEvent(partiesPostDeleteEvent));
                // Calling Post API Leave event
                IPlayerPostLeaveEvent partiesPostLeaveEvent = plugin.getEventManager().preparePlayerPostLeaveEvent(player, party, LeaveCause.TIMEOUT, null);
                plugin.getScheduler().runAsync(() -> plugin.getEventManager().callEvent(partiesPostLeaveEvent));
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_TIMEOUT_DELETE, party.getId().toString(), player.getPlayerUUID().toString()), true);
            } else {
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY_GENERIC, party.getId().toString()), true);
            }
        } else {
            // Kick member
            party.removeMember(player, LeaveCause.TIMEOUT, player);
            party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_LEAVE_SERVER, player);
            // Calling Post API Leave event
            IPlayerPostLeaveEvent partiesPostLeaveEvent = plugin.getEventManager().preparePlayerPostLeaveEvent(player, party, LeaveCause.TIMEOUT, null);
            plugin.getScheduler().runAsync(() -> plugin.getEventManager().callEvent(partiesPostLeaveEvent));
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_TIMEOUT_KICK, player.getPlayerUUID().toString(), party.getId().toString()), true);
        }
    } else {
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_LEAVEEVENT_DENY, player.getPlayerUUID().toString(), party.getId().toString()), true);
    }
}
Also used : IPlayerPostLeaveEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostLeaveEvent) IPartyPreDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent) IPartyPostDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPostDeleteEvent) IPlayerPreLeaveEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreLeaveEvent)

Example 4 with IPartyPreDeleteEvent

use of com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent in project Parties by AlessioDP.

the class PartyManager method removePlayerTimedOut.

public void removePlayerTimedOut(PartyPlayerImpl player, PartyImpl party, LeaveCause leaveCause, DeleteCause deleteCause) {
    boolean mustDelete = false;
    // Calling Pre API event
    IPlayerPreLeaveEvent partiesPreLeaveEvent = plugin.getEventManager().preparePlayerPreLeaveEvent(player, party, leaveCause, null);
    plugin.getEventManager().callEvent(partiesPreLeaveEvent);
    if (!partiesPreLeaveEvent.isCancelled()) {
        if (party.getLeader() != null && party.getLeader().equals(player.getPlayerUUID())) {
            mustDelete = true;
            // Leader
            if (ConfigParties.GENERAL_MEMBERS_ON_PARTY_LEAVE_CHANGE_LEADER || ConfigParties.GENERAL_MEMBERS_ON_LEAVE_SERVER_CHANGE_LEADER) {
                // Change leader due to player leave
                boolean foundNewLeader = findNewPartyLeader(party);
                if (foundNewLeader) {
                    // Do not delete the party anymore
                    mustDelete = false;
                }
            }
        }
        if (party.getOnlineMembers(true).size() == 0) {
            mustDelete = true;
        }
        if (party.isFixed()) {
            mustDelete = false;
        }
        if (mustDelete) {
            // Calling Pre API event
            IPartyPreDeleteEvent partiesPreDeleteEvent = plugin.getEventManager().preparePartyPreDeleteEvent(party, deleteCause, player, null);
            plugin.getEventManager().callEvent(partiesPreDeleteEvent);
            if (!partiesPreDeleteEvent.isCancelled()) {
                // Delete party
                party.delete(DeleteCause.TIMEOUT, player, player);
                // Calling Post API Delete event
                IPartyPostDeleteEvent partiesPostDeleteEvent = plugin.getEventManager().preparePartyPostDeleteEvent(party, deleteCause, player, null);
                plugin.getScheduler().runAsync(() -> plugin.getEventManager().callEvent(partiesPostDeleteEvent));
                // Calling Post API Leave event
                IPlayerPostLeaveEvent partiesPostLeaveEvent = plugin.getEventManager().preparePlayerPostLeaveEvent(player, party, leaveCause, null);
                plugin.getScheduler().runAsync(() -> plugin.getEventManager().callEvent(partiesPostLeaveEvent));
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_TIMEOUT_DELETE, party.getId(), player.getPlayerUUID()), true);
            } else {
                plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY_GENERIC, party.getId()), true);
            }
        } else {
            // Kick member
            party.removeMember(player, LeaveCause.TIMEOUT, player);
            party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_LEAVE_SERVER, player);
            // Calling Post API Leave event
            IPlayerPostLeaveEvent partiesPostLeaveEvent = plugin.getEventManager().preparePlayerPostLeaveEvent(player, party, leaveCause, null);
            plugin.getScheduler().runAsync(() -> plugin.getEventManager().callEvent(partiesPostLeaveEvent));
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_TIMEOUT_KICK, player.getPlayerUUID(), party.getId()), true);
        }
    } else {
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_LEAVEEVENT_DENY, player.getPlayerUUID(), party.getId()), true);
    }
}
Also used : IPlayerPostLeaveEvent(com.alessiodp.parties.api.events.common.player.IPlayerPostLeaveEvent) IPartyPreDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent) IPartyPostDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPostDeleteEvent) IPlayerPreLeaveEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreLeaveEvent)

Example 5 with IPartyPreDeleteEvent

use of com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent in project Parties by AlessioDP.

the class CommandKick method onCommand.

@Override
public void onCommand(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = ((PartiesCommandData) commandData).getPartyPlayer();
    // Command handling
    String playerName = commandData.getArgs()[1];
    UUID playerUUID = null;
    Set<UUID> matchingPlayers = LLAPIHandler.getPlayerByName(playerName);
    List<UUID> listPlayers = new LinkedList<>(matchingPlayers);
    listPlayers.removeIf((uuid) -> !getPlugin().getPlayerManager().getPlayer(uuid).isInParty());
    Collections.sort(listPlayers);
    if (listPlayers.size() > 1) {
        // Check if the player have selected someone
        if (commandData.getArgs().length > 2) {
            try {
                int sel = Integer.parseInt(commandData.getArgs()[2]);
                playerUUID = listPlayers.get(sel - 1);
            } catch (Exception ignored) {
            }
        }
        // The player didn't select a player
        if (playerUUID == null) {
            for (String str : Messages.MAINCMD_KICK_CONFLICT_CONTENT) {
                if (str.contains("%list_players%")) {
                    int i = 1;
                    for (UUID uuid : listPlayers) {
                        PartyPlayerImpl pp = getPlugin().getPlayerManager().getPlayer(uuid);
                        sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_CONFLICT_PLAYER.replace("%number%", Integer.toString(i)).replace("%username%", playerName), pp, getPlugin().getPartyManager().getPartyOfPlayer(pp));
                        i++;
                    }
                } else {
                    sendMessage(sender, partyPlayer, str);
                }
            }
            return;
        }
    } else if (listPlayers.size() == 1) {
        // Player found
        playerUUID = listPlayers.get(0);
    } else {
        // Not found
        sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_FOUND.replace("%player%", playerName));
        return;
    }
    OfflineUser kickedPlayer = plugin.getOfflinePlayer(playerUUID);
    Objects.requireNonNull(kickedPlayer);
    PartyPlayerImpl kickedPp = getPlugin().getPlayerManager().getPlayer(playerUUID);
    PartyImpl party = partyPlayer != null ? getPlugin().getPartyManager().getParty(partyPlayer.getPartyId()) : null;
    boolean otherParty = false;
    if (party == null || !party.getMembers().contains(kickedPlayer.getUUID())) {
        // Other party
        otherParty = true;
        if (commandData.havePermission(PartiesPermission.ADMIN_KICK_OTHERS)) {
            party = getPlugin().getPartyManager().getParty(kickedPp.getPartyId());
            if (party == null) {
                sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PLAYER_NOT_IN_PARTY, kickedPp);
                return;
            }
        } else {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_PLAYERNOTINPARTY, kickedPp);
            return;
        }
    } else {
        // Same party
        if (partyPlayer.getRank() < kickedPp.getRank() && !commandData.havePermission(PartiesPermission.ADMIN_KICK_OTHERS)) {
            sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_PLAYERHIGHERRANK, kickedPp);
            return;
        }
    }
    // Command starts
    // Calling API event
    IPlayerPreLeaveEvent partiesPreLeaveEvent = getPlugin().getEventManager().preparePlayerPreLeaveEvent(kickedPp, party, LeaveCause.KICK, partyPlayer);
    getPlugin().getEventManager().callEvent(partiesPreLeaveEvent);
    if (!partiesPreLeaveEvent.isCancelled()) {
        if (party.getLeader() != null && party.getLeader().equals(kickedPlayer.getUUID())) {
            // Leader
            boolean mustDelete = true;
            // Check if leader can be changed
            if (ConfigParties.GENERAL_MEMBERS_ON_PARTY_LEAVE_CHANGE_LEADER && party.getMembers().size() > 1) {
                PartyPlayerImpl newLeader = party.findNewLeader();
                if (newLeader != null) {
                    // Found a new leader
                    mustDelete = false;
                    party.changeLeader(newLeader);
                    party.removeMember(kickedPp, LeaveCause.KICK, partyPlayer);
                    sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
                    party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_LEADER_CHANGED, newLeader);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK_LEADER_CHANGE, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", newLeader.getName()), true);
                }
            }
            if (mustDelete) {
                // Calling Pre API event
                IPartyPreDeleteEvent partiesPreDeleteEvent = getPlugin().getEventManager().preparePartyPreDeleteEvent(party, DeleteCause.KICK, kickedPp, partyPlayer);
                getPlugin().getEventManager().callEvent(partiesPreDeleteEvent);
                if (!partiesPreDeleteEvent.isCancelled()) {
                    // Disbanding party
                    sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
                    party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST_DISBAND, kickedPp);
                    party.delete(DeleteCause.KICK, kickedPp, partyPlayer);
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", otherParty, true), true);
                } else
                    plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_DELETEEVENT_DENY, party.getId(), sender.getName(), sender.getUUID().toString()), true);
            }
        } else {
            // Normal
            if (kickedPlayer.isOnline()) {
                // Online
                kickedPp.sendMessage(Messages.MAINCMD_KICK_PLAYERKICKED, partyPlayer);
            }
            party.removeMember(kickedPp, LeaveCause.KICK, partyPlayer);
            sendMessage(sender, partyPlayer, Messages.MAINCMD_KICK_SENT, kickedPp);
            party.broadcastMessage(Messages.MAINCMD_KICK_BROADCAST, kickedPp);
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_KICK, sender.getName(), kickedPp.getName(), party.getName() != null ? party.getName() : "_", otherParty, false), true);
        }
    } else
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_API_LEAVEEVENT_DENY, sender.getUUID().toString(), party.getId()), true);
}
Also used : User(com.alessiodp.core.common.user.User) OfflineUser(com.alessiodp.core.common.user.OfflineUser) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartiesCommandData(com.alessiodp.parties.common.commands.utils.PartiesCommandData) IPlayerPreLeaveEvent(com.alessiodp.parties.api.events.common.player.IPlayerPreLeaveEvent) LinkedList(java.util.LinkedList) IPartyPreDeleteEvent(com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent) OfflineUser(com.alessiodp.core.common.user.OfflineUser) UUID(java.util.UUID) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

IPartyPreDeleteEvent (com.alessiodp.parties.api.events.common.party.IPartyPreDeleteEvent)5 IPlayerPreLeaveEvent (com.alessiodp.parties.api.events.common.player.IPlayerPreLeaveEvent)4 User (com.alessiodp.core.common.user.User)3 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)3 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)3 IPartyPostDeleteEvent (com.alessiodp.parties.api.events.common.party.IPartyPostDeleteEvent)2 IPlayerPostLeaveEvent (com.alessiodp.parties.api.events.common.player.IPlayerPostLeaveEvent)2 OfflineUser (com.alessiodp.core.common.user.OfflineUser)1 LinkedList (java.util.LinkedList)1 UUID (java.util.UUID)1