Player target = args[1]?

Discussion in 'Plugin Development' started by MCMatters, May 5, 2014.

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

    MCMatters

    Im trying to
    Code:
                if (args.length == 2) {
                    Player target = (I Dont Get What Goes Here)
    
     
  2. Offline

    TGRHavoc

    MCMatters
    Player target = Bukkit.getOnlinePlayer(args[1]) - or whichever argument the player is being set in.
     
  3. Offline

    MCMatters

    The method getOnlinePlayer(String) is undefined for the type Bukkit
     
  4. Offline

    coasterman10

    Correction: Bukkit.getPlayer(username)
     
  5. Offline

    Wizehh

    Shouldn't we be using Bukkit.getPlayer(UUID.fromString(username))?
     
  6. Offline

    Gater12

    Double correction: Bukkit.getPlayerExact(String s) for some safety of actually getting THAT player.

    Unless you want to get a player that is closest to that name.
     
  7. Offline

    Cloaking_Ocean

    Well the way I do it is just Player target = this.getServer.getPlayer(args[2]);
     
  8. Wizehh No. UUIDs are only good because they'll always (theoretically) be unique for each player, whereas usernames won't necessarily always be the same player. Converting the username to a UUID removes that safety, so there's no real reason to use it over usernames in that case.
     
  9. Offline

    1Rogue


    Usernames aren't UUIDs
     
  10. Offline

    geret13

    Don't forget to do a null check, the player might not exist!
     
  11. Offline

    Wizehh

    Oh, I see. I just suggested that because of the former method being deprecated.
     
  12. Wizehh And that's why it's important to know when to use what. ;) Especially because of what 1Rogue said.
     
Thread Status:
Not open for further replies.

Share This Page