Get world.

Discussion in 'Plugin Development' started by wouter0100, Nov 10, 2011.

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

    wouter0100

    Hey,

    I'm bussy with a plugin for my server, but now.
    I have a World, called world.
    And i'm using this line:
    Code:
    Location location = new Location(null, 347, 68, 234, (float) 92.851685, (float) 12.149901);
    for a NPC, but how can i select the world?
    I have tryed things like:
    Code:
    (World) world = "World";
    Location location = new Location(world, 347, 68, 234, (float) 92.851685, (float) 12.149901);
    but that dont work,

    Thanks!
    Wouter0100
     
  2. Offline

    stelar7

    World world = Bukkit.getServer().getWorld("World");
     
  3. The world name is case-sensitive though.
     
  4. Offline

    wouter0100

    I got the following error:
    With this code:
    Code:
            World world = (net.minecraft.server.World) Bukkit.getServer().getWorld("world");
            Location location = new Location((org.bukkit.World) world, 347, 68, 234, (float) 92.851685, (float) 12.149901);
    line 93 =
    Code:
            NPCManager.spawnNPC("VIP", location, "VIP");
    Thats under the location and world lines.
     
  5. You are not suposed to use the nms World. You got your import wrong.
     
  6. Offline

    wouter0100

    Now the following error:
    Code:
            World world = (World) Bukkit.getServer().getWorld("world");
            Location location = new Location(world, 347, 68, 234, (float) 92.851685, (float) 12.149901);
            NPCManager.spawnNPC("VIP", location, "VIP"); //Line 95
     
  7. I've had problems with Bukkit.getServer().getWorld() returning null. I dont know how to fix it though.
     
  8. Offline

    wouter0100

    -Hiden-, i have changed Bukkit to this, same error.

    I have now:
    Code:
            if(getServer().getWorld("world") != null)
            {
    
                World world = getServer().getWorld("world");
                Location location = new Location(world, 347, 68, 234, (float) 92.851685, (float) 12.149901);
                NPCManager.spawnNPC("VIP", location, "VIP");
    
            }else{
    
                log.severe("VIP NPC NOT SPAWNED!!!!!");
    
            }
            
    But it gives this error:
    Line 98 = NPCManager bla bla.

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

    Father Of Time

    A strong tool for debugging null point exceptions is console printing. try running the following (note: I wrote this in notepad, so it will likely need some slight tweaking to compile):

    Code:
        if(getServer().getWorld("world") != null)
        {
            World world = getServer().getWorld("world");
            log.info( world.toString() );
    
            Location location = new Location(world, 347, 68, 234, (float) 92.851685, (float) 12.149901);
            if( location != null )
                log.info( location.toString() )
    
            else
            log.info( "location variable null" )
    
            // NPCManager.spawnNPC("VIP", location, "VIP");
    
            }else{
    
                log.severe("VIP NPC NOT SPAWNED!!!!!");
    
            }
    
    This is what is causing the console error:

    Code:
    NPCManager.spawnNPC("VIP", location, "VIP");
    But it's not that line of code itself, its that one of the variables that it's being passed is null. Seeing as only one of the three variables being sent to it has the potential of being null we can make a strong assumption that its the location variable that is causing the problem.

    By running the code I provided above we can confirm whether or not the location variable is null, and if it is we can break down the location declaration to identify the problem. Run the above code and post the console output and we can go from there. Good luck!
     
  10. Offline

    krooked590

    if world is not your default world then you will get null. the only way to get around the npe problem is to load the world you that you want before you try to get its name.
    exaple:

    String test = getServer().getWorld("world2").getName();
    System.out.println(test);
    String test2 = getServer().getWorld("world").getName();
    System.out.println(test2);

    the first 2 lines of code will execute because my default world name is world 2. when it tries to call the name of world i will get null. you can load a world name by using WorldCreator.name("world").createWorld();

    if "world" does not exist tho this will create it, if it does exist it will just load it.
    example of it working:

    String test = getServer().getWorld("world2").getName();
    System.out.println(test);
    WorldCreator.name("world").createWorld();
    String test2 = getServer().getWorld("world").getName();
    System.out.println(test2);

    now world should no longer be returning null....hopefully
     
  11. Offline

    wouter0100

    This:
    Code:
    World wereld = this.getServer().getWorld("world");	
    Location locatie = new Location(wereld, 347, 68, 234, (float) 61.03366, (float) 1.3500059);		
    log.info(locatie.getX() + " " + locatie.getY() + " " + locatie.getZ() + " " + locatie.getYaw() + " " + locatie.getPitch() + " " + locatie.getWorld().toString());
    
    is returing this:
    347.0 68.0 234.0 61.03366 1.3500059 CraftWorld{name=world}

    So, it dont returns null.

    This is returning this:
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  12. Offline

    Evenprime

    Well, obviously "NPCManager" is null. Where do you get the value of "NPCManager" from?
     
  13. Offline

    wouter0100

    Yea, It works now good ;p.
    I dont have created ever the new NPCManager(this); :p.
     
Thread Status:
Not open for further replies.

Share This Page