Issues with .getOfflinePlayer(UUID id)

Discussion in 'Spigot Plugin Development' started by spookyFalco, Jun 4, 2016.

  1. Im working on an plugin, and for some reason, I cannot get an offlinePlayer object usng the above meathod, or any other one I could think of. Here is some of my code

    Code (Text):

            OfflinePlayer mayor1 = Elections.instance.getServer().getOfflinePlayer(Elections.MAYOR1_UUID);
            OfflinePlayer mayor2 = Elections.instance.getServer().getOfflinePlayer(Elections.MAYOR2_UUID);  
         
            Bukkit.broadcastMessage(mayor1.getName());
            Bukkit.broadcastMessage(mayor2.getName());
    I have already testing to make sure the static UUID objects I am using are not null, so what am I doing wrong?

    Here is the error Im getting
    Code (Text):
    [23:12:59] [Server thread/ERROR]: Could not pass event InventoryClickEvent to Elections v0.0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1851) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:33) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:10) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
        at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_9_R2.command.ColouredConsoleSender.sendMessage(ColouredConsoleSender.java:55) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.broadcast(CraftServer.java:1288) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.broadcastMessage(CraftServer.java:452) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.Bukkit.broadcastMessage(Bukkit.java:295) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at com.blackquartz.elections.gui.MayorGUI.<init>(MayorGUI.java:26) ~[?:?]
        at com.blackquartz.elections.gui.MainGUI$1.onClick(MainGUI.java:30) ~[?:?]
        at com.blackquartz.elections.gui.core.IconMenu.clickMenuItem(IconMenu.java:156) ~[?:?]
        at com.blackquartz.elections.listener.IconMenuListener.onInventoryClick(IconMenuListener.java:42) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        ... 15 more
    [23:13:00] [Server thread/ERROR]: Could not pass event InventoryClickEvent to Elections v0.0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1851) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:33) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PacketPlayInWindowClick.a(SourceFile:10) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
        at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_9_R2.command.ColouredConsoleSender.sendMessage(ColouredConsoleSender.java:55) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.broadcast(CraftServer.java:1288) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.broadcastMessage(CraftServer.java:452) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at org.bukkit.Bukkit.broadcastMessage(Bukkit.java:295) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        at com.blackquartz.elections.gui.MayorGUI.<init>(MayorGUI.java:26) ~[?:?]
        at com.blackquartz.elections.gui.MainGUI$1.onClick(MainGUI.java:30) ~[?:?]
        at com.blackquartz.elections.gui.core.IconMenu.clickMenuItem(IconMenu.java:156) ~[?:?]
        at com.blackquartz.elections.listener.IconMenuListener.onInventoryClick(IconMenuListener.java:42) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.9.4.jar:git-Spigot-4af49dc-6d133d5]
        ... 15 more
     
     
  2. Can you post the error code please? Thanks!

    Inviato dal mio SM-G930F utilizzando Tapatalk
     
  3. Just added it to the original post
     
  4. Something is null, and I'm going to guess it's the instance.

    Instead of doing this

    Code (Text):

    Elections.instance.getServer().getOfflinePlayer();
     
    Why not do this

    Code (Text):

    Bukkit.getOfflinePlayer();
     
     
    • Agree Agree x 1
  5. What is on line 26 of MayorGUI.java? That's what's causing the null pointer exception.
     
  6. Expanding on this, it tells you that line 26 ran Bukkit.broadcastMessage. Since it successfully called line 26 and the error was inside bukkit code, that means the supplied parameter (in this case, the String returned by getName()) is the problem.

    If getName() is returning null, I suggest debugging the UUIDs. The UUIDs might not be null, but do they actually represent a valid player?

    And as BillyGalbreath said, you should just use Bukkit.getOfflinePlayer() instead >.< It does the same as the getOfflinePlayer() you used, but it's simpler and you don't need to worry about having a plugin instance.