Way to get a reference to the default world?

Discussion in 'Plugin Development' started by capsup, Mar 4, 2011.

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

    capsup

    Okay. So I'm making this plugin where it's possible to make the compass point to a bunch of bookmarks you make yourself. Doing that, I am going to use sqlite to save all these various bookmarks. Okay, so that's all done and stuff. My problem is to retrieve a reference to the world by the name that I have saved in the sqlite database, because creating a new location means I have to give it a reference to the world, and the obvious x,y,z. Thing is I use my own class, SqliteManager to do all the sqlite stuff. However, this class does not have access to the getServer() function in any way, so I can't do the whole getServer().getWorld("world") thing. And therefore I cannot just return a HashMap<String, Location> back to the calling function from within the plugin. So my only solution as I currently see it, is to create a custom Location class and then do the whole thing in there. Could anybody help me out and tell me if there is any smarter way to do this?
     
  2. Offline

    Cheesier

    You can do this by making a variable in the main file public, and then get it.

    If this is part of the main file, Lets call it Main.java
    Code:
    public static Plugin plugin;
    
    onEnable() {
        plugin = this;
    }
    Then from another file, lets say SqliteManager.java
    Code:
    Main.plugin.getServer().getWorld()....
    Hopefully you get my point :)

    Just a tip the next time you write something, don't write it as a wall please :)
     
  3. Offline

    eisental

    You could pass the server reference as an argument to the function you're calling or store a reference to your JavaPlugin or Server in the SqliteManager class. Then you can do plugin.getServer().getWorld("world") or server.getWorld("world").
     
  4. Offline

    capsup

    That would only work if the SqliteManager is a class object that I have to instantiate. Which is not the case. I only use it as a library.
    --- merged: Mar 4, 2011 7:49 PM ---
    Thanks. Passing the server reference as an argument is probably what I'll start to do for now until I find a prettier way.
     
  5. Offline

    Cheesier

    This is not true, the variable plugin is static :)
    I use it in a simular purpose.
     
  6. Offline

    capsup

    Haha, you're totally right. I'm so glad I was wrong for once. :) Works wonderfully. Thanks alot for your help.
     
  7. Offline

    Nohup

    Per the Bukkit multiworld announcement and subsequent threads, getWorlds().get(0) is guaranteed to be the default world.
     
  8. Offline

    Cheesier

    Glad I can help :)
     
Thread Status:
Not open for further replies.

Share This Page