What happens when a player teleports into an unloaded chunk?

Discussion in 'Plugin Development' started by CorrieKay, Jul 1, 2012.

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

    CorrieKay

    Does the server load it around the player, or does it wait for the chunk to load, then execute the teleport?

    See, in my servers plugin, ive created a home and back commands, and a lot of my players complain about being portaled into walls, into the ground, and in some rare cases (though not rare enough!) they get teleported straight into the void :c

    Now, heres my thought... Maybe the chunk is unloaded, and it messes with where the player ends up? idk... :\
     
  2. Offline

    Jnorr44

    the server starts to load it around the player. Thats why when you tp somewhere that isn't loaded on a slow server, you have to wait before you can see everything around you. And that is also why you fall a little, then pop back up to the original tp... etc...

    EDIT - but it shouldn't mess up where the player ends up...
     
  3. Offline

    chaseoes

    Yeah, lots of home etc. plugins have that issue - it'll teleport them before the chunk is loaded, and they'll start falling, only to stop when it does load (this is how they end up in the ground, they'll start falling, it'll load, then they'll be stuck there). If it's slow at loading they can fall far enough to where they end up in the void.
     
  4. Offline

    CorrieKay

    hmm... i could just force the chunk to load, and create a repeating task that repeatedly asks if the chunk is loaded... then teleport them...
     
  5. Offline

    Paul O'Reilly

    You can force the chunk to load... and hook into the ChunkLoadEvent. Instant gratification with no task required :)
     
  6. Offline

    CorrieKay

    Aye, thats what i was thinking, but im just wondering if thats actually the problem at hand :3

    does forcing a chunk to load pause the thread until the chunk is loaded?
     
  7. Offline

    Jnorr44

    Good idea, ill download that plugin!
     
  8. Offline

    EnvisionRed

    I'm not sure, but loading chunks takes barely any time at all. If it does pause the thread, it will be negligible unless your plugin requires very precise measurements of time etc, etc.
     
  9. Offline

    CorrieKay

    nope, it doesnt.

    thats why im hoping the chunk load method returns after the chunk is actually loaded, instead of schedule the chunk TO be loaded... Cuz the next line will be the teleport.

    At the very least i could probably do:

    chunk.load();
    boolean isLoaded = chunk.isLoaded();
    while(!isLoaded){
    isLoaded = chunk.isLoaded();
    }
    //teleport

    to FORCE it to wait till the chunk is loaded.

    But thats.. Probably not the best way to go x3
     
  10. Offline

    EnvisionRed

    It would work though. "If it looks stupid but works, it's not stupid"
     
    CorrieKay likes this.
  11. Offline

    OstlerDev

    SpoutPlugin does this...
     
  12. Offline

    Jnorr44

    Yes, but spoutplugin is a big plugin for such a small effect. I wouldn't download it if I just wanted teleport-smoothing.
     
  13. Offline

    CorrieKay

    thats a fairly heavy handed solution for something i could do in, as i said above, under five lines of code.
     
  14. Offline

    OstlerDev

    No what I mean is that the SpoutPlugin (no need for client just the plugin in your server dir) automatically grabs when a teleport is going to happen and loads the chunks before sending them.
     
  15. Offline

    CorrieKay

    Orly?

    Thats not a bad idea... Does it require spout to be on the client? or is it a soft dependency?
     
  16. Offline

    Paul O'Reilly

    You could try using Player.sendChunkChange for a similar effect?
     
  17. Offline

    CorrieKay

    ooh, good idea.
     
  18. Offline

    OstlerDev

    It does not require the Spout Client, just their plugin in your plugins folder.
     
  19. Offline

    andf54

    What you describe is similar to what I had. I used getHighestBlockYAt(...) to get the location for the player to spawn. The problem is that if the chunk isn't loaded, then it might return invalid Y.

    I just did .loadChunk() and added +2 to y.
     
  20. Offline

    OstlerDev

    I usually use
    Code:
    Chunk c = w.getChunkAt(new Location(w,x,0,z));
    w.loadChunk(c);
     
  21. Offline

    Jnorr44

    This plugin will solve MANY issues! I was looking for one for my server for a long time. Yours is a first!
     
  22. Offline

    md_5

    And then you will leak chunks.
    iirc chunks loaded like that aren't auto unloaded.
     
  23. Offline

    CorrieKay

    specifically with the loadChunk method?
     
  24. Offline

    md_5

    Yeah, thats what I thought. Someone may wanna double check though.
     
  25. Offline

    OstlerDev

    Hmm, I may be wrong but it unloads as long as the player leaves the area, but if you cancel the teleport then you would do
    c.unload();
     
  26. Offline

    Paul O'Reilly

    Just came across this while searching for plugins for our server:
    http://dev.bukkit.org/server-mods/warptastic/
    The authors intent:
    Could be worth looking to see how Odiumxxx designed it. (Something like jd-gui can help with looking at how compiled code works)
     
  27. Offline

    CorrieKay

    Huh, i checked his github (or rather, the github with that exact name + bukkit plugin repos in it) and it doesnt seem to have warptastic. Guess ill just have to decompile it and take a looksee
     
  28. do this. If chunk not rendered, Warp them, enable flight and lock their possition, wait till its done, reteleport, remove flight, and give cake.
    View attachment 10276
     
    dark_hunter likes this.
  29. How would you do this? Specifically, how would you determine if the chunk has been rendered?
     
  30. Offline

    CorrieKay

    uh, if i have something that will prevent them from moving while the chunk loads... Then i dont have to give them flight. A cancelled move event, iirc, would prevent falling.

    technically, it would only matter serverside, so just check if the chunk is loaded. If the chunk isnt rendered clientside, the player will bounce around in midair till it does (the client doesnt have a block under them, so it tries to fall, sending a move packet to the server, which sends back a NO U packet, all, WTF BRO you cant fall THROUGH A BLOCK.) However, if the player is in an unloaded chunk, theres no block SERVERside either, so the server would allow it, which is why my players are suffocating, and falling into the void...
     
Thread Status:
Not open for further replies.

Share This Page