Solved Cannot set scoreboard for invalid CraftPlayer?

Discussion in 'Plugin Development' started by thepaperboy99, Jan 11, 2014.

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

    thepaperboy99

    Hello Bukkit, I randomly get this error when I try to set a scoreboard to a player. When the server starts, I could join for the first time, and everything will work. But if I were to leave and join back, an error happens. Am I doing something wrong here?

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event){
    3. Player player = event.getPlayer();
    4. Scoreboards.getInstance().update(player);
    5. }
    6.  
    7.  
    8. public void update(Player player){
    9. ScoreboardManager manager = Bukkit.getScoreboardManager();
    10. Scoreboard board = manager.getNewScoreboard();
    11. Objective o = board.registerNewObjective(player.getName(), "dummy");
    12. o.setDisplaySlot(DisplaySlot.SIDEBAR);
    13. o.setDisplayName(ChatColor.GOLD + "Stats ");
    14. Score s = o.getScore(Bukkit.getOfflinePlayer("Player"));
    15. s.setScore(1);
    16. player.setScoreboard(board);
    17. }


    Error:

    PHP:
    [15:07:03 INFO]: thepaperboy99[/127.0.0.1:57638logged in with entity id 608 at
    ([world84.0224809874150870.0260.69999998807907)
    [
    15:07:03 ERROR]: Could not pass event PlayerJoinEvent to KitPvP v0.1
    org
    .bukkit.event.EventException
            at org
    .bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va
    :427) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a
    :62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava
    :481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava
    :466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craft
    bukkit
    .jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craft
    bukkit
    .jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit
    .jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused byjava.lang.IllegalStateExceptionCannot set scoreboard for invalid Cr
    aftPlayer
            at org
    .bukkit.craftbukkit.v1_7_R1.entity.CraftPlayer.setScoreboard(Craft
    Player
    .java:1063) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            
    at me.thepaperboy99.kitpvp.Scoreboards.update(Scoreboards.java:33) ~[?:?
    ]
            
    at me.thepaperboy99.kitpvp.KitPVPListener.onPlayerJoin(KitPVPListener.ja
    va
    :18) ~[?:?]
            
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.6.0
    _05
    ]
            
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.6.0
    _05
    ]
            
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .6.0_05
    ]
            
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.6.0_05]
            
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va
    :425) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            ... 
    14 more
    Line 33 is player.setScoreboard(board);

    All help is appreciated, Thanks!
     
  2. Offline

    Superckl1

    If you look at the source for CraftPlayer you'll this see under setScoreboard:

    Code:java
    1. if (playerConnection.isDisconnected()) {
    2. throw new IllegalStateException("Cannot set scoreboard for invalid CraftPlayer");
    3. }
    4.  


    I vaguely remember this problem from some of my other plugins. I'm not entirely sure, but I think PlayerJoinEvent is fired before the Player is set to connected (I might be completely wrong). First, try setting your priority to Monitor, which probably won't work. If that doesn't work, try scheduling the code for one tick after the PlayerJoinEvent.
     
  3. Offline

    thepaperboy99



    Thanks, I figured a scheduler would work half an hour after I posed lol. But thanks anyways. :)
     
Thread Status:
Not open for further replies.

Share This Page