Search in sources :

Example 21 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class CommonListener method handlePostPartyCreate.

public void handlePostPartyCreate(UUID partyId, UUID playerId, boolean load) {
    PartyImpl party = load ? plugin.getPartyManager().loadParty(partyId) : plugin.getPartyManager().getParty(partyId);
    if (party != null) {
        if (load)
            plugin.getPlayerManager().reloadPlayer(playerId);
        PartyPlayerImpl leader = plugin.getPlayerManager().getPlayer(partyId);
        IPartyPostCreateEvent partiesPostCreateEvent = plugin.getEventManager().preparePartyPostCreateEvent(leader, party);
        plugin.getEventManager().callEvent(partiesPostCreateEvent);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_MESSAGING_LISTEN_CREATE_PARTY, partyId.toString(), playerId != null ? playerId.toString() : "none"), true);
    }
}
Also used : PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) IPartyPostCreateEvent(com.alessiodp.parties.api.events.common.party.IPartyPostCreateEvent) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 22 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class PartyManager method loadParty.

public PartyImpl loadParty(String name) {
    // Get the party and save it into the party list
    PartyImpl ret = getParty(name);
    addPartyToCache(ret);
    return ret;
}
Also used : PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 23 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class PartyManager method reloadParty.

public boolean reloadParty(UUID id) {
    PartyImpl party = getPartyFromCache(id);
    if (party != null) {
        removePartyFromCache(party);
        party = plugin.getDatabaseManager().getParty(id);
        if (party != null) {
            addPartyToCache(party);
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_RELOADED, party.getName() != null ? party.getName() : party.getId()), true);
        } else
            plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_PARTY_RELOADED_DELETED, id), true);
        return true;
    }
    return false;
}
Also used : PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 24 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl in project Parties by AlessioDP.

the class CommandInvite method preRequisites.

@Override
public boolean preRequisites(@NotNull CommandData commandData) {
    User sender = commandData.getSender();
    PartyPlayerImpl partyPlayer = getPlugin().getPlayerManager().getPlayer(sender.getUUID());
    // Checks for command prerequisites
    if (!sender.hasPermission(permission)) {
        sendNoPermissionMessage(partyPlayer, permission);
        return false;
    }
    if (commandData.getArgs().length != 2) {
        sendMessage(sender, partyPlayer, Messages.PARTIES_SYNTAX_WRONG_MESSAGE.replace("%syntax%", syntax));
        return false;
    }
    PartyImpl party = getPlugin().getPartyManager().getPartyOfPlayer(partyPlayer);
    if (party == null) {
        if (!ConfigParties.GENERAL_INVITE_AUTO_CREATE_PARTY_UPON_INVITE) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_NOTINPARTY);
            return false;
        }
    } else {
        if (!getPlugin().getRankManager().checkPlayerRankAlerter(partyPlayer, RankPermission.INVITE))
            return false;
        if (party.isFull()) {
            sendMessage(sender, partyPlayer, Messages.PARTIES_COMMON_PARTYFULL);
            return false;
        }
        ((PartiesCommandData) commandData).setParty(party);
    }
    ((PartiesCommandData) commandData).setPartyPlayer(partyPlayer);
    commandData.addPermission(PartiesPermission.ADMIN_COOLDOWN_INVITE_BYPASS);
    return true;
}
Also used : User(com.alessiodp.core.common.user.User) 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 25 with PartyImpl

use of com.alessiodp.parties.common.parties.objects.PartyImpl 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)

Aggregations

PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)106 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)75 User (com.alessiodp.core.common.user.User)39 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)31 ADPPlugin (com.alessiodp.core.common.ADPPlugin)11 UUID (java.util.UUID)11 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)10 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)10 PartiesPlugin (com.alessiodp.parties.common.PartiesPlugin)9 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)9 PartyHomeImpl (com.alessiodp.parties.common.parties.objects.PartyHomeImpl)8 LinkedList (java.util.LinkedList)8 LinkedHashSet (java.util.LinkedHashSet)7 List (java.util.List)7 HashMap (java.util.HashMap)6 ADPMainCommand (com.alessiodp.core.common.commands.utils.ADPMainCommand)5 CommandData (com.alessiodp.core.common.commands.utils.CommandData)5 OfflineUser (com.alessiodp.core.common.user.OfflineUser)5 CommonCommands (com.alessiodp.parties.common.commands.list.CommonCommands)5 PartiesSubCommand (com.alessiodp.parties.common.commands.utils.PartiesSubCommand)5