Solved Teleporting player to a different world, No APIs

Discussion in 'Plugin Development' started by jbman223, Aug 26, 2012.

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

    jbman223

    How would I go about teleporting a player to a different world without API's? I know you are probably thinking this is simple stuff. But the world is not in the current world list. Here is the list of worlds Bukkit recognizes:

    world
    world_nether
    world_the_end

    But i want to teleport a player to the world arena, however whenever I try to, I get a null pointer exception which means that the world is not in Bukkit's list of worlds.


    Error and most recent code: http://forums.bukkit.org/posts/1291687/
     
  2. Offline

    Sabersamus

    World world = Bukkit.getWorld("arena");
    if(world == null){
    WorldCreator creator = new WorldCreator("arena");
    creator.environment(World.Environment.NORMAL);
    creator.generateStructures(true);
    world = creator.createWorld();
    }

    player.teleport(world.getSpawnLocation());
     
  3. Offline

    jbman223


    The world is created, though.
     
  4. Offline

    Darq

    jbman223 Bukkit doesn't have a list of worlds it 'recognizes'.
    Bukkit.getWorld(String worldName); returns the world by that name if it exists.
    or, Bukkit.getWorlds(); Returns a List of the worlds on the server.
     
  5. Offline

    jbman223


    The world that I want isnt on the list, and Bukkit clearly does not know where to get it because it gives me a NUllPointerException when I try to teleport somebody there.
     
  6. Offline

    Darq

    Then the world isn't loaded on the server you're trying to do this with.

    To prevent the NPE:
    Code:
    World w = Bukkit.getWorld("arena");
    if (w == null) {
        //World wasn't found on the server, perhaps log it?
        return;
    } else {
        //Oh boy! It was found. That means you can teleport players to it now.
    }
    
     
  7. Offline

    jbman223


    I understand that the world isn't loaded, how would i load it?
    Here is my code, look at this thread that I made previously before I know what was causing the NPE:
    http://forums.bukkit.org/posts/1291687/
     
  8. Bukkit.createWorld()
    You can just search how to use createWorld() if you can't figure it out, I'm sure it's been discussed before :)
     
  9. Offline

    jbman223

    Its still not working.
     
  10. That explains everything :p
     
  11. Offline

    jbman223

    Yes, but it still doesn't work. Thank you so much for your help, though.
     
  12. Offline

    lx3krypticx

    You need to explain what isn't working. So we can actually help.
     
  13. Offline

    jbman223

    I did explain what isn't working. If you read the first post, I said that whenever I try to tp the player to a different world the world gives me a NPE.
     
  14. Offline

    Sabersamus

    That still doesn't tell us whats wrong, we need 2 things. A.) The Error. B.) The most recent code.
     
  15. Offline

    jbman223

    Error and most recent code: http://forums.bukkit.org/posts/1291687/
     
  16. You didn't use createWorld() properly if getWorld() still returns null.

    Also, you should just use Bukkit.createWorld() *instead* of getWorld() if you're sure the world exists... or you want it to be created if it does not, so it will always return a world.
    Like the description said, if the world is already loaded, createWorld() just acts like getWorld().
     
  17. Offline

    Supertt007

    Sabersamus here just perfectly solved your problem on the second post. The reason you are getting an NPE is because the arena world isn't loaded. That's why you need to use the code above to check and load it
     
    Sabersamus likes this.
  18. Offline

    shinobuattack

    Bumping... I am having a similar issue except I am not getting a null pointer exception and Bukkit does know that my generated world exists. If you could help me out, much appreciated :)
     
  19. Offline

    Sabersamus

    Well, considering we don't know what your problem is, how are we to help you?
     
Thread Status:
Not open for further replies.

Share This Page