Solved Scoreboard NullPointerException?

Discussion in 'Plugin Development' started by AppleBabies, Jan 17, 2016.

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

    AppleBabies

    Okie dokie, here we go. So, I am working on a new minigame, and for the scoreboard I have set up a class called BoardManager. But when I access it from another class, it will not work. I am wondering why.

    In my Arena.class I have done the following:
    Code:
    private BoardManager bmanager;
    
    
    and then...
    Code:
    public void addPlayer(Player p){
         bmanager.setScoreboard(p);
    }
    //and
    public void removePlayer(Player p){
      bmanager.removeScoreboard(p);
    }
    ...this is my BoardManager.java:
    Code:
    public class BoardManager {
    
        Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
        Objective objective = board.registerNewObjective("score", "dummy");
       
           @SuppressWarnings("deprecation")
        public void setScoreboard(Player p){
               if((board.getObjective("") == null)){
               objective.setDisplaySlot(DisplaySlot.SIDEBAR);
               Score score = objective.getScore(p);
               score.setScore(0);
               p.setScoreboard(board);
               }
           }
          
           public void removeScoreboard(Player p){
               p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
           }
          
           @SuppressWarnings("deprecation")
        public void updateScoreboard(Player p, int amount){
               if (p.getScoreboard().getObjective("score") != null) {
                   Scoreboard b = p.getScoreboard();
                   Objective ob = b.getObjective("score");
                   Score score = ob.getScore(p);
                   score.setScore(score.getScore() + amount);
               }
               else {
                   setScoreboard(p);
               }
              
              
           }
         
       
    }
    Any and all help would be greatly appreciated! :) Thanks!
     
  2. Offline

    Javlin

    Are there any errors at all? Have you tried creating a scoreboard without the class?
     
  3. Offline

    AppleBabies

    @Javlin Here's the error:
    Code:
    17.01 10:23:39 [Server] INFO ... 15 more
    17.01 10:23:39 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at com.themadmc.minigame.CommandManager.onCommand(CommandManager.java:71) ~[?:?]
    17.01 10:23:39 [Server] INFO at com.themadmc.minigame.commands.Join.onCommand(Join.java:41) ~[?:?]
    17.01 10:23:39 [Server] INFO at com.themadmc.minigame.Arena.addPlayer(Arena.java:88) ~[?:?]
    17.01 10:23:39 [Server] INFO Caused by: java.lang.NullPointerException
    17.01 10:23:39 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:536) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:628) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:672) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_65]
    17.01 10:23:39 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_65]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) ~[craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit188.jar:git-Bukkit-53fac9f]
    17.01 10:23:39 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'sp' in plugin ShearPressure v1.0
    17.01 10:23:39 [Server] ERROR null
    I haven't tried putting it in a lone class because I based this off of another scoreboard I made. It's exactly the same. I think it's just having troubles grabbing a player, or it doesn't like the way I passed constructors.
     
  4. Offline

    Javlin

    You should learn to read stacktraces (here).
    There is an NPE somewhere, but I can't tell where because this isn't the entire report it seems.
     
  5. Offline

    AppleBabies

    @Javlin I have read it - but all it leads to is the scoreboard being null. And this is the only report I was given, too. The 15 more... isn't collapsible.
     
  6. Offline

    Javlin

    Realizing this now but:
    do you ever set bmanager to a new BoardManager?
     
  7. Offline

    AppleBabies

    @Javlin Shoot! I did not! Let me do that...

    EDIT: Works! Marking as solved! Thanks!
     
    Last edited: Jan 17, 2016
Thread Status:
Not open for further replies.

Share This Page