Bukkit Plugin

Any help topics that don't fit in the current categories can go here.
Post Reply
User avatar
Samuel98
Posts: 46
Joined: Wed Oct 05, 2011 1:20 am
Location: United Kingdom
Contact:

Bukkit Plugin

Post by Samuel98 »

Content Deleted
Last edited by Samuel98 on Sun Mar 22, 2015 9:35 pm, edited 2 times in total.
Image

Samuel Carr
Server Developer
W: http://epiccrafts.co.uk
E: [url]mailto://samuel.carr@epiccrafts.co.uk[/url]
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Bukkit Plugin

Post 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.
Image
Post Reply