How to get the current World?

Discussion in 'Plugin Development' started by Guildejo, Apr 9, 2012.

Thread Status:
Not open for further replies.
  1. Hey,
    hope someone can help me with this problem...
    I try to get the current world while enabling my plugin, but i can't find any function that provides the worldname or a world object.

    So, how do i get the world that's currently loaded on the server? Without having e.g. a player sending a command or something?

    Hope you understand what i mean and can help me :)

    Thanks in advance!
     
  2. Thanks for your reply, but i want to get the current world without knowing its name!
    What i need is a function like Player.getWorld(), but without having a player object ;)

    Hope you can help me!
     
  3. Offline

    Iron_Crystal

    Do you have a location you are working with? you could do something like Entity.getLocation and the Location.getWorld(). You could also do a Block.getLocation and then the world, or whatever you are working with/.
     
  4. Mhh, i'll better explain what i wanna do, maybe someone's got a better idea...^^

    I save several information in the config,yml like for example locations(x,y and z coords).
    And these information should be world exclusive...so i wanted to save them somehow like that:
    Code:
    path = "areas." + worldName + "." + nameOfLocation + ".x" = 123;
    Is there a better way saving these information?
     
  5. Well, without a player or location, there is no 'current' world. There are three worlds running simultaneously right out of the bat.
     
  6. Offline

    Jobi

    String worldName = player.getLocation().getWorld().getName();
    nameOfLocation is something you already have as a variable, right?

    Edit: Kumpelblase2 is right, you need a player, whos world you want to get
     
  7. But as i said in the first post... i dont have a player object....
     
  8. Then you probably need to store it somewhere at the point where you still have a player or location.
     
  9. Offline

    Jobi

    and which "current" world do you need? Nether, normal, Ender? the plugin has to know what world you mean
     
  10. I need the normal "current world"
     
  11. Offline

    Jobi

    the "world"? And what do you mean with current?
     
  12. It is possible get all normal worlds, but as I said, there's no current one. To get those normal worlds you can use the method that I mentioned earlier and check the environment of each world if it's the normal environment.
     
  13. Arg!
    I failed!
    Jobi, you got me to the right solution!I thought that Bukkit.getWorlds() would provide ALL worlds saved on the server, but it only gets me the ones which are currently loaded (included the nether and the end).

    Sry for taking your time, and thanks to Jobi ;)
     
  14. Offline

    Jobi

    no problem [leaf]
     
Thread Status:
Not open for further replies.

Share This Page