Array becoming null

Discussion in 'Spigot Plugin Development' started by InfiniteIV, May 4, 2015.

  1. Code (Text):
        public static void startGame(){
            Location[] tS = {
            new Location( Bukkit.getWorld("Teweran"),119.5,91.5,-1189.5),
            new Location( Bukkit.getWorld("Teweran"),118.5,91.5,-1184.5),
            new Location( Bukkit.getWorld("Teweran"),116.5,91.5,-1179.5),
            new Location( Bukkit.getWorld("Teweran"),113.5,91.5,-1175.5),
            new Location( Bukkit.getWorld("Teweran"),109.5,91.5,-1172.5),
            new Location( Bukkit.getWorld("Teweran"),104.5,91.5,-1170.5),
            new Location( Bukkit.getWorld("Teweran"),99.5,91.5,-1169.5),
            new Location( Bukkit.getWorld("Teweran"),94.5,91.5,-1170.5),
            new Location( Bukkit.getWorld("Teweran"),89.5,91.5,-1172.5),
            new Location( Bukkit.getWorld("Teweran"),85.5,91.5,-1175.5),
            new Location( Bukkit.getWorld("Teweran"),82.5,91.5,-1179.5),
            new Location( Bukkit.getWorld("Teweran"),80.5,91.5,-1184.5),
            new Location( Bukkit.getWorld("Teweran"),79.5,91.5,-1189.5),
            new Location( Bukkit.getWorld("Teweran"),80.5,91.5,-1194.5),
            new Location( Bukkit.getWorld("Teweran"),82.5,91.5,-1199.5),
            new Location( Bukkit.getWorld("Teweran"),85.5,91.5,-1203.5),
            new Location( Bukkit.getWorld("Teweran"),89.5,91.5,-1206.5),
            new Location( Bukkit.getWorld("Teweran"),94.5,91.5,-1208.5),
            new Location( Bukkit.getWorld("Teweran"),99.5,91.5,-1209.5),
            new Location( Bukkit.getWorld("Teweran"),104.5,91.5,-1208.5),
            new Location( Bukkit.getWorld("Teweran"),109.5,91.5,-1206.5),
            new Location( Bukkit.getWorld("Teweran"),113.5,91.5,-1203.5),
            new Location( Bukkit.getWorld("Teweran"),116.5,91.5,-1199.5),
            new Location( Bukkit.getWorld("Teweran"),118.5,91.5,-1194.5)
            };
            Arena ar  = Voting.getFinalAnswer();
            int i = 0;
            arena  = ar;
            for(Player p: Bukkit.getOnlinePlayers()){
                if(!(alive.contains(p.getName()))){
                    alive.add(p.getName());
                }
                if(i==24){
                    i= 0;
                }
                p.teleport(tS[i]);
                i++;
    }
    }
    The array was returning null when it belonged to the map {This is the only map for now} so I decided to try to debug it and found that it wasn't the arena that was turning it to null, it just was null itself. The exception happens at p.teleport(tS);
    Code (Text):
    [09:48:54 WARN]: [SRSG] Task #6 for SRSG v1.0.4 generated an exception
    java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer.teleport(CraftPlayer.java:464) ~[spigot.jar:git-Spigot-2ec6f06-7722428]
            at org.bukkit.craftbukkit.v1_8_R2.entity.CraftEntity.teleport(CraftEntity.java:223) ~[spigot.jar:git-Spigot-2ec6f06-7722428]
            at net.mcsro.SG.utils.GameManager.startGame(GameManager.java:34) ~[?:?]
            at net.mcsro.SG.utils.Countdown.run(Countdown.java:17) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot.jar:git-Spigot-2ec6f06-7722428]
            at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot.jar:git-Spigot-2ec6f06-7722428]
            at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:720) [spigot.jar:git-Spigot-2ec6f06-7722428]
            at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-2ec6f06-7722428]
            at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-2ec6f06-7722428]
            at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-2ec6f06-7722428]
            at java.lang.Thread.run(Thread.java:745) [?:1.7.0_75]
     
    GameManager 34 is p.teleport
    and Countdown 17 is GameManager.startGame();
     
    #1 InfiniteIV, May 4, 2015
    Last edited: May 4, 2015
  2. Try checking if Bukkit.getWorld("Teweran") returns null also as it may be possible that the world does not exist or is not recognized by the server.
     
  3. Yeah, Teweran is null, just checked. I have no idea why it is though, I've added the world to SP to add the spawns and that worked fine but when I add the folder to the server it doesn't work.
     
  4. I think it's because spigot does not support multiple worlds. Try loading you server with Multiverse. It's a plugin that adds support for multiple worlds.
     
  5. or try loading worlds by using bukkit.yml: http://wiki.bukkit.org/Bukkit.yml#.2AOPTIONAL.2A_worlds
     
  6. gigosaurus

    Supporter

    Of course spigot supports multiple worlds - how else would Multiverse (a bukkit/spigot plugin) create them? :p

    Code (Java):
    Bukkit.createWorld(WorldCreator.name("world"));
    should do the trick.
     
    #6 gigosaurus, May 4, 2015
    Last edited: May 4, 2015
  7. I've used that but it still is null. I've tried loading the world into a server with Multiverse aswell but everytime I tried importing the world, it would fail.

    EDIT: I just tried it onto another world, it worked so after I imported it, I removed the old world folder in the SG server's files and moved it there, the map is still null.
     
  8. Sorry, I thought Multiverse played around with the stuff :p

    I think a lot of debugging is due.
     
  9. gigosaurus

    Supporter

    Or just load the world like how I said... It even eliminates the need for MultiVerse (unless you have some other purpose for it).
     
  10. I just installed multiverse on the server, it took me to Teweran but my lugin still says it is null.
    @gigosaurus wouldn't that create the world instead?
    EDIT: I just tried yours gigo, it still didn't work, Teweran is null.
     
    #10 InfiniteIV, May 4, 2015
    Last edited: May 4, 2015
  11. gigosaurus

    Supporter

    It creates the world inside Bukkit from the already existing world files (or creates the world files if they don't already exist).
    Just make sure you have the world in the correct directory.
    [​IMG]
     
    #11 gigosaurus, May 4, 2015
    Last edited: May 4, 2015
  12. After the Bukkit.createWorld Tweweran was not null but when I called I tried to teleport the players to the locations it was null.
    [​IMG]
     
  13. set it as an default world?
     
  14. gigosaurus

    Supporter

    Are you creating the location array after you've created the world? If not then that's your problem.
     
  15. The default world is the lobby world, that's an arena.
    Just fixed it, that was the problem, I defined the arenas at the start of the on enable and created Teweran at the end, thanks!