Search in sources :

Example 1 with PartiesPlaceholder

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

the class EssentialsChatHandler method onChatPlayer.

@EventHandler
public void onChatPlayer(AsyncPlayerChatEvent event) {
    String old = event.getFormat();
    if (old.toLowerCase().contains("{parties_")) {
        // Bypass useless checks if parties doesn't exist
        boolean somethingChanged = false;
        PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
        PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
        Pattern pat = Pattern.compile("\\{parties_([a-z\\_]+)\\}", Pattern.CASE_INSENSITIVE);
        Matcher mat = pat.matcher(old);
        while (mat.find()) {
            String base = mat.group(0);
            String identifier = mat.group(1);
            if (identifier != null) {
                PartiesPlaceholder ph = PartiesPlaceholder.getPlaceholder(identifier);
                if (ph != null) {
                    old = old.replace(base, ph.formatPlaceholder(pp, party));
                    somethingChanged = true;
                }
            }
        }
        if (somethingChanged)
            event.setFormat(old);
    }
}
Also used : Pattern(java.util.regex.Pattern) PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPlaceholder(com.alessiodp.parties.addons.internal.PartiesPlaceholder) Matcher(java.util.regex.Matcher) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity) EventHandler(org.bukkit.event.EventHandler)

Example 2 with PartiesPlaceholder

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

the class PAPIHook method onPlaceholderRequest.

@Override
public String onPlaceholderRequest(Player p, String identifier) {
    PartyPlayerEntity pp = plugin.getPlayerManager().getPlayer(p.getUniqueId());
    PartyEntity party = plugin.getPartyManager().getParty(pp.getPartyName());
    PartiesPlaceholder ph = PartiesPlaceholder.getPlaceholder(identifier);
    return ph != null ? ph.formatPlaceholder(pp, party) : "";
}
Also used : PartyPlayerEntity(com.alessiodp.parties.players.objects.PartyPlayerEntity) PartiesPlaceholder(com.alessiodp.parties.addons.internal.PartiesPlaceholder) PartyEntity(com.alessiodp.parties.parties.objects.PartyEntity)

Aggregations

PartiesPlaceholder (com.alessiodp.parties.addons.internal.PartiesPlaceholder)2 PartyEntity (com.alessiodp.parties.parties.objects.PartyEntity)2 PartyPlayerEntity (com.alessiodp.parties.players.objects.PartyPlayerEntity)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 EventHandler (org.bukkit.event.EventHandler)1