From 5c5a0acd18589856eb825d17c85d95db0111fa51 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Fri, 23 Sep 2011 12:46:31 -0400 Subject: [PATCH] Fixed "list" to not show junk in console. --- .../TotalFreedomMod/TotalFreedomMod.java | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java index ab33c71..de36e39 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java +++ b/src/me/StevenLawson/TotalFreedomMod/TotalFreedomMod.java @@ -101,35 +101,43 @@ public class TotalFreedomMod extends JavaPlugin } else if(cmd.getName().equalsIgnoreCase("listreal") || cmd.getName().equalsIgnoreCase("list")) { - StringBuilder online = new StringBuilder(); - online.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(Bukkit.getOnlinePlayers().length); - online.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(Bukkit.getMaxPlayers()); - online.append(ChatColor.BLUE).append(" players online."); - sender.sendMessage(online.toString()); - + StringBuilder onlineStats = new StringBuilder(); StringBuilder onlineUsers = new StringBuilder(); - onlineUsers.append("Connected players: "); - boolean first = true; - for (Player p : Bukkit.getOnlinePlayers()) + + if (player == null) { - if (first) - { - first = false; - } - else - { - onlineUsers.append(", "); - } - if (p.isOp()) - { - onlineUsers.append(ChatColor.RED).append(p.getName()); - } - else + onlineStats.append(String.format("There are %d out of a maximum %d players online.", Bukkit.getOnlinePlayers().length, Bukkit.getMaxPlayers())); + + onlineUsers.append("Connected players: "); + boolean first = true; + for (Player p : Bukkit.getOnlinePlayers()) { + if (first) first = false; + else onlineUsers.append(", "); onlineUsers.append(p.getName()); } - onlineUsers.append(ChatColor.WHITE); } + else + { + onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(Bukkit.getOnlinePlayers().length); + onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(Bukkit.getMaxPlayers()); + onlineStats.append(ChatColor.BLUE).append(" players online."); + + onlineUsers.append("Connected players: "); + boolean first = true; + for (Player p : Bukkit.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()); return true;