Solved Issue with putting player name and scoreboard into hashmap.

Discussion in 'Plugin Development' started by nick6899, Oct 21, 2015.

Thread Status:
Not open for further replies.
  1. I have been trying to put a player name and a scoreboard into a hashmap, and when i do i am confronted with an NPE. i am very agitated at this point.

    putting name into HashMap:

    Code:
    @EventHandler
          public void onJoin(PlayerJoinEvent e){
              Player player = e.getPlayer(); //Save the player
              String name = player.getName();
      
           
              ScoreboardManager manager = Bukkit.getScoreboardManager();
              Scoreboard board = manager.getNewScoreboard();
              Objective objective = board.registerNewObjective("RankUp Info", "dummy");
              objective.setDisplaySlot(DisplaySlot.SIDEBAR);
              objective.setDisplayName(ChatColor.AQUA + "Simple Society");
              Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Current Rank: " + plugin.perms.getPrimaryGroup(player)));
              score.setScore(0);
              player.setScoreboard(board);
            boards.put(name, board);
          }
    NPE:
    Code:
    21.10 18:03:10 [Server] INFO ... 14 more
    21.10 18:03:10 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
    21.10 18:03:10 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
    21.10 18:03:10 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_40]
    21.10 18:03:10 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
    21.10 18:03:10 [Server] INFO at Listeners.JoinListener.onJoin(JoinListener.java:41) ~[?:?]
    21.10 18:03:10 [Server] INFO Caused by: java.lang.NullPointerException
    21.10 18:03:10 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:813) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java:148) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:157) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:298) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.7.jar:git-Spigot-b2c2c63-a3cb1bc]
    21.10 18:03:10 [Server] INFO org.bukkit.event.EventException
     
  2. Offline

    RoboticPlayer

    @nick6899 You marked this as solved. Could you provide how you solved it for future reference of anyone wanting to do the same thing?
     
  3. Offline

    adam753

  4. Lol, Adam is right. I feel completely stupid.
     
Thread Status:
Not open for further replies.

Share This Page