Search in sources :

Example 1 with ReplaceTextBundle

use of com.loohp.interactivechat.objectholders.ReplaceTextBundle in project InteractiveChat by LOOHP.

the class PlayernameDisplay method getNames.

private static Collection<ReplaceTextBundle> getNames() {
    List<ReplaceTextBundle> names = new ArrayList<>();
    ICPlayerFactory.getOnlineICPlayers().forEach(each -> {
        if (VanishUtils.isVanished(each.getUniqueId())) {
            return;
        }
        names.add(new ReplaceTextBundle(ChatColorUtils.stripColor(each.getName()), each, each.getName()));
        if (InteractiveChat.useBukkitDisplayName && !ChatColorUtils.stripColor(each.getName()).equals(ChatColorUtils.stripColor(each.getDisplayName()))) {
            names.add(new ReplaceTextBundle(ChatColorUtils.stripColor(each.getDisplayName()), each, each.getDisplayName()));
        }
        for (String nickname : each.getNicknames()) {
            names.add(new ReplaceTextBundle(ChatColorUtils.stripColor(nickname), each, nickname));
        }
    });
    CollectionUtils.filter(names, each -> !each.getPlaceholder().isEmpty());
    names.sort(Comparator.reverseOrder());
    return new LinkedHashSet<>(names);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ReplaceTextBundle(com.loohp.interactivechat.objectholders.ReplaceTextBundle) ArrayList(java.util.ArrayList)

Example 2 with ReplaceTextBundle

use of com.loohp.interactivechat.objectholders.ReplaceTextBundle in project InteractiveChat by LOOHP.

the class PlayernameDisplay method process.

public static Component process(Component component, Optional<ICPlayer> sender, Player receiver, long unix) {
    Collection<ReplaceTextBundle> names = PlayernameDisplay.names;
    if (names == null) {
        names = getNames();
    }
    Set<HoverEvent<?>> doNotReplace = new HashSet<>();
    for (ReplaceTextBundle entry : names) {
        component = processPlayer(entry.getPlaceholder(), entry.getPlayer(), sender, receiver, component, doNotReplace, unix);
    }
    return ComponentCompacting.optimize(component);
}
Also used : HoverEvent(net.kyori.adventure.text.event.HoverEvent) ReplaceTextBundle(com.loohp.interactivechat.objectholders.ReplaceTextBundle) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ReplaceTextBundle (com.loohp.interactivechat.objectholders.ReplaceTextBundle)2 LinkedHashSet (java.util.LinkedHashSet)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 HoverEvent (net.kyori.adventure.text.event.HoverEvent)1