Score Board NPE Issue :(

Discussion in 'Plugin Development' started by HackintoshMan, Apr 19, 2013.

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

    HackintoshMan

    I have spen a while trying to switch over to the new scoreboard api in my plugin. BUT, it is not off to a god start. Whenever I load up the plugin for the first time, I get the following NPE…

    Code:
    19:04:45 [SEVERE] Could not load 'plugins/MCFTF2.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_5_R2.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_5_R2.CraftServer.<init>(CraftServer.java:217)
        at net.minecraft.server.v1_5_R2.PlayerList.<init>(PlayerList.java:55)
        at net.minecraft.server.v1_5_R2.DedicatedPlayerList.<init>(SourceFile:11)
        at net.minecraft.server.v1_5_R2.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:381)
        at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at com.hackintoshman.mcftf2.MCFTF2.<init>(MCFTF2.java:34)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178)
        ... 9 more
    
    With the following code:

    Code:java
    1. package com.hackintoshman.mcftf2;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.EventPriority;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.PlayerDeathEvent;
    12. import org.bukkit.event.player.PlayerJoinEvent;
    13. import org.bukkit.event.player.PlayerQuitEvent;
    14. import org.bukkit.event.player.PlayerRespawnEvent;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17. import org.bukkit.scoreboard.Scoreboard;
    18. import org.bukkit.scoreboard.ScoreboardManager;
    19. import org.bukkit.scoreboard.Team;
    20.  
    21. import com.hackintoshman.mcftf2.commands.CommandKD;
    22. import com.hackintoshman.mcftf2.commands.CommandSetPoints;
    23. import com.hackintoshman.mcftf2.commands.CommandTeam;
    24.  
    25. public class MCFTF2 extends JavaPlugin implements Listener {
    26.  
    27. public String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[MCFTF2] "
    28. + ChatColor.AQUA;
    29. public int redScore = 0;
    30. public int blueScore = 0;
    31. public int gameTime;
    32. public boolean isCTF;
    33. public ScoreboardManager manager = Bukkit.getScoreboardManager();
    34. public Scoreboard board = manager.getNewScoreboard();
    35. public Team red = board.registerNewTeam("Red");
    36. public Team blue = board.registerNewTeam("Blue");
    37.  
    38. @Override
    39. public void onEnable() {
    40.  
    41. System.out.println("[MCFTF2] Loading the scoreboard...");
    42. scoreBoardHandler();
    43.  
    44. System.out.println("[MCFTF2] Loading config...");
    45. loadConfig();
    46.  
    47. getCommand("kd").setExecutor(new CommandKD(this));
    48. getCommand("setpoint").setExecutor(new CommandSetPoints(this));
    49. getCommand("team").setExecutor(new CommandTeam(this));
    50.  
    51. getServer().getPluginManager().registerEvents(new CaptureTheFlagHandler(this), this);
    52. getServer().getPluginManager().registerEvents(this, this);
    53. }
    54.  
    55. @Override
    56. public void onDisable() {
    57.  
    58. System.out.println("[MCFTF2] MCFTF2 succesfully disabled!");
    59. System.out.println("[MCFTF2] Thanks for using!");
    60. saveConfig();
    61. }


    I have no clue as to why this is happening(It is null on lion 34 I know THAT) and how to fix it. I have tried to register(if that is what its called) in the onEnable.
     
  2. Offline

    Tirelessly

    Initialize the variables on lines 33 and 34 in your onEnable.
     
  3. Offline

    Tzeentchful

    You are setting the scoreboard manager object before the scoreboard manager for the server has been initialized.
    Try setting the scoreboard manager and scoreboard in your onEnable.
     
  4. Offline

    HackintoshMan

    Like this?

    In the class :

    Code:java
    1. public ScoreboardManager manager;
    2. public Scoreboard board;
    3. public Team red;
    4. public Team blue;


    and in the onEnable:

    Code:java
    1. manager = Bukkit.getScoreboardManager();
    2. board = manager.getNewScoreboard();
    3. board.registerNewTeam("Red");
    4. board.registerNewTeam("Blue");
     
  5. Offline

    Tzeentchful

    Yep that should work.
     
  6. Offline

    HackintoshMan

    I have fixed the issue, but I am having a hard time seeing if a player is on a team or not…
     
  7. Offline

    kreashenz

    Put heaps of spaces on each side of the Red so it looks like
    Code:java
    1. board.registerNewTeam(" Red ");
     
Thread Status:
Not open for further replies.

Share This Page