problem with getting worlds

Discussion in 'Plugin Development' started by Abrupt, Feb 19, 2011.

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

    Abrupt

    I've been using this for a while because I haven't been able to do it without a player:
    Code:
    player.getWorld();
    but I've noticed that I could do it without needing a player, like such:
    Code:
    plugin.getServer().getWorld("world");
    whereas plugin is an instance of my main class (which extends JavaPlugin).

    javadoc page about getServer().getWorld():
    http://javadoc.lukegb.com/BukkitJD/...t/CraftServer.html#getWorld(java.lang.String)

    my problem is that I get a null pointer exception whenever I try to use this, and my world folder is called "world" (it's the default one when the server loads). what am I doing wrong?
     
  2. Offline

    Edward Hand

    how about using:

    Code:
    plugin.getServer().getWorlds().get(n)
    (where n is 0 for your first world, 1 for your second world etc)
     
  3. Offline

    Abrupt

    Code:
    plugin.getServer().getWorlds().get(0)
    gives me the same null pointer exception error.
     
  4. Offline

    Edward Hand

    Any possibility you could post the exact error as well as you're code (or the relevant parts at least)?
     
  5. Offline

    Abrupt

    Here's the full error message:
    I'm getting the world to use alongside NpcSpawner lib, more specifically the SpawnBasicHumanNpc(String, String, String, World, double, double, double, float, float) function.

    Like I've said earlier, it was working before when I used a player to get the world from, so SpawnBasicHumanNpc is not the problem.

    Here's the relevant code, where line 63 has double stars to symbolize it:
    Code:
    public class NPC {
    	public static WoM plugin;
    
    	public NPC(WoM instance) {
    		plugin = instance;
    	}
    
    	public static void spawn(String id) {
    		File file = new File(WoM.npcpath + id + ".dat");
    **		BasicHumanNpc npc = NpcSpawner.SpawnBasicHumanNpc(id, KVFile.getValue("color", file) + KVFile.getValue("name", file), plugin.getServer().getWorlds().get(0), Double.parseDouble(KVFile.getValue("X", file)), Double.parseDouble(KVFile.getValue("Y", file)), Double.parseDouble(KVFile.getValue("Z", file)), Float.parseFloat(KVFile.getValue("Yaw", file)), Float.parseFloat(KVFile.getValue("Pitch", file)));
    		HumanNPCList.put(id, npc);
    	}
    KVFile is a class I've made that uses the Properties functions from java.util.Properties
     
Thread Status:
Not open for further replies.

Share This Page