Am I doing this correctly?

Discussion in 'Plugin Development' started by Smartloser, Feb 16, 2014.

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

    Smartloser

    Hi guys. I made a scoreboard plugin for factions related, and this code works, but it generates an error in the console. Here's the code + error.

    Code:java
    1.  
    2. public void updateScores()
    3. {
    4. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    5. {
    6. public void run()
    7. {
    8. for (final Player p : Bukkit.getOnlinePlayers())
    9. {
    10.  
    11. if (!b.containsKey(p) || p.getScoreboard().equals(null) || p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).equals(null))
    12. {
    13. createScoreBoard(p);
    14. b.put(p, 1);
    15. }
    16.  
    17. UPlayer uplayer = UPlayer.get(p);
    18. if (p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).equals(null))
    19. {
    20. p.getScoreboard().registerNewObjective(p.getName(), "dummy");
    21. p.setScoreboard(p.getScoreboard());
    22. }
    23. p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).setDisplayName(ChatColor.DARK_AQUA + p.getName());
    24. Score money = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Money"));
    25. Score mpower = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "MyPower"));
    26. Score fpower = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "FactionPower"));
    27. Score territory = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "ClaimedLand"));
    28. territory.setScore(uplayer.getFaction().getLandCount());
    29. if (uplayer.hasFaction() == false)
    30. {
    31. fpower.setScore(0);
    32. }
    33. else
    34. {
    35. fpower.setScore(uplayer.getFaction().getPowerRounded());
    36. }
    37. mpower.setScore(uplayer.getPowerRounded());
    38. money.setScore((int)(economy.getBalance(p.getName())));
    39. p.setScoreboard(p.getScoreboard());
    40.  
    41. }
    42. }
    43. }, 0L, 20L);
    44. }
    45.  


    Code:java
    1.  
    2. public static void createScoreBoard(Player p)
    3. {
    4. Scoreboard board = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
    5. Objective obj = board.registerNewObjective(p.getName(), "dummy");
    6. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    7. p.setScoreboard(board);
    8. }
    9.  



    Error:
    Code:
    17.02 08:50:05 [Server] INFO java.lang.NullPointerException
    17.02 08:50:05 [Server] INFO [08:50:05 WARN]: [FactionBoard] Task #2649 for FactionBoard v1.0 generated an exception
    
    So, my question is, what could return null in the code I wrote above?.
     
  2. Offline

    MrInspector

    If it's working on your server but not on other servers, these might be the reason why,

    * plugin has been compiled in a different java version than the server

    * plugin is using a really different CB build than the server
     
  3. Offline

    Smartloser

    Updated.
     
Thread Status:
Not open for further replies.

Share This Page