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);
}
}
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;
}
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"));
}
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"));
}
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"));
}
Aggregations