Solved can not get SpawnLocation

Discussion in 'Plugin Development' started by spacemoehre, Aug 20, 2014.

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

    spacemoehre

    I can not get the SpawnLocation of world... HELP

    World world = null;
    world = this.getServer().getWorld("world");
    world.setSpawnLocation(0, 100, 0);
    p.teleport(new Location (world,
    world
    .getSpawnLocation() <-- Error: NullPointerException
    .getX(),
    world
    .getSpawnLocation()
    .getY(),
    world
    .getSpawnLocation()
    .getZ()));
     
  2. Safe the location in a variable and set the spawnlocation after this. then use the variable instead of getSpawnLocation(); you should do this anyway to keep your code clean of not needed calls. if you still get a nullpointer exception on this variable, i cant imagine what your server is doing xD
    what i think what is happening is, your world is new loaded, but no player is on it, so no chunk is load, so maybe also no location is load, so every method which returns a location will return null. Maybe the list of all locations is setUp with the first chunkgeneration. that's the only thing i could imagine
     
  3. Offline

    spacemoehre

    I have the feeling that i#m totally doing the wrong stuff^^

    World world = null;
    world = this.getServer().getWorld("world");
    int x = 0;
    int y = 100;
    int z = 0;
    Location loc = new Location(world, x,y,z);
    world.setSpawnLocation(x,y,z); <- NullPointer
    p.teleport(new Location (world,
    world
    .getSpawnLocation()
    .getX(),
    world
    .getSpawnLocation()
    .getY(),
    world
    .getSpawnLocation()
    .getZ()));

    if i missunderstand you, please correct my code^^

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

    Panjab

    Just use this:

    Code:java
    1.  
    2. World world = null;
    3.  
    4. if (Bukkit.getWorld("world") != null) {
    5. world = Bukkit.getWorld("world");
    6.  
    7. world.setSpawnLocation(0, 100, 0);
    8. p.teleport(world.getSpawnLocation());
    9. }


    The only thing I could imagine why you're getting a NullPointerException thrown, is because you dont have a World called "world". Because if you'd do, it would not throw an exception. That is the reason why I've added a Null-Check.
     
  5. Offline

    spacemoehre

    That seems good but my world Bukkit.getWorld("world") seems to be null...
    Because there is no teleport
     
  6. Offline

    Necrodoom

    spacemoehre then you don't have a world called "world"....
     
  7. Offline

    spacemoehre

    but i have ^^ whats going on???
    ok. if i dont have a world called 'world'. how can i create on?
    Or has anybody an example??
     
  8. Offline

    Necrodoom

    spacemoehre are you sure you have a world named that? Paste startup log please.
     
  9. Offline

    spacemoehre

    Screenshot 2014-08-20 19.49.26(2).png
     

    Attached Files:

  10. Offline

    Necrodoom

  11. Offline

    spacemoehre

    what is the startup log?
    i know im beginner
     
  12. Offline

    Necrodoom

  13. Offline

    spacemoehre

    [17:52:52] [Server thread/INFO]: Starting minecraft server version 1.7.9
    [17:52:52] [Server thread/INFO]: Loading properties
    [17:52:52] [Server thread/INFO]: Default game type: SURVIVAL
    [17:52:52] [Server thread/INFO]: Generating keypair
    [17:52:53] [Server thread/INFO]: Starting Minecraft server on *:25565
    [17:52:53] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-1-ga6e0bfd-b3095jnks (MC: 1.7.9) (Implementing API version 1.7.9-R0.3-SNAPSHOT)
    [17:52:53] [Server thread/INFO]: Preparing level "world2"
    [17:52:53] [Server thread/INFO]: Preparing start region for level 0 (Seed: -8376348725945657641)
    [17:52:53] [Server thread/INFO]: Preparing start region for level 1 (Seed: -8376348725945657641)
    [17:52:54] [Server thread/INFO]: Preparing start region for level 2 (Seed: -8376348725945657641)
    [17:52:54] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [17:52:54] [Server thread/INFO]: Done (0,918s)! For help, type "help" or "?"
    [19:39:03] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 5912509ms behind, skipping 118250 tick(s)
    [22:05:42] [Server thread/INFO]: CONSOLE: Stopping the server..
    [22:05:42] [Server thread/INFO]: Stopping server
    [22:05:42] [Server thread/INFO]: Saving players
    [22:05:42] [Server thread/INFO]: Saving worlds
    [22:05:42] [Server thread/INFO]: Saving chunks for level 'world2'/Overworld
    [22:05:42] [Server thread/INFO]: Saving chunks for level 'world2_nether'/Nether
    [22:05:42] [Server thread/INFO]: Saving chunks for level 'world2_the_end'/The End
    [22:05:42] [Thread-4/INFO]: Stopping server
    [22:05:42] [Thread-4/INFO]: Saving players
    [22:05:42] [Thread-4/INFO]: Saving worlds
    [22:05:42] [Thread-4/INFO]: Saving chunks for level 'world2'/Overworld
     
  14. Offline

    Necrodoom

    spacemoehre the world loaded is "world2", " world" is not loaded and thus is null.
     
    bennie3211 likes this.
  15. Offline

    spacemoehre

    how can i load world in the beginn? i want to port my player from world2 to world. i think it is something with the onEnable method...
     
  16. Offline

    Necrodoom

    spacemoehre you will first need to load the world, see createWorld method of server, or multiworld plugin.
     
  17. Offline

    spacemoehre

    ok...

    so that was the problem. i had no worldcreator...
    Solved

    Necrodoom best man ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page