Bukkit.getWorld() returns null!?!?!

Discussion in 'Plugin Help/Development/Requests' started by arinerron, May 5, 2015.

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

    arinerron

    I've been working on a project and now I am stumped on something. This code isn't working! It's returning null!!! (The Bukkit.getWorld() part!)
    Code:
    World world = Bukkit.getWorld(this.getConfig().getString("Minigame." + MINIGAMES[i].getTitle() + ".lobby.world"));
    When I did printed the world name and it's length to the console (Length so I can tell if there are spaces) I got this:
    Code:
    [Minigame] tester is the world and it's length is 6.
    And for your knowledge, I checked the config for my plugin and yes the path exists. And it is right, the world I am working in is called tester!

    EDIT: Oh yeah and I also tried the this.getServer().getWorld() and it does the same thing! :(
     
  2. Offline

    teej107

    It's obvious that a world does not exist with the name of the String you are passing in the parameters of #getWorld(). Make sure the String you are passing to the method parameters is what you think it is and the world name too.
     
  3. Offline

    arinerron

    I checked for that already, the world exists, infact I am looking at the folder that contains the world and it exists! Could it be some invisible unicode character I don't see or something? Although thanks for responding! Nobody is, and it is kinda urgent! :p
     
  4. Offline

    teej107

    @arinerron Put in debug code. Make sure the String you are getting from the config matches the world name.
     
  5. Offline

    arinerron

    Ok! I put this in:
    Code:
    Bukkit.getWorld(name).equals(tester);
    And it returned true (In other words it says that the world name it is getting from the config file == "tester" which is what the real world name is!) Could it be a bug or something? What am I doing wrong? :\
     
  6. Offline

    teej107

    How do you know it's returning null? Can you post more code?
     
  7. Offline

    arinerron

    Ok! I know it's returning null because I get this error:
    Code:
    [19:22:18 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command ' mingame' in plugin  MiniGame v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:625) ~[craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1058) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:919) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:37) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(SourceFile:9) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_75]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_75]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:656) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:609) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:517) [craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_75]
    Caused by: java.lang.NullPointerException
        at com.arinerron.plugins.bukkit. MiniGame.Main.getMinigame(Main.java:67) ~[?:?]
        at com.arinerron.plugins.bukkit. MiniGame.Main.onCommand(Main.java:131) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.8.jar:git-Bukkit-33d5de3]
        ... 14 more
    
    I get nullpointerexceptions from it. Basically there is a Location that is supposed to load when you run the command. The location is stored in the config file. It retrieves all the info correctly, but it doesn't get the world properly! :(
     
  8. Offline

    1Rogue


    Post the line of code.

    Additionally just because a world is in the folder doesn't mean it's loaded, it either needs to be the defaut world or loaded separately.
     
  9. Offline

    arinerron

    Code:
    int x = this.getConfig().getInt("Minigame." + MINIGAMES[i].getTitle() + ".lobby.x");
                int y = this.getConfig().getInt("Minigame." + MINIGAMES[i].getTitle() + ".lobby.y");
                int z = this.getConfig().getInt("Minigame." + MINIGAMES[i].getTitle() + ".lobby.z");
                World world = Bukkit.getWorld(this.getConfig().getString("Minigame." + MINIGAMES[i].getTitle() + ".lobby.world"));
                this.MINIGAMES[i].setLobby(new Location(world, x, y, z))
    Just so you know, the setLobby isn't the problem. I am absolutely 100% sure, I already thought of that!
     
    Markyroson likes this.
  10. Coordinates must be doubles, not ints
     
    Markyroson likes this.
  11. Offline

    I Al Istannen

    @Hugmanrique The ints should be implicity casted to doubles. I see no error with that.
     
  12. Offline

    Lolmewn

    @arinerron Sure, but is the world actually loaded though?
     
  13. So I have the same problem, I tried to debug it.
    The result was:
    Bukkit.getWorlds() was returning my world, but Bukkit.getWorld("world") wasn't. It isn't a mistype error.
     
  14. Offline

    arinerron

    @Lolmewn @Hugmanrique The world was loaded. It still isn't working! :( I don't know what is wrong. Hugmanrique and I both debugged it but it still doesn't work. Maybe this would work though I'll try it when I get home:
    Code:
    public World getWorld(String world) {
        List<World> worlds = Bukkit.getWorlds();
        int index = 0;
        for(int i = 0; !(world.equals(worlds.get(i).getName())); i++) {
            if(i == worlds.size()) {
                return null;
            }
            index = i;
        }
        return worlds.get(index);
    }
    Oh yeah and to wait until the server loaded all the worlds, I did this:
    Code:
    this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
        public void run() {
            // This code will run directly after the server
            // has finished loading the worlds and the plugins
        } }, 1);
     
    Last edited by a moderator: Jun 30, 2015
  15. Offline

    Boomer

    any possibility that the phantom spaces in the middle of the package and at the start of the command might be throwing the null? Looks odd ..processing command '[SPACE]word' and "..s.bukkit.[SPACE]MiniGame.Main...", might it muddle something? Are the errors thrown up pointing to the exact lines you've pointed at, or are you jumping to assume thats the line.
     
  16. Offline

    Lolmewn

    @arinerron Your for loop was never going to work - when it finds a world with the same name the loop immediately stops. You could use a do-while loop, or just iterate over i instead.
     
  17. Offline

    arinerron

    @Boomer Yes it is the line the error pointed to. The spaces I checked for by doing:
    Code:
    System.out.println("'" + world + "' is the name of the world and its length is '" + world.length() + "'");
    And from that I get:
    Code:
    'tester' is the name of the world and its length is '6'
    Oh yes the spaces were caused when I was replacing the real plugin name so that others don't create the plugin before I finish it... :\ It was an accident...

    @Lolmewn The for loops was a custom substitute of Bukkit.getWorld(String name)...

    It is supposed to stop when it either finds the world it is looking for and returns it, or when it reaches the end of the ArrayList.
     
    Last edited by a moderator: Jun 30, 2015
  18. Offline

    Boomer

    --removed comment

    can you test via hardcoding - sub in "tester" for the getWorld() rather than the config arguments, to make absolutely sure that it is world returning null on getting , rather than the arguments returning null for some stupid reason?
     
    Last edited by a moderator: Jun 30, 2015
  19. I have a fix! Load the world into a variable in the onEnable method, then call that variable. Worked for me
     
  20. Offline

    arinerron

    I just realized the when I call the world name from the config file I just realized that the name is null......

    WOW I just realized the problem, it was that there was a misspelling in the config! Thanks alot for your help guys! :) Hopefully if people see this in the future, maybe they will notice they have the same problem! :) So happy right now... XD

    I don't know how to close a thread, so I'll just leave this one open until a moderator comes or something...
     
    Last edited by a moderator: Jun 30, 2015
  21. Offline

    Boomer

    Strange how that works out that way isn't it. But, as you can see from the processes we went through, the process didn't fail us.
    'tester' is the name of the world and i
    You were right there, staring at it in the face, the right way, exactly at the spot where you knew it would be, but only you could do the comparison to realise your map world was misspelled on the server "tetser" etc :D

    Its things like that that become tricky beasts, because once they've cloaked themselves from the first detection, they've been labled as invisible to the rest of the troubleshooting no matter how much you look at it, until an obscene amount of time passes.
     
Thread Status:
Not open for further replies.

Share This Page