Page 1 of 1

Bukkit Plugin

Posted: Mon Apr 09, 2012 8:40 pm
by Samuel98
Content Deleted

Re: Bukkit Plugin

Posted: Tue Apr 10, 2012 3:33 pm
by jacek
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.
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.

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.