Search in sources :

Example 21 with PartiesPlaceholder

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

the class PartiesPlaceholderTest method testPlaceholderListPartiesByOthers.

@Test
public void testPlaceholderListPartiesByOthers() {
    PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_members_1");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_MEMBERS_NUMBER, placeholder);
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_members_1_id");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_MEMBERS_NUMBER_PLACEHOLDER, placeholder);
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_kills_1");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_KILLS_NUMBER, placeholder);
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_kills_1_id");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_KILLS_NUMBER_PLACEHOLDER, placeholder);
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_experience_1");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_EXPERIENCE_NUMBER, placeholder);
    placeholder = PartiesPlaceholder.getPlaceholder("list_parties_by_experience_1_id");
    assertEquals(PartiesPlaceholder.LIST_PARTIES_BY_EXPERIENCE_NUMBER_PLACEHOLDER, placeholder);
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) Test(org.junit.jupiter.api.Test)

Example 22 with PartiesPlaceholder

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

the class PartiesPlaceholderTest method testPlaceholderMotd.

@Test
public void testPlaceholderMotd() {
    PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder("motd");
    assertEquals(PartiesPlaceholder.MOTD, placeholder);
    assertEquals("", placeholder.formatPlaceholder(player1, party1, "motd"));
    party1.setAccessible(true);
    party1.setMotd("motd");
    party1.setAccessible(false);
    assertEquals(party1.getMotd(), placeholder.formatPlaceholder(player1, party1, "motd"));
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) Test(org.junit.jupiter.api.Test)

Example 23 with PartiesPlaceholder

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

the class PartiesPlaceholderTest method testPlaceholderLeaderName.

@Test
public void testPlaceholderLeaderName() {
    PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder("leader_name");
    assertEquals(PartiesPlaceholder.LEADER_NAME, placeholder);
    assertEquals("Dummy", placeholder.formatPlaceholder(player1, party1, "leader_name"));
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) Test(org.junit.jupiter.api.Test)

Example 24 with PartiesPlaceholder

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

the class MessageUtils method convertPlaceholders.

public String convertPlaceholders(String message, PartyPlayerImpl player, PartyImpl party, String emptyPlaceholder) {
    String ret = message;
    String replacement;
    Matcher matcher = PLACEHOLDER_PATTERN.matcher(ret);
    while (matcher.find()) {
        String identifier = matcher.group(1);
        // Match basic placeholders
        switch(CommonUtils.toLowerCase(identifier)) {
            case "%player%":
            case "%user%":
                if (player != null) {
                    replacement = player.getName();
                    ret = ret.replace(identifier, replacement);
                }
                break;
            // Nothing to do
            default:
        }
        PartiesPlaceholder placeholder = PartiesPlaceholder.getPlaceholder(stripPlaceholder(identifier));
        if (placeholder != null) {
            replacement = placeholder.formatPlaceholder(player, party, stripPlaceholder(identifier), emptyPlaceholder);
            if (replacement != null)
                ret = ret.replace(identifier, replacement);
        }
    }
    return ret;
}
Also used : PartiesPlaceholder(com.alessiodp.parties.common.addons.internal.PartiesPlaceholder) Matcher(java.util.regex.Matcher)

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