Search in sources :

Example 1 with UserRank

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]));
    }
}
Also used : UserRank(com.easterlyn.user.UserRank) TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) AutoUser(com.easterlyn.user.AutoUser) User(com.easterlyn.user.User) HashMap(java.util.HashMap) AutoUser(com.easterlyn.user.AutoUser) ArrayList(java.util.ArrayList) Description(co.aikar.commands.annotation.Description) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandPermission(co.aikar.commands.annotation.CommandPermission) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 2 with UserRank

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;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) UserRank(com.easterlyn.user.UserRank) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) OfflinePlayer(org.bukkit.OfflinePlayer)

Aggregations

UserRank (com.easterlyn.user.UserRank)2 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 CommandAlias (co.aikar.commands.annotation.CommandAlias)1 CommandCompletion (co.aikar.commands.annotation.CommandCompletion)1 CommandPermission (co.aikar.commands.annotation.CommandPermission)1 Description (co.aikar.commands.annotation.Description)1 Syntax (co.aikar.commands.annotation.Syntax)1 AutoUser (com.easterlyn.user.AutoUser)1 User (com.easterlyn.user.User)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)1 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Player (org.bukkit.entity.Player)1