use of com.easterlyn.user.UserRank in project Easterlyn by Easterlyn.
the class ListCommand method list.
@CommandAlias("list|ls")
@Description("{@@sink.module.list.description}")
@CommandPermission("easterlyn.command.list")
@Syntax("")
@CommandCompletion("")
public void list(BukkitCommandIssuer issuer) {
Player sender = issuer.getPlayer();
UserRank[] ranks = UserRank.values();
Multimap<String, User> groupedUsers = HashMultimap.create();
int total = 0;
for (Player player : Bukkit.getOnlinePlayers()) {
if (sender != null && !sender.canSee(player)) {
continue;
}
++total;
for (int i = ranks.length - 1; i >= 0; --i) {
UserRank rank = ranks[i];
if (i == 0 || player.hasPermission(rank.getPermission())) {
groupedUsers.put(rank.getFriendlyName(), core.getUserManager().getUser(player.getUniqueId()));
break;
}
}
}
if (ThreadLocalRandom.current().nextDouble() < .001) {
Map<String, String> easterEgg = new HashMap<>();
easterEgg.put("name", "Herobrine");
easterEgg.put("color", ChatColor.BLACK.toString());
groupedUsers.put(UserRank.MEMBER.getFriendlyName(), new AutoUser(core, easterEgg));
}
issuer.sendInfo(MessageKey.of("sink.module.list.header"), "{value}", String.valueOf(total), "{max}", String.valueOf(Bukkit.getMaxPlayers()));
for (int i = ranks.length - 1; i >= 0; --i) {
String groupName = ranks[i].getFriendlyName();
if (i > 0 && groupName.equals(ranks[i - 1].getFriendlyName()) || !groupedUsers.containsKey(groupName)) {
continue;
}
Collection<User> users = groupedUsers.get(groupName);
List<BaseComponent> components = new ArrayList<>(users.size() * 2 + 2);
TextComponent component = new TextComponent(groupName);
component.setColor(ranks[i].getColor());
components.add(component);
component = new TextComponent(": ");
component.setColor(ChatColor.YELLOW);
components.add(component);
TextComponent separator = new TextComponent(", ");
separator.setColor(ChatColor.YELLOW);
users.forEach(user -> {
components.add(user.getMention());
components.add(separator);
});
components.remove(components.size() - 1);
issuer.getIssuer().spigot().sendMessage(components.toArray(new BaseComponent[0]));
}
}
use of com.easterlyn.user.UserRank in project Easterlyn by Easterlyn.
the class DiscordUser method getMention.
@Override
public TextComponent getMention() {
TextComponent component = new TextComponent("@" + getDisplayName());
component.setColor(getColor());
component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "http://discord.easterlyn.com"));
TextComponent line = new TextComponent("#main");
line.setColor(Colors.CHANNEL);
TextComponent extra = new TextComponent("on Discord");
extra.setColor(ChatColor.WHITE);
line.addExtra(extra);
line.addExtra(extra);
component.addExtra(line);
line = new TextComponent("\n" + getDisplayName());
line.setColor(getColor());
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(getUniqueId());
if (offlinePlayer.getName() != null && !offlinePlayer.getName().equals(line.getText().trim())) {
TextComponent realName = new TextComponent(" (" + offlinePlayer.getName() + ")");
realName.setColor(ChatColor.WHITE);
line.addExtra(realName);
}
component.addExtra(line);
UserRank rank = getRank();
line = new TextComponent("\n" + rank.getFriendlyName());
line.setColor(rank.getColor());
component.addExtra(line);
return component;
}
Aggregations