Solved Removing online players from a HashMap?

Discussion in 'Plugin Development' started by WesJD, Nov 22, 2014.

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

    WesJD

    Well, I was about finished with coding this minigame, though it doesn't seem to remove players that are online & in the HashMap...

    Code:
    Code:java
    1. for(Player online : PO.getOnlinePlayers())
    2. if(Scoreboards.pointD.containsKey(online.getName())) {
    3. Scoreboards.pointD.put(online.getName(), 0);
    4. }


    PO.java:
    Code:java
    1. public static List<Player> getOnlinePlayers() {
    2. List<Player> list = Lists.newArrayList();
    3. for (World world : Bukkit.getWorlds()) {
    4. list.addAll(world.getPlayers());
    5. }
    6. return Collections.unmodifiableList(list);
    7. }
     
  2. hashmap.remove(key);
     
    Skionz likes this.
  3. Offline

    WesJD

    FisheyLP
    I'll try it again, didn't seem to work earlier..
     
  4. ...
    just do
    Code:java
    1. return list;
     
  5. Offline

    Dragonphase

    WesJD

    Firstly, I can immediately see that you understand little of the principles of object orientated programming, as you are making seemingly unnecessary calls to static methods. Please learn about statics and where it is appropriate to use them.

    Secondly, why are you using a method like this to retrieve an immutable list of all online players? Why not use:

    Code:java
    1. Bukkit.getOnlinePlayers();
     
  6. Offline

    teej107

    Why are you not using Bukkit.getOnlinePlayers()?

    Post code or we have no proof of you trying.
     
  7. Offline

    WesJD

    FisheyLP
    Changed the return, and it's working now. Thanks.

    I'm not going to question it as I'm just a basic Java programmer. I'll take a look at when it is. Thanks.
     
Thread Status:
Not open for further replies.

Share This Page