Efficiently Getting Offline Player

Discussion in 'Plugin Development' started by SirQuantum, Jul 27, 2019.

Thread Status:
Not open for further replies.
  1. So, for my purposes I want to get a player that's potentially Offline, however iterating through the entire collection of OfflinePlayers seems extreme? Is there a more effective way of doing this or do I have to settle?

    Edit: Sorry for any ambiguity, I want to search for the given player based on their username.
     
    Last edited: Jul 27, 2019
  2. Offline

    Machine Maker

  3. Sorry I should have cleared up I wanted to get them based on their Username.
     
  4. Offline

    Machine Maker

  5. I'm aware of this method. However, it's deprecated. I'm retrieving the username from a command argument. My current approach is just dispatching the task to another thread and running it asynchronously, however this solution seems overly complicated and I wanted a simpler solution.
     
  6. Offline

    Machine Maker

    Yeah, so if you are just getting that from a command argument, then you can get away with using the deprecated method. I assume you are using Craftbukkit, not spigot. Deprecated methods are almost never removed and are generally just put in to alert you to changes.
     
  7. Very well, however I'll keep this thread open as I'd still like to have another solution.

    This solution also doesn't offer anyway of telling if a username is invalid or not

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 27, 2019
  8. Offline

    Machine Maker

    oh wait

    Yeah it does. the OfflinePlayer class has a hasPlayedBefore() method that returns true or false depending if the player has played on the server or not. That might be what you are looking for. @SirQuantum

    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/OfflinePlayer.html#hasPlayedBefore--


    A possible other solution to getting a player by their UUID is to use Mojangs Public API to look up that username and see if a UUID is returned. if it is, its a player, and you have the uuid to lookup the OfflinePlayer with.
    https://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time
     
Thread Status:
Not open for further replies.

Share This Page