Search in sources :

Example 1 with Displayable

use of me.totalfreedom.totalfreedommod.rank.Displayable in project TotalFreedomMod by TotalFreedom.

the class Command_list method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length > 1) {
        return false;
    }
    if (FUtil.isFromHostConsole(sender.getName())) {
        final List<String> names = new ArrayList<>();
        for (Player player : server.getOnlinePlayers()) {
            names.add(player.getName());
        }
        msg("There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE);
        return true;
    }
    final ListFilter listFilter;
    if (args.length == 1) {
        switch(args[0]) {
            case "-a":
                listFilter = ListFilter.ADMINS;
                break;
            case "-i":
                listFilter = ListFilter.IMPOSTORS;
                break;
            case "-f":
                listFilter = ListFilter.FAMOUS_PLAYERS;
                break;
            default:
                return false;
        }
    } else {
        listFilter = ListFilter.PLAYERS;
    }
    final StringBuilder onlineStats = new StringBuilder();
    final StringBuilder onlineUsers = new StringBuilder();
    onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().size());
    onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers());
    onlineStats.append(ChatColor.BLUE).append(" players online.");
    final List<String> names = new ArrayList<>();
    for (Player player : server.getOnlinePlayers()) {
        if (listFilter == ListFilter.ADMINS && !plugin.al.isAdmin(player)) {
            continue;
        }
        if (listFilter == ListFilter.IMPOSTORS && !plugin.al.isAdminImpostor(player)) {
            continue;
        }
        if (listFilter == ListFilter.FAMOUS_PLAYERS && !ConfigEntry.FAMOUS_PLAYERS.getList().contains(player.getName().toLowerCase())) {
            continue;
        }
        Displayable display = plugin.rm.getDisplay(player);
        names.add(display.getColoredTag() + player.getName());
    }
    String playerType = listFilter == null ? "players" : listFilter.toString().toLowerCase().replace('_', ' ');
    onlineUsers.append("Connected ");
    onlineUsers.append(playerType + ": ");
    onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
    if (senderIsConsole) {
        sender.sendMessage(ChatColor.stripColor(onlineStats.toString()));
        sender.sendMessage(ChatColor.stripColor(onlineUsers.toString()));
    } else {
        sender.sendMessage(onlineStats.toString());
        sender.sendMessage(onlineUsers.toString());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) Displayable(me.totalfreedom.totalfreedommod.rank.Displayable) ArrayList(java.util.ArrayList)

Example 2 with Displayable

use of me.totalfreedom.totalfreedommod.rank.Displayable in project TotalFreedomMod by TotalFreedom.

the class Module_help method getBody.

@Override
public String getBody() {
    final CommandMap map = CommandReflection.getCommandMap();
    if (map == null || !(map instanceof SimpleCommandMap)) {
        return paragraph("Error loading commands.");
    }
    final StringBuilder responseBody = new StringBuilder().append(heading("Command Help", 1)).append(paragraph("This page is an automatically generated listing of all plugin commands that are currently live on the server. " + "Please note that it does not include vanilla server commands."));
    final Collection<Command> knownCommands = ((SimpleCommandMap) map).getCommands();
    final Map<String, List<Command>> commandsByPlugin = new HashMap<>();
    for (Command command : knownCommands) {
        String pluginName = "Bukkit";
        if (command instanceof PluginIdentifiableCommand) {
            pluginName = ((PluginIdentifiableCommand) command).getPlugin().getName();
        }
        List<Command> pluginCommands = commandsByPlugin.get(pluginName);
        if (pluginCommands == null) {
            pluginCommands = Lists.newArrayList();
            commandsByPlugin.put(pluginName, pluginCommands);
        }
        pluginCommands.add(command);
    }
    final Iterator<Map.Entry<String, List<Command>>> it = commandsByPlugin.entrySet().iterator();
    while (it.hasNext()) {
        final Map.Entry<String, List<Command>> entry = it.next();
        final String pluginName = entry.getKey();
        final List<Command> commands = entry.getValue();
        Collections.sort(commands, new CommandComparator());
        responseBody.append(heading(pluginName, 2)).append("<ul>\r\n");
        Displayable lastTfmCommandLevel = null;
        for (Command command : commands) {
            if (!TotalFreedomMod.pluginName.equals(pluginName)) {
                responseBody.append(buildDescription(command));
                continue;
            }
            Displayable tfmCommandLevel = FreedomCommand.getFrom(command).getPerms().level();
            if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel) {
                responseBody.append("</ul>\r\n").append(heading(tfmCommandLevel.getName(), 3)).append("<ul>\r\n");
            }
            lastTfmCommandLevel = tfmCommandLevel;
            responseBody.append(buildDescription(command));
        }
        responseBody.append("</ul>\r\n");
    }
    return responseBody.toString();
}
Also used : Displayable(me.totalfreedom.totalfreedommod.rank.Displayable) SimpleCommandMap(org.bukkit.command.SimpleCommandMap) HashMap(java.util.HashMap) PluginIdentifiableCommand(org.bukkit.command.PluginIdentifiableCommand) PluginIdentifiableCommand(org.bukkit.command.PluginIdentifiableCommand) FreedomCommand(me.totalfreedom.totalfreedommod.command.FreedomCommand) Command(org.bukkit.command.Command) List(java.util.List) HashMap(java.util.HashMap) SimpleCommandMap(org.bukkit.command.SimpleCommandMap) Map(java.util.Map) CommandMap(org.bukkit.command.CommandMap) SimpleCommandMap(org.bukkit.command.SimpleCommandMap) CommandMap(org.bukkit.command.CommandMap)

Example 3 with Displayable

use of me.totalfreedom.totalfreedommod.rank.Displayable in project TotalFreedomMod by TotalFreedom.

the class Command_rank method message.

public String message(Player player) {
    Displayable display = plugin.rm.getDisplay(player);
    Rank rank = plugin.rm.getRank(player);
    StringBuilder sb = new StringBuilder();
    sb.append(ChatColor.AQUA).append(player.getName()).append(" is ").append(display.getColoredLoginMessage());
    if (rank != display) {
        sb.append(ChatColor.AQUA).append(" (").append(rank.getColoredName()).append(ChatColor.AQUA).append(')');
    }
    return sb.toString();
}
Also used : Displayable(me.totalfreedom.totalfreedommod.rank.Displayable) Rank(me.totalfreedom.totalfreedommod.rank.Rank)

Aggregations

Displayable (me.totalfreedom.totalfreedommod.rank.Displayable)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 FreedomCommand (me.totalfreedom.totalfreedommod.command.FreedomCommand)1 Rank (me.totalfreedom.totalfreedommod.rank.Rank)1 Command (org.bukkit.command.Command)1 CommandMap (org.bukkit.command.CommandMap)1 PluginIdentifiableCommand (org.bukkit.command.PluginIdentifiableCommand)1 SimpleCommandMap (org.bukkit.command.SimpleCommandMap)1 Player (org.bukkit.entity.Player)1