Bukkit Plugin
Bukkit Plugin
Content Deleted
Last edited by Samuel98 on Sun Mar 22, 2015 9:35 pm, edited 2 times in total.
Samuel Carr
Server Developer
W: http://epiccrafts.co.uk
E: [url]mailto://samuel.carr@epiccrafts.co.uk[/url]
Re: Bukkit Plugin
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.
The formatting thing is a little bit more awkward, basically you need to know if the current player you are on in your loop is the first one in the list. There is no way to do that with the loop above since you have no idea if the player is sleeping or not until you have done the check. So put all of the awake players into a new list
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.