Search in sources :

Example 1 with PartyColorImpl

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

the class PartiesPlaceholderTest method testPlaceholderColorName.

@Test
public void testPlaceholderColorName() {
    PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder("color_name");
    assertEquals(PartiesPlaceholder.COLOR_NAME, placeholder);
    assertEquals("", placeholder.formatPlaceholder(player1, party1, "color_name"));
    party1.setAccessible(true);
    party1.setColor(new PartyColorImpl("red", "123", "&c", 0, 0, 0));
    party1.setAccessible(false);
    assertEquals(party1.getColor().getName(), placeholder.formatPlaceholder(player1, party1, "color_name"));
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) PartyColorImpl(com.alessiodp.parties.common.parties.objects.PartyColorImpl) Test(org.junit.jupiter.api.Test)

Example 2 with PartyColorImpl

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

Example 3 with PartyColorImpl

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

the class ConfigParties method saveColors.

private void saveColors() {
    if (ConfigParties.RAW_ADDITIONAL_COLOR_LIST != null) {
        // Cleanup unused colors
        for (String color : ConfigParties.RAW_ADDITIONAL_COLOR_LIST.getKeys(false)) {
            boolean found = false;
            for (PartyColorImpl partyColor : ((PartiesPlugin) plugin).getColorManager().getColorList()) {
                if (partyColor.getName().equals(color)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                ConfigParties.RAW_ADDITIONAL_COLOR_LIST.remove(color);
            }
        }
        // Update colors
        for (PartyColorImpl partyColor : ((PartiesPlugin) plugin).getColorManager().getColorList()) {
            ConfigParties.RAW_ADDITIONAL_COLOR_LIST.set(partyColor.getName() + ".command", partyColor.getCommand());
            ConfigParties.RAW_ADDITIONAL_COLOR_LIST.set(partyColor.getName() + ".code", partyColor.getCode());
            if (partyColor.getDynamicPriority() > 0 && partyColor.getDynamicKills() > 0 && partyColor.getDynamicMembers() > 0) {
                ConfigParties.RAW_ADDITIONAL_COLOR_LIST.set(partyColor.getName() + ".dynamic.priority", partyColor.getDynamicPriority());
                ConfigParties.RAW_ADDITIONAL_COLOR_LIST.set(partyColor.getName() + ".dynamic.kills", partyColor.getDynamicKills());
                ConfigParties.RAW_ADDITIONAL_COLOR_LIST.set(partyColor.getName() + ".dynamic.members", partyColor.getDynamicMembers());
            }
        }
    }
}
Also used : PartyColorImpl(com.alessiodp.parties.common.parties.objects.PartyColorImpl)

Example 4 with PartyColorImpl

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

the class ConfigParties method loadDefaults.

@Override
public void loadDefaults() {
    loadDefaultConfigOptions();
    RANK_LIST = new HashSet<>();
    PartyRankImpl rankMember = new PartyRankImpl("member", "Member", "&bMember", 5, 0, null, Arrays.asList("party.sendmessage", "party.home", "party.desc", "party.motd", "party.claim"), true);
    PartyRankImpl rankModerator = new PartyRankImpl("moderator", "Moderator", "&cModerator", 10, 0, rankMember, Arrays.asList("party.ask.accept", "party.ask.deny", "party.invite", "party.kick"), false);
    PartyRankImpl rankLeader = new PartyRankImpl("member", "Member", "&bMember", 5, 0, null, Collections.singletonList("*"), true);
    RANK_LIST.add(rankMember);
    RANK_LIST.add(rankModerator);
    RANK_LIST.add(rankLeader);
    RANK_SET_DEFAULT = 5;
    RANK_SET_HIGHER = 20;
    ADDITIONAL_COLOR_LIST = new HashSet<>(Arrays.asList(new PartyColorImpl("red", "red", "&c", -1, -1, -1), new PartyColorImpl("green", "green", "&a", -1, -1, -1), new PartyColorImpl("yourcustomcolor", "special", "&9&n", -1, -1, -1)));
}
Also used : PartyRankImpl(com.alessiodp.parties.common.players.objects.PartyRankImpl) PartyColorImpl(com.alessiodp.parties.common.parties.objects.PartyColorImpl)

Example 5 with PartyColorImpl

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

the class ConfigParties method handleColors.

private void handleColors() {
    Set<PartyColorImpl> colors = new HashSet<>();
    if (ConfigParties.RAW_ADDITIONAL_COLOR_LIST != null) {
        for (String key : ConfigParties.RAW_ADDITIONAL_COLOR_LIST.getKeys(false)) {
            PartyColorImpl color = new PartyColorImpl(key);
            color.setCommand(ConfigParties.RAW_ADDITIONAL_COLOR_LIST.getString(key + ".command", ""));
            color.setCode(ConfigParties.RAW_ADDITIONAL_COLOR_LIST.getString(key + ".code", ""));
            color.setDynamicPriority(ConfigParties.RAW_ADDITIONAL_COLOR_LIST.getInt(key + ".dynamic.priority", -1));
            color.setDynamicMembers(ConfigParties.RAW_ADDITIONAL_COLOR_LIST.getInt(key + ".dynamic.members", -1));
            color.setDynamicKills(ConfigParties.RAW_ADDITIONAL_COLOR_LIST.getInt(key + ".dynamic.kills", -1));
            colors.add(color);
        }
        ConfigParties.ADDITIONAL_COLOR_LIST = colors;
    } else {
        plugin.getLoggerManager().logError(PartiesConstants.DEBUG_CONFIG_FAILED_COLOR_NOTFOUND);
    }
    ConfigParties.ADDITIONAL_COLOR_LIST.stream().findFirst().get().setDynamicMembers(15);
}
Also used : PartyColorImpl(com.alessiodp.parties.common.parties.objects.PartyColorImpl) HashSet(java.util.HashSet)

Aggregations

PartyColorImpl (com.alessiodp.parties.common.parties.objects.PartyColorImpl)7 PartiesPlaceholder (com.alessiodp.parties.common.addons.internal.PartiesPlaceholder)3 Test (org.junit.jupiter.api.Test)3 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 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)1 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)1 PartyRankImpl (com.alessiodp.parties.common.players.objects.PartyRankImpl)1 HashSet (java.util.HashSet)1