Hi guys, I am having a little bit of trouble with a plugin i am making. Can someone please tell me the code to list players in THEIR world only if they type a command. Thanks
Create a new HashMap with key type String, and object type List<String> Then when you wand to add the player, you can do something like this: List<String> l = map.get(player.getWolrd().getName()); l.add(p.getName()); map.put(l);
cpi2001 Code:java public Set<Player> getPlayersInWorld(Player player) { Set<Player> players; players = new HashSet<Player>(); for(Player comparingPlayer:Bukkit.getOnlinePlayers()) { if(!player.equals(comparingPlayer) && player.getWorld().equals(comparingPlayer.getWorld())) { players.add(comparingPlayer); } } return players;}
Maurdekye I was under the impression that he wanted a list of players in the same world as a player but not including the player himself.
Maurdekye I see. Thanks for the correction. Code:java public List<Player> getPlayersInWorld(Player player) { List<Player> players = player.getWorld().getPlayers(); players.remove(player); return players;}