From 30f144b21b9f67a8a52bb377df8690e6fd56d183 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 15 Jan 2011 18:31:20 -0800 Subject: [PATCH] Typing /list or /who will show an improved playerlist --- .../vPlayersOnline/vBlockListener.java | 3 +- .../vPlayersOnline/vPlayerListener.java | 40 +++++++++++++++---- .../vPlayersOnline/vPlayersOnline.java | 19 ++------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vBlockListener.java b/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vBlockListener.java index 71c749a11..02e016bef 100644 --- a/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vBlockListener.java +++ b/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vBlockListener.java @@ -1,7 +1,6 @@ package com.bukkit.nossr50.vPlayersOnline; -import org.bukkit.Block; -import org.bukkit.BlockFace; + import org.bukkit.Material; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockListener; diff --git a/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayerListener.java b/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayerListener.java index da25cd250..c5f3f6156 100644 --- a/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayerListener.java +++ b/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayerListener.java @@ -1,12 +1,12 @@ package com.bukkit.nossr50.vPlayersOnline; -import org.bukkit.Location; -import org.bukkit.Player; +import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerListener; -import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.ChatColor; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Handle events for all Player related events @@ -14,18 +14,42 @@ import org.bukkit.ChatColor; */ public class vPlayerListener extends PlayerListener { private final vPlayersOnline plugin; + protected static final Logger log = Logger.getLogger("Minecraft"); public vPlayerListener(vPlayersOnline instance) { plugin = instance; } - - public void onPlayerJoin(PlayerEvent event) { - Player player = event.getPlayer(); - Player players[] = plugin.getServer().getOnlinePlayers(); + //Function to count the players + public int playerCount(){ + Player players[] = plugin.getServer().getOnlinePlayers(); int x = 0; for(Player hurrdurr: players){ x++; } - player.sendMessage(ChatColor.GREEN + "There are " + x + " players online"); + return x; + } + + //Message to be sent when a player joins + public void onPlayerJoin(PlayerEvent event) { + Player player = event.getPlayer(); + player.sendMessage(ChatColor.GREEN + "There are " + playerCount() + " players online"); } + //Message to be sent when a player uses /list + public void onPlayerCommand(PlayerChatEvent event) { + log.log(Level.INFO, event.getMessage() + "|" + event.getPlayer().getName()); + String[] split = event.getMessage().split(" "); + Player player = event.getPlayer(); + if(split[0].equalsIgnoreCase("/list") || split[0].equalsIgnoreCase("/who")){ + event.setCancelled(true); + String tempList = ""; + for(Player p : plugin.getServer().getOnlinePlayers()) + { + if(p != null){ + tempList+= p.getName(); + } + } + //Output the player list + player.sendMessage(ChatColor.RED + "Player List (" + tempList +")"); + } + } } diff --git a/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayersOnline.java b/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayersOnline.java index 12551b788..68a95edd2 100644 --- a/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayersOnline.java +++ b/vPlayersOnline/com/bukkit/nossr50/vPlayersOnline/vPlayersOnline.java @@ -2,7 +2,7 @@ package com.bukkit.nossr50.vPlayersOnline; import java.io.File; import java.util.HashMap; -import org.bukkit.Player; +import org.bukkit.event.player.*; import org.bukkit.Server; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event; @@ -10,6 +10,7 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.PluginManager; +import org.bukkit.entity.Player; /** * vPlayersOnline for Bukkit @@ -30,25 +31,13 @@ public class vPlayersOnline extends JavaPlugin { public void onEnable() { PluginManager pm = getServer().getPluginManager(); - getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this); - getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this); + pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this); //Displays a message when plugin is loaded PluginDescriptionFile pdfFile = this.getDescription(); System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); } public void onDisable() { - System.out.println("vPlayersOnline disabled."); } - public boolean isDebugging(final Player player) { - if (debugees.containsKey(player)) { - return debugees.get(player); - } else { - return false; - } - } - - public void setDebugging(final Player player, final boolean value) { - debugees.put(player, value); - } }