From 9344a1311614b2b0ab21871063956aae0f96d3ba Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Mon, 17 Sep 2012 21:33:01 -0400 Subject: [PATCH] Rewrote the /list command. Now shows superadmins in GOLD + a few other goodies. Fixed a bug in the cager. --- .../Commands/Command_list.java | 88 ++++++++----------- .../Listener/TFM_PlayerListener.java | 2 +- 2 files changed, 37 insertions(+), 53 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java index 105a9bda..526033ea 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_list.java @@ -1,5 +1,9 @@ package me.StevenLawson.TotalFreedomMod.Commands; +import java.util.ArrayList; +import java.util.List; +import me.StevenLawson.TotalFreedomMod.TFM_Util; +import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -10,78 +14,58 @@ public class Command_list extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + final boolean is_clanforge = sender.getName().equalsIgnoreCase("remotebukkit"); + StringBuilder onlineStats = new StringBuilder(); StringBuilder onlineUsers = new StringBuilder(); - if (senderIsConsole) + onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().length); + onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers()); + onlineStats.append(ChatColor.BLUE).append(" players online."); + + List player_names = new ArrayList(); + for (Player p : server.getOnlinePlayers()) { - onlineStats.append(String.format("There are %d out of a maximum %d players online.", server.getOnlinePlayers().length, server.getMaxPlayers())); + String prefix = ""; - onlineUsers.append("Connected players: "); - boolean first = true; - for (Player p : server.getOnlinePlayers()) + if (!is_clanforge) { - if (first) + if (TFM_Util.isUserSuperadmin(p)) { - first = false; - } - else - { - onlineUsers.append(", "); - } - - if (sender.getName().equalsIgnoreCase("remotebukkit")) - { - onlineUsers.append(p.getName()); + if (p.isOp()) + { + prefix = (ChatColor.GOLD + "[SA+OP]"); + } + else + { + prefix = (ChatColor.GOLD + "[SA]"); + } } else { if (p.isOp()) { - onlineUsers.append("[OP]").append(p.getName()); - } - else - { - onlineUsers.append(p.getName()); + prefix = (ChatColor.RED + "[OP]"); } } } + + player_names.add(prefix + p.getName() + ChatColor.WHITE); + } + + onlineUsers.append("Connected players: ").append(StringUtils.join(player_names, ", ")); + + if (senderIsConsole) + { + sender.sendMessage(ChatColor.stripColor(onlineStats.toString())); + sender.sendMessage(ChatColor.stripColor(onlineUsers.toString())); } else { - onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().length); - onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers()); - onlineStats.append(ChatColor.BLUE).append(" players online."); - - onlineUsers.append("Connected players: "); - boolean first = true; - for (Player p : server.getOnlinePlayers()) - { - if (first) - { - first = false; - } - else - { - onlineUsers.append(", "); - } - - if (p.isOp()) - { - onlineUsers.append(ChatColor.RED).append(p.getName()); - } - else - { - onlineUsers.append(p.getName()); - } - - onlineUsers.append(ChatColor.WHITE); - } + sender.sendMessage(onlineStats.toString()); + sender.sendMessage(onlineUsers.toString()); } - sender.sendMessage(onlineStats.toString()); - sender.sendMessage(onlineUsers.toString()); - return true; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 6f16d2d2..06f51471 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -215,7 +215,7 @@ public class TFM_PlayerListener implements Listener if (out_of_cage) { - playerdata.setCaged(true, target_pos, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER), playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER)); + playerdata.setCaged(true, target_pos, playerdata.getCageMaterial(TFM_UserInfo.CageLayer.OUTER), playerdata.getCageMaterial(TFM_UserInfo.CageLayer.INNER)); playerdata.regenerateHistory(); playerdata.clearHistory(); TFM_Util.buildHistory(target_pos, 2, playerdata);