[Solved]Dealing with offline players

Discussion in 'Spigot Plugin Development' started by IrChaos, Jul 5, 2015.

  1. Okay... let's try to explain this, maybe someone has a work around I don't. Start with Code:


    Code (Java):

    String owner = new String(ChatColor.stripColor(sign.getLine(3)));
    if(Bukkit.getPlayerExact(owner).isOnline()){
             Bukkit.getPlayerExact(owner).sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "Send This Message!");
              return;  
    }
    return;
    So if "owner" is online, it sends the message. But if not I get this:
    *Note* Line 78 is the if statement here.
    Code (Text):
    [Server thread/ERROR]: Could not pass event InventoryCloseEvent to ChaosShops v0.9.9
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.handleInventoryCloseEvent(CraftEventFactory.java:838) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1384) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.PacketPlayInCloseWindow.a(PacketPlayInCloseWindow.java:18) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.PacketPlayInCloseWindow.a(PacketPlayInCloseWindow.java:1) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:718) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.NullPointerException
        at gq.chaosdev.chaosshops.SOHandler.soldOut(SOHandler.java:78) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.6-R0.1-SNAPSHOT.jar:git-Spigot-ae40327-21681b3]
    It all works and does it's job like it should, other than not understanding if the player is online, this is damn ugly in the console if you know what I mean. lol
    I am sure I am just missing something simple here, Just never had to deal with finding if players are online or not... anyone know what I am missing?
     
  2. you need to check if Bukkit.getPlayerExact(owner) isn't null, instead of checking if it's online.
     
    • Winner Winner x 1
    • Useful Useful x 1
  3. That makes absolutely no logical sense... why would I need to find out if the player is null when I want to know if they are online or not... oh Bukkit.
    Thanks, works perfectly. lol