Search in sources :

Example 11 with PartiesPlaceholder

use of com.alessiodp.parties.common.addons.internal.PartiesPlaceholder in project Parties by AlessioDP.

the class EssentialsChatHandler method onChatPlayer.

@EventHandler
public void onChatPlayer(AsyncPlayerChatEvent event) {
    String old = event.getFormat();
    if (CommonUtils.toLowerCase(old).contains("{parties_")) {
        // Bypass useless checks if this isn't an Parties placeholder
        boolean somethingChanged = false;
        PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
        PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
        Matcher mat = PATTERN.matcher(old);
        while (mat.find()) {
            String base = mat.group(0);
            String identifier = mat.group(1);
            if (identifier != null) {
                identifier = CommonUtils.toLowerCase(identifier);
                PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder(identifier);
                if (placeholder != null) {
                    String parsed = placeholder.formatPlaceholder(partyPlayer, party, identifier);
                    if (parsed != null) {
                        old = old.replace(base, Color.translateAlternateColorCodes(parsed));
                        somethingChanged = true;
                    }
                }
            }
        }
        if (somethingChanged)
            event.setFormat(old);
    }
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) Matcher(java.util.regex.Matcher) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) EventHandler(org.bukkit.event.EventHandler)

Example 12 with PartiesPlaceholder

use of com.alessiodp.parties.common.addons.internal.PartiesPlaceholder in project Parties by AlessioDP.

the class PAPIHook method onRequest.

@Override
public String onRequest(OfflinePlayer offlinePlayer, @NotNull String identifier) {
    if (offlinePlayer != null) {
        PartyPlayerImpl partyPlayer = plugin.getPlayerManager().getPlayer(offlinePlayer.getUniqueId());
        PartyImpl party = plugin.getPartyManager().getParty(partyPlayer.getPartyId());
        PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder(identifier);
        return placeholder != null ? placeholder.formatPlaceholder(partyPlayer, party, identifier) : null;
    }
    return null;
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 13 with PartiesPlaceholder

use of com.alessiodp.parties.common.addons.internal.PartiesPlaceholder in project Parties by AlessioDP.

the class PartiesPlaceholderTest method testPlaceholderListPartiesByOnlineMembers.

@Test
public void testPlaceholderListPartiesByOnlineMembers() {
    doAnswer(args -> {
        if (((int) args.getArgument(2)) == 0)
            return Sets.newSet(party3);
        else if (((int) args.getArgument(2)) == 1)
            return Sets.newSet(party2);
        else if (((int) args.getArgument(2)) == 2)
            return Sets.newSet(party1);
        return Sets.newSet();
    }).when(mockDatabaseManager).getListParties(eq(PartiesDatabaseManager.ListOrder.ONLINE_MEMBERS), anyInt(), anyInt());
    PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_online_members_1");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_ONLINE_MEMBERS_NUMBER, placeholder);
    assertEquals(party3.getName(), placeholder.formatPlaceholder(null, null, "list_parties_by_online_members_1"));
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_online_members_2");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_ONLINE_MEMBERS_NUMBER, placeholder);
    assertEquals(party2.getName(), placeholder.formatPlaceholder(null, null, "list_parties_by_online_members_2"));
    // No more parties
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_online_members_4");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_ONLINE_MEMBERS_NUMBER, placeholder);
    assertEquals("", placeholder.formatPlaceholder(null, null, "list_parties_by_online_members_4"));
    // Placeholder
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_online_members_1_id");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_ONLINE_MEMBERS_NUMBER_PLACEHOLDER, placeholder);
    assertEquals(party3.getId().toString(), placeholder.formatPlaceholder(null, null, "list_parties_by_online_members_1_id"));
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) Test(org.junit.jupiter.api.Test)

Example 14 with PartiesPlaceholder

use of com.alessiodp.parties.common.addons.internal.PartiesPlaceholder in project Parties by AlessioDP.

the class PartiesPlaceholderTest method testPlaceholderName.

@Test
public void testPlaceholderName() {
    PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder("name");
    assertEquals(PartiesPlaceholder.NAME, placeholder);
    assertEquals(party1.getName(), placeholder.formatPlaceholder(player1, party1, "name"));
    placeholder = PartiesPlaceholder.getPlaceholder("party");
    assertEquals(PartiesPlaceholder.PARTY, placeholder);
    assertEquals(party1.getName(), placeholder.formatPlaceholder(player1, party1, "party"));
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) Test(org.junit.jupiter.api.Test)

Example 15 with PartiesPlaceholder

use of com.alessiodp.parties.common.addons.internal.PartiesPlaceholder in project Parties by AlessioDP.

the class PartiesPlaceholderTest method testPlaceholderColorCommand.

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

Aggregations

PartiesPlaceholder (com.alessiodp.parties.common.addons.internal.PartiesPlaceholder)24 Test (org.junit.jupiter.api.Test)21 PartyColorImpl (com.alessiodp.parties.common.parties.objects.PartyColorImpl)3 PartyImpl (com.alessiodp.parties.common.parties.objects.PartyImpl)2 PartyPlayerImpl (com.alessiodp.parties.common.players.objects.PartyPlayerImpl)2 Matcher (java.util.regex.Matcher)2 RankManager (com.alessiodp.parties.common.players.RankManager)1 PartyRankImpl (com.alessiodp.parties.common.players.objects.PartyRankImpl)1 EventHandler (org.bukkit.event.EventHandler)1