Help with getWorld()

Discussion in 'Plugin Development' started by Raz, Jun 19, 2011.

Thread Status:
Not open for further replies.
  1. Code:
                List worlds = server.getWorlds();
                for(int i = 1;  i < worlds.size(); i++){
                String world = worlds.get(i).toString();
                String wn = server.getWorld(world).getName();
                String we = server.getWorld(world).getEnvironment().name();
    //Do stuffs with strings wn & we
    } 
    So, This code is **** up worldwarp 2.0.
    Gives me NullPointerException at the line String wn = server.... (4:th line)
    Anyone see's whats wrong? I can't and eclipse gives me no errors. builds without warnings
     
  2. String world = worlds.get(i).toString();
    You get the world as an World-object and then convert it to String. First of all, this and the following line is not necessary, because server.getWorlds() already gives you World-objects.

    BTW, you should add a generic to the List-declaration at the first line
    List<World> worlds = server.getWorlds();

    world.get(i) already returns your World and you can call stuff like getName() and getEnvironment().

    Umm, I explained kinda messy, but I hope I helped ;)
     
  3. Offline

    Brain

    This might help:
    PHP:
    // get list of worlds
    final List<Worldworlds server.getWorlds();

    // go through the complete list of worlds, one at a time and *do stuff*
    final Iterator<Worlditer worlds.iterator();
    while(
    iter.hasNext()) {
        
    // get next world
        
    final World world iter.next();

        
    // get world name
        
    final String wn world.getName();

        
    // get world environment
        
    final Environment we world.getEnvironment();

        
    // Do stuffs with wn & we
    }// end while 
    Remark: I hate the post add/edit functionality of this forum. Click somewhere else in the browser window and everything is gone. What happened to plain old <textarea> without all the fancy crap?
     
  4. You can still click the "More Options..."-button to have it displayed in its own window. And the textarea mode for plain text can be reached with the [​IMG]-symbol (top right corner of the editor).


    @Raz
    I just noticed you started your loop with int i = 1 in the OP. Why not 0?
     
    Brain likes this.
  5. Offline

    Brain

    Ahh, thanks a lot, Bone008, you just made my life a lot easier. I had to type my previous post three times which got me a little p-o'd.
     
  6. Thanks to booth of you :) Works great now.
    I See my errors clearly right now. I Guess coding to 03:00 in the morning isn't to recommend, atleast not without coffe :p
     
  7. Offline

    badbh222

    Coding till 6am is even better. :D
     
Thread Status:
Not open for further replies.

Share This Page