Search in sources :

Example 1 with PartyColor

use of com.alessiodp.parties.api.interfaces.PartyColor in project Parties by AlessioDP.

the class CommandColor 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
    Set<PartyColorImpl> availableColors = getPlugin().getColorManager().getAvailableColors(sender);
    if (commandData.getArgs().length == 1) {
        if (party.getColor() != null)
            sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_INFO, availableColors));
        else
            sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_EMPTY, availableColors));
        return;
    }
    boolean isRemove = false;
    PartyColor color = null;
    if (commandData.getArgs()[1].equalsIgnoreCase(ConfigMain.COMMANDS_MISC_REMOVE)) {
        // Remove command
        isRemove = true;
    } else {
        // Normal command
        for (PartyColorImpl pc : availableColors) {
            if (pc.getCommand().equalsIgnoreCase(commandData.getArgs()[1])) {
                color = pc;
                break;
            }
        }
        if (color == null) {
            // Color doesn't exist
            sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_WRONGCOLOR, availableColors));
            return;
        }
        if (getPlugin().getEconomyManager().payCommand(EconomyManager.PaidCommand.COLOR, partyPlayer, commandData.getCommandLabel(), commandData.getArgs()))
            return;
    }
    // Command starts
    party.setColor(color);
    if (isRemove) {
        sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_REMOVED, availableColors));
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_COLOR_REM, partyPlayer.getName(), party.getName() != null ? party.getName() : "_"), true);
    } else {
        sendMessage(sender, partyPlayer, parseWithAvailableColors(Messages.ADDCMD_COLOR_CHANGED, availableColors), party);
        party.broadcastMessage(parseWithAvailableColors(Messages.ADDCMD_COLOR_BROADCAST, availableColors), partyPlayer);
        plugin.getLoggerManager().logDebug(String.format(PartiesConstants.DEBUG_CMD_COLOR, partyPlayer.getName(), party.getName() != null ? party.getName() : "_", color.getName()), 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) PartyColor(com.alessiodp.parties.api.interfaces.PartyColor) PartyColorImpl(com.alessiodp.parties.common.parties.objects.PartyColorImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

User (com.alessiodp.core.common.user.User)1 PartyColor (com.alessiodp.parties.api.interfaces.PartyColor)1 PartiesCommandData (com.alessiodp.parties.common.commands.utils.PartiesCommandData)1 PartyColorImpl (com.alessiodp.parties.common.parties.objects.PartyColorImpl)1 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1