Bukkit.getScoreboardManager().getMainScoreboard().getTeams() throws NPE

Discussion in 'Spigot Plugin Development' started by TheRedMelonYT, Mar 24, 2017.

  1. There are definately teams but every time this code is run, it throws NullPointException.
     
  2. Okx

    Okx

    May we see the error, and the code?
     
  3. Error:

    Code (Text):
    [14:23:40] [Server thread/WARN]: [NekoBoard] Task #46 for NekoBoard v1.0.0 generated an exception
    java.lang.NullPointerException
        at com.nekomc.nekoBoard.NekoBoard$1.run(NekoBoard.java:60) ~[?:?]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
    Code:

    Code (Text):
    ScoreboardManager sbm = getServer().getScoreboardManager();

    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

        @Override
        public void run() {
           
            Bukkit.getLogger().info(sbm.getMainScoreboard().getTeams().toString());
           
        }
       
    }, 0L, 1L);
     
  4. WuK

    WuK

    That means, the MainScoreboard or the Teams aren't exists
     
  5. Don't call Server::getScoreboardManager() before onEnable() has been executed (so in onEnable, in a BukkitScheduler::runTask(...) call). Plugins are loaded (iirc) before the worlds are loaded (and, if setup in plugin.yml, also enabled before world load), which means the vanilla scoreboard manager (Minecraft's own) doesn't yet exist - since it's initialised after the worlds are loaded.
     
  6. if(sbm.getMainScoreboard().getTeams() == null) {
    System.out.println("It's null");
    }else{
    System.out.println(sbm.getMainScoreboard().getTeams().toString());
     

Share This Page