A few questions...

Discussion in 'Spigot Plugin Development' started by WulfGamesYT, Jun 13, 2018.

  1. Hey everyone, just want to ask a couple of questions, so here goes nothing:

    1. Is there a way to get players, when they rejoin on some servers to instantly teleport to hub, i.e. forgetting their last position? Because I've noticed if they rejoin it sends them to their last location before they logged out and teleports them to the spawn.

    2. Is there a way to loop through ArrayList's and have items being removed from it at the same time on the same "main thread" without causing the ConcurrentModificationException error? E.g. loop through the list at one time and if it's being looped through and someone logs out for example and it removes their instance from the list it causes this error?

    3. Is there a way to load multiple chunks on an async thread for a random tp plugin, because loading chunks on the main thread obviously, even at the same time and with a interval of like a second between each chunk loads, it causes lag both ways?

    Thank you, and have a great day!
     
  2. Praya

    Benefactor

    1. PlayerJoinEvent -> teleport player to spawn
    2. List<Object> newList = new ArrayList<Object>(list); -> loop the newList -> remove object from list
    3. ¯\_(ツ)_/¯
     
  3. This didn't help.
     
  4. Praya

    Benefactor

    do you mean same main thread is by using same list?
     
  5. I'm not changing the arraylist on an async thread, I'm only looping through it on the main thread and removing elements on the main thread but it still causes errors. It was initialized as a public arraylist on the main thread.
     
  6. Would this help? http://www.baeldung.com/java-concurrentmodificationexception
     
  7. I'll give it a read but I've been reading on about the error before making this thread and I can't see why its causing the error, I'm doing everything it says and I'm trying to avoid Iterators for arraylists.
     
  8. Can you post the code causing this error so we have something to actually debug?
     
  9. You can't modify a list while iterating over it, generally. Unless you use an Iterator, something like this:

    Code (Text):
    Iterator<String> iterator = yourList.iterator();
    while (iterator.hasNext()) {
      String value = iterator.next();
      if (value is something you want to remove)
           iterator.remove();
    }
     
    • Agree Agree x 1
  10. The code would be quite big to post as it's in several classes, e.g. about 14 classes and used on different plugins but I'm 100% sure it's correctly written using for loops, maybe I can sort this problem out on my own but could you guys try and answer my other 2 questions please, thanks?
     
  11. 1. I think you can TP players on join, but not really sure. Hopefully someone else who has done this can answer for sure (it's definitely possible)

    2. I think I answered your loop issue .. use an iterator.

    3. No, you can't load chunks async. Sadly.
     
    • Like Like x 1
  12. 1. If I understood correctly, you can just use PlayerJoinEvent.
    3. You can't load chunks async, it's not safe. If you can calculate the random position before teleporting, you can load the chunks slowly with a runnable. Remember to keep the chunks loaded if you do this, since they will get unloaded if left unused.
     
    • Like Like x 1
  13. PlayerJoinEvent you have to wait 1 tick and then teleport the player else it causes the famous invisibility bug I think for 1.8 servers.
    Also I think there is a way to completely wipe the players last location when they leave, wouldn't that be stored in a world data file for the player or is it stored client side?
     
    • Informative Informative x 1
  14. Player position data is stored in a world's player data folder in a file that's named after the player's UUID. I doubt that you'd ever actually need to modify it though.
     

Share This Page