onWorldLoaded

Discussion in 'Plugin Development' started by DiddiZ, Mar 17, 2011.

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

    DiddiZ

    I've a problem with the onWorldLoaded hook. It seems never to be called:
    Code:
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.WORLD_LOADED, new AnyRegWorldListener(), Event.Priority.Monitor, this);
    Code:
        private class AnyRegWorldListener extends WorldListener
        {
            public void onWorldLoaded(WorldEvent event) {
                log.info("[AnyReg] World listener heard something");
            }
        }
    Other hooks work fine.
     
  2. Offline

    Edward Hand

    You are correct. It is never called anywhere in the code (at least in the version I have). It must not be implemented yet. (There are a fair few hooks that aren't implemented yet).
     
  3. Offline

    DiddiZ

    Hm, I don't see a todo note in the bukkit sourcode or the javadocs.
    Then getServer().getWorlds will have to work, until the hook is ready.
     
  4. Offline

    Drakia

    The hook works fine for me, I however implemented it as such:
    Code:
    private final wListener worldListener = new wListener();
    pm.registerEvent(Event.Type.WORLD_LOADED, worldListener, Priority.Normal, this);
    
    Code:
        private class wListener extends WorldListener {
        	@Override
        	public void onWorldLoaded(WorldEvent event) {
        		World w = event.getWorld();
        		// We have to make sure the world is actually loaded. This gets called twice for some reason.
        		if (w.getBlockAt(w.getSpawnLocation()).getWorld() != null) {
        			Portal.loadAllGates(w);
        		}
        	}
        }
    The event is called in https://github.com/Bukkit/CraftBukk.../java/org/bukkit/craftbukkit/CraftServer.java on line 335
     
  5. Offline

    DiddiZ

    Uh, tried the same and got nothing.
    Is the hook fired when loading a world (at server start, when the first player connects) or when creating a new one?
     
  6. Offline

    Drakia

    The main world is loaded before any plugins are loaded, so it doesn't fire the event. The event is only fired when a plugin such as MultiVerse creates a world. If you want to make sure to catch all past and future worlds, on plugin startup loop through getWorlds(), then have a hook for onWorldLoaded() that does stuff for any world loaded after that point (Via plugin)
     
  7. Offline

    DiddiZ

    Ah, thanks.
    That makes sense.
    But the "Loaded world: world" message when the first player joins is pretty useless then, or?
     
  8. Offline

    Drakia

    That is one of your plugins causing that, the core Bukkit server doesn't say anything about a world being loaded for me on first connect.
    This is the output on my server when I first start up and connect: http://pastebin.com/fQt8CmMj
     
  9. Offline

    DiddiZ

    I think it's essentials.
     
  10. Offline

    Drakia

    Most likely, it's probably Essentials "loading" for that world, not the world itself loading.
     
Thread Status:
Not open for further replies.

Share This Page