Bukkit Plugin
Posted: Mon Apr 09, 2012 8:40 pm
Content Deleted
this is pretty easy, instead of plugin.getServer().getOnlinePlayers() which gets all players on the server you can do sender.getWorld().getPlayers() which gets all of the players in a world.SamzRulez wrote:EDIT: And also I want to only get the players that are in the same world as the sender cause this only happen when a command is entered.
ArrayList<String> awakePlayers = new ArrayList<String>(); for (Player player : ((Player) sender).getWorld().getPlayers()){ if (player.isSleeping() == false){ awakePlayers.add(player.getName()); } }then you can easily format that list to look nice by first outputting the first item in the list and then every other item with the separator before it.
StringBuilder result = new StringBuilder(); result.append(awakePlayers.get(0)); for (int i = 1; i < awakePlayers.size(); ++i){ result.append(", "); result.append(awakePlayers.get(i)); } sender.sendMessage(result.toString());There is a bit of error checking you will need to add, if the command comes from the console this will fail because there is no .getWorld() for the console. It will also fail if there are no players awake.