Solved Problem with Scoreboard

Discussion in 'Plugin Development' started by Elsifo92, Aug 24, 2013.

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


    Hi! I've a problem with the scoreboard on a plugin i'm working on.
    Here's the server log:
    Caused by: java.lang.IllegalStateException: Cannot set scoreboard for invalid CraftPlayer
        at org.bukkit.craftbukkit.v1_6_R2.entity.CraftPlayer.setScoreboard(
        at org.bukkit.command.PluginCommand.execute(
        ... 15 more
    And this is the code which manages the scoreboard:
    1. public class Follower
    2. {
    3. private Player p;
    4. private int rep;
    5. private God god;
    6. private GregorianCalendar lastPrayed;
    7. private GregorianCalendar lastHealed;
    8. private Scoreboard s;
    9. public Follower(Player p, int rep, God god, GregorianCalendar lastPrayed,GregorianCalendar lastHealed)
    10. {
    11. this.p=p;
    12. this.rep=rep;
    13. this.god=god;
    14. this.lastPrayed=lastPrayed;
    15. this.lastHealed=lastHealed;
    16. updateScore();
    17. }
    18. public void updateScore()
    19. {
    20. s=Bukkit.getScoreboardManager().getNewScoreboard();
    21. s.registerNewObjective("Reputazione", "dummy");
    22. Objective o=s.getObjective("Reputazione");
    23. o.setDisplaySlot(DisplaySlot.SIDEBAR);
    24. Score r=o.getScore(p);
    25. r.setScore(Utility.getLevel(rep));
    26. p.setScoreboard(s);
    27. }
    28. public void showScoreboard()
    29. {
    30. p.setScoreboard(s);
    31. }
    32. public void hideScoreboard()
    33. {
    34. p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
    35. }
    36. [...]
    37. }

    Basically: when a player joins the server, under certain conditions, a Follower object is created. At the first login it's all ok, the scoreboard is shown correctly, and so on. But, if the player log out and then log back again, that exception occurs, and I've to stop the server to get things to work again. I'm not getting something, or it's a known problem? Thank you! (BTW sorry for my bad english, i'm not a native speaker...)
  2. Offline


    Moved to correct section.
  3. Offline


    Whoops, sorry :/
  4. Offline



    You need to save it in a config.
  5. Offline


    I solved it.
    For anyone having the same problem: you don't have to delete the reference to the scoreboard, keep it saved in a HashMap for example. Then, when the player logs again, just set that scoreboard. Thanks anyway PropGamer for the answer!
    uyuyuy99 likes this.
Thread Status:
Not open for further replies.

Share This Page