getWorld() Problems

Discussion in 'Plugin Development' started by cpi2001, Mar 12, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    cpi2001

    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
     
  2. Offline

    MOMOTHEREAL

    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);
     
    acecheesecr14 likes this.
  3. Offline

    Amgis

    cpi2001
    Code:java
    1. public Set<Player> getPlayersInWorld(Player player) {
    2.  
    3. Set<Player> players;
    4.  
    5. players = new HashSet<Player>();
    6.  
    7. for(Player comparingPlayer:Bukkit.getOnlinePlayers()) {
    8.  
    9. if(!player.equals(comparingPlayer) &&
    10. player.getWorld().equals(comparingPlayer.getWorld())) {
    11.  
    12. players.add(comparingPlayer);
    13. }
    14. }
    15.  
    16. return players;
    17. }
     
  4. Offline

    Maurdekye

    Amgis It's just getWorld().getPlayers(). I don't see what you're all going on about.
     
  5. Offline

    Amgis

    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.
     
  6. Offline

    Maurdekye

    Amgis Then World#getPlayers().remove((Player) sender);. It's not that hard.
     
    Amgis likes this.
  7. Offline

    Amgis

    Maurdekye

    I see. Thanks for the correction.
    Code:java
    1. public List<Player> getPlayersInWorld(Player player) {
    2.  
    3. List<Player> players = player.getWorld().getPlayers();
    4.  
    5. players.remove(player);
    6.  
    7. return players;
    8. }
     
  8. Offline

    acecheesecr14

    You shouldn't be storing players, use their names!
    It can create a massive memory leak!
     
  9. Offline

    cpi2001

    Amgis likes this.
  10. Only if not dealt with correctly ;)
     
  11. Offline

    acecheesecr14

    Chances are, most people aren't going to know that they have to unload all the data on disconnect...
     
Thread Status:
Not open for further replies.

Share This Page