World Generation Error

Discussion in 'Plugin Development' started by Ivan, Jan 5, 2013.

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

    Ivan

    Code:java
    1.  
    2. @Override
    3. public void onEnable(){
    4. WorldCreator gamesmap = new WorldCreator("world");
    5. Random random = new Random();
    6. gamesmap.seed(random.nextLong());
    7. gamesmap.environment(Environment.NORMAL);
    8. gamesmap.generateStructures(true);
    9. gamesmap.createWorld();
    10.  

    This is my code, my plugin loads before world generation, and I'm getting a nullpointer exception at gamesmap.createWorld(); I want to randomize the world on restart any ideas? :L
     
  2. Offline

    caseif

    I'm not quite sure of why you're getting this error, but maybe you could try using gamesmap.seed() (without args)?
     
  3. Offline

    Ivan

    That just returns the seed :L. I think its because the server didn't load fully yet
     
  4. Offline

    caseif

    It may be because you're trying to overwrite the default world. Try naming the world to something else. Additionally, you need may need to replace the line giving you the error with
    Code:java
    1. this.getServer().createWorld(gamesmap);

    Let me know if either of these solutions work. :D
     
  5. Offline

    Ivan

  6. Offline

    caseif

    Did you replace the problem line with the one I posted?
     
  7. Offline

    Ivan

    Yup I tried both
     
  8. Offline

    hockeygoalie5

    I haven't used these classes before, but the exception is called by the method that gets the server's default gamemode. Maybe you need to pass more options to gamesmap?
     
  9. Offline

    caseif

    Here's some code that does this same thing:
    Code:java
    1. WorldCreator creator = new WorldCreator("world_nightmare");
    2. creator.environment(World.Environment.THE_END);
    3. creator.generateStructures(false);
    4. creator.seed();
    5. creator.createWorld();
    6. this.world = this.getServer().createWorld(creator);

    I have no idea why your code doesn't work, but maybe try replacing it with this, and seeing if there's a difference.

    Additionally, I'm pretty sure that if you don't define a seed, it will default to a random one.
     
  10. Offline

    fireblast709

    He creates a WorldCreator, which internally tries to get the default gamemode of the world. But the world is not yet loaded, so the list does not have index 0 at that moment.

    1. Don't load your plugin before the world loads
    2. Creating a WorldCreator for "world" would just return the default world
     
Thread Status:
Not open for further replies.

Share This Page