world.getSpawnLocation(), doesn't work correctly?

Discussion in 'Plugin Development' started by Relick, Sep 10, 2011.

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

    Relick

    I have some code that uses getSpawnLocation() on a world to define a location, then teleports the player there. This works for when the player is in a different world (such as X is in aworld an wants to go to bworld, this works), however when the player is in the same world they want to go to (e.g. a go to spawn function) it places them about 30 layers below the actual spawn location. I haven't measured it yet, so it could be an exact number and therefore possibly to work around but is there a better way of doing it?

    Sorry if it's blatantly obvious, I'm not good with the obvious :p
     
  2. Offline

    Timberjaw

    The way the MC server handles spawn points is a bit weird. I've encountered this issue before but never put the time into properly diagnosing it. As a simple workaround, you can use the world.getHighestBlockAt method to get a safer Y for the X/Z location.
     
  3. Offline

    Relick

    Ah thanks, good idea. Works good for now (until some sort of fix is made).

    Doesn't work with the nether unfortunately. Any other work arounds?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  4. Offline

    emericask8ur

    Location spawn = p.getWorld().getSpawnLocation();
    p.teleport(spawn);
     
  5. Offline

    Relick

    What do you think I've been doing? Is there even any other way of doing it.

    I'm asking for help with a bug in the code you just posted. When you go to the same world, it doesn't work. Try it yourself if you don't believe me.
     
  6. Offline

    emericask8ur

    Well i think you might have to have to have a custom set spawn code for this. Because i did spawn in mine and it sended me all the way down xD
     
  7. Offline

    Timberjaw

    You might have to resort to a loop and check for a 2-block high zone of block AIR.

    Example code that probably will not compile:
    Code:
    for(int y = 1; y < 125; y++)
    {
        if(world.getBlockAt(x,y,z).getTypeId() == Block.AIR &&
           world.getBlockAt(x,y+1,z).getTypeId() == Block.AIR)
        {
            // x,y,z is safe
        }
    }
     
  8. Offline

    Relick

    That unfortunately didn't work either D:.
    The nether is so weird.

    I also had a look at some other plugins, and what seems to work for them, would either be unsuitable for my plugin or doesn't work for me :p
     
  9. Offline

    Relick

    Gone through a couple more plugins, even PlgSetSpawn doesn't work :/

    I really hope this is fixed for the next bukkit.
     
  10. Offline

    paalbra

    What do you mean by "does not work"?

    This is how it works as far as i know:
    The getSpawnLocation will get the spawn location(as block location) as set in level.dat. If you teleport to this location you might end up wherever it is set to.. in water, in a cave, in block(=suffocation). To find a safe spawn location i think you will need to do something like Timberjaw suggested.

    A problem(In my eyes) is that bukkit saves each world(normal world, nether and the end) in it's own folder and they therefore have their own level.dat and spawn location. That part makes very little sense to me. A server should only have one spawn .. imo
     
  11. Offline

    bergerkiller

  12. Offline

    paalbra

    Hmm .. tested that one a bit and i'm somewhat able to replicate the issue. Strange stuff, but it doesn't have anything to do with spawn locations (as far as i can see).
     
Thread Status:
Not open for further replies.

Share This Page