How to get Player Object properly from Command Arguments?

Discussion in 'Plugin Development' started by motionfrog, Jul 7, 2019.

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


    Hello. I know, maybe this question has been asked a few times, but there is none (i found) that make me clear of what I want.

    From the docs, i saw that Bukkit.getPlayer(String name) is Depreciated, is it still used in newer plugins nowadays?

    What is the best way you can recommend to get Player Object by the argument in a command?

    I tried to create a new static Object with ArrayList<UUID> inside it and store all offline player data on plugin loads (onEnable) and create onPlayerJoin listener to add a new player to the list. Then when a player calls the command with player name argument, the plugin loops inside the ArrayList and find the equal value with the input argument.

    Is there more ways to implement this? Or should I stick with the depreciated method getPlayer(String) for an easy instant solution ?

    Thank you very much.
    Last edited: Jul 7, 2019
  2. Offline

    timtower Moderator Moderator

    @motionfrog Just use Bukkit.getPlayer(name), just not for data storage. For getting a player based on name it is fine.
  3. Offline


    You can change the title using 'Thread Tools' at the top right of your post.
  4. Offline


    shoot, didnt saw it before moderated, thanks for the tips ;)

    Ah I see thanks for that, I think so too, that the UUID usage is for non-unique player name, that it is so rare to find that error. Thank you ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jul 7, 2019
Thread Status:
Not open for further replies.

Share This Page