0

I am trying to use the method getWorld to get the world of a string, but every time, no matter what string I input, null is returned. Here is an example of what I have tried:

World world = server.getWorld("world");

As documented here it states that the method would return null if the world does not exist, however I have made sure that my world name is world. I've googled around too for a solution, but no luck.

Alex
  • 361
  • 1
  • 4
  • 15
  • Your code looks great! Maybe its an issue with Bukkit API, or perhaps you are building for a version other than 1.6.4-R2? This is all i can think of at the moment, except maybe its case sensitive. – Drifter64 Jan 06 '14 at 23:35
  • 1
    Try using the `getWorlds()` method to see all available worlds. There is a chance that it's in the wrong directory maybe. – Obicere Jan 06 '14 at 23:37
  • @Drifter64 Thanks! I am using the latest recommended build for 1.6.4 so there shouldn't be any problems there. I Suppose I'll fill out a bug report unless someone else thinks I'm doing something wrong. – Alex Jan 06 '14 at 23:45
  • @Obicere that method does work for me and I can see a list of loaded worlds with it, which opens up a viable temporary solution until this is fixed. I'll probably write my own method to check against the `World`s in that list. Thanks for the input. – Alex Jan 06 '14 at 23:50
  • @Alex so that's definitely a bug in the client. Then again, it might have something to do with the word choice for the name, I truly don't know. Hopefully this gets resolved soon :) – Obicere Jan 06 '14 at 23:54
  • For anyone else looking `getWorlds()[0]` will usually return your default world, though `Bukkit.getWorld(worldName)` is preferable. Alternatively, get the world from a player instance using `player.getWorld()` if you know the player is in that world. – Slate Jan 23 '14 at 13:39

1 Answers1

2

If you use getServer().getWorld(), it will return null every time. You need to get it from Bukkit itself. It's in the API twice, but only one is working. use Bukkit.getWorld() and it will work just fine.

David
  • 704
  • 1
  • 6
  • 13
  • I don't think that would make a difference, since it doesn't return `null` for me every time. Do you have any references to back up your claim? – clabe45 Oct 08 '17 at 14:24