NullPointerException When Trying to Access Offline Player

Discussion in 'Plugin Development' started by BronzW, Sep 8, 2020.

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

    BronzW

    Im trying to access an OfflinePlayer object by this code right here;

    Code:Java
    1.  
    2. YamlLoader ymlLdr = new YamlLoader();
    3. String uuid;
    4.  
    5. uuid = ymlLdr.getUuidFromDiscordId("414459528998813736");
    6. System.out.println(uuid);
    7.  
    8. // 8daa0dd6-d184-4d80-894c-08fc4302d7df
    9. UUID uniqueId = UUID.fromString(uuid);
    10.  
    11. OfflinePlayer player = Bukkit.getOfflinePlayer(uniqueId);
    12. title = player.getName();
    13. description = "Ditt discord konto är direkt kopplat till whitelisten.";
    14.  


    ...I get this error:

    Code:
    [JDA MainWS-ReadThread] ERROR JDA - One of the EventListeners had an uncaught exception
    java.lang.NullPointerException
        at org.bukkit.Bukkit.getOfflinePlayer(Bukkit.java:878)
        at me.Acrins.DiscordWhitelist.DiscordAPI.Commands.onGuildMessageReceived(Commands.java:81)
        at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:398)
        at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
        at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:82)
        at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:69)
        at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:150)
        at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:97)
        at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
        at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:948)
        at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:835)
        at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:813)
        at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:986)
        at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:385)
        at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:276)
        at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:996)
        at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:755)
        at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
        at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
        at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
    

    But if I input the exact same thing into https://mcuuid.net/ , it works. And if I create a local variable with the same uuid and try that, my code doesn't work. And yes, the uuid I'm pulling out of the yml file is the same as the one I'm trying to use.


    And something important too, I'm not doing this in a command. I'm using the JDA library to be able to interact with discord. So this basically checks if you uuid is in a yml file that is connected to your discord id. Could that be a problem?
     
    Last edited: Sep 8, 2020
  2. Offline

    timtower Administrator Administrator Moderator

    @BronzW Did you look for what can be null?
     
  3. Offline

    BronzW

    What do you mean? It references the line where I'm trying to get a offlineplayer by the uuid

    Code:java
    1.  
    2. OfflinePlayer player = Bukkit.getOfflinePlayer(uniqueId);
    3.  
     
  4. Offline

    timtower Administrator Administrator Moderator

    @BronzW And does uniqueId have a value then?
     
  5. Offline

    BronzW

  6. Offline

    KarimAKL

    @BronzW Try checking what line 878 of Bukkit is. That might give you a hint to what's wrong.
     
  7. Offline

    BronzW

    It says it is not a valid line number? I'm using eclipse. Is it that that causes it or were you referencing something else?
     
  8. Offline

    Kars

    No you don't. At least not in the code you provided.
     
  9. Offline

    KarimAKL

    @BronzW I'm talking about the source code from the server jar you're using.
     
Thread Status:
Not open for further replies.

Share This Page