use of com.sk89q.worldguard.util.profile.cache.ProfileCache in project WorldGuard by EngineHub.
the class DefaultDomain method toPlayersComponent.
private Component toPlayersComponent(ProfileCache cache) {
List<String> uuids = Lists.newArrayList();
Map<String, UUID> profileMap = Maps.newHashMap();
for (String name : playerDomain.getPlayers()) {
profileMap.put(name, null);
}
if (cache != null) {
ImmutableMap<UUID, Profile> results = cache.getAllPresent(playerDomain.getUniqueIds());
for (UUID uuid : playerDomain.getUniqueIds()) {
Profile profile = results.get(uuid);
if (profile != null) {
profileMap.put(profile.getName(), uuid);
} else {
uuids.add(uuid.toString());
}
}
} else {
for (UUID uuid : playerDomain.getUniqueIds()) {
uuids.add(uuid.toString());
}
}
final TextComponent.Builder builder = TextComponent.builder("");
final Iterator<TextComponent> profiles = profileMap.keySet().stream().sorted().map(name -> {
final UUID uuid = profileMap.get(name);
final TextComponent component = TextComponent.of(name, TextColor.YELLOW).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, uuid == null ? TextComponent.of("Name only", TextColor.GRAY) : TextComponent.of("Last known name of uuid: ", TextColor.GRAY).append(TextComponent.of(uuid.toString(), TextColor.WHITE))));
if (uuid == null) {
return component;
}
return component.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, uuid.toString()));
}).iterator();
while (profiles.hasNext()) {
builder.append(profiles.next());
if (profiles.hasNext() || !uuids.isEmpty()) {
builder.append(TextComponent.of(", "));
}
}
if (!uuids.isEmpty()) {
builder.append(TextComponent.of(uuids.size() + " unknown uuid" + (uuids.size() == 1 ? "" : "s"), TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(String.join("\n", uuids)).append(TextComponent.newline().append(TextComponent.of("Click to select"))))).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, String.join(",", uuids))));
}
return builder.build();
}
Aggregations