Add one by one [HELP]

Discussion in 'Spigot Plugin Development' started by Settler, Jun 21, 2015.

  1. Hello,
    How to make something that will add one by one player to an hash map.
    Thanks.
     
  2. Be more specific
     
  3. A for loop with players online length?
     
  4. If you mean adding players with a delay, create a new thread that will add the players and make the thread.sleep(milliseconds timeout) void.
     
  5. Why would you want to create a new thread just for the sake of adding a player...
    Use Bukkit#getScheduler()#scheduleSyncDelayedTask or use a Bukkit Runnable
     
  6. because a thread can do more than one thing at the same time!
     
    • Funny Funny x 1
  7. false
     
    • Like Like x 4
  8. Using a for loop, loop through all the players and for each one add them to the list.
     
    • Agree Agree x 1
  9. I have mechanisam when player join to the server he gets serial number. So when server restarts all player need to be added to a serialnumber hashmap. One by one.
    @bo0tzz
     
  10. Then loop through the players and add them to the hashmap, like I said?
     
  11. When someone join to the server he gets his serialnumber. For example third person who joined to the server has serialnumber 3. Or i maybe didn't understand you.
    @bo0tzz
     
  12. Well, on join, put the player in the hashmap. I would advise against using serial numbers such as 3, 4, 5, and continuing - rather, use the UUID of the player.
     
  13. I already made on join event. But when server restarts hash map is deleting
    @bo0tzz
     
  14. Obviously, a hashmap can't be saved if the JVM shuts off - this should be basic knowledge. If you want to save the hashmap contents, you'll have to save it to a file.