How can I get the player from a UUID

Discussion in 'Plugin Development' started by MrSnare, Jun 30, 2013.

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

    MrSnare

    I would need to check if the UUID belongs to a player and also see if they are online.

    Code:
        public void sendMessageToTeam(String message){
            //getTeamMates() returns a list of UUIDs
            for(UUID uuid : getTeamMates()){
                //if uuid belongs to a player and they are online, send them a message
            }
        }
     
  2. Offline

    pope_on_dope

    MrSnare from Shotbow! HEY! sorry off topic.
     
    MrSnare likes this.
  3. Offline

    MrSnare

    Yes hello :D
     
  4. Offline

    JazzaG

    MrSnare

    Code:
       
        public void sendMessageToTeam(String message){
            //getTeamMates() returns a list of UUIDs
            for(UUID uuid : getTeamMates()){
                try {
                    Player player = getPlayerByUuid(uuid);
                    player.sendMessage("foo");
                } catch(IllegalArgumentException ignored) {}
            }
        }
     
        /** Gets online player from UUID */
        public Player getPlayerByUuid(UUID uuid) {
            for(Player p : getServer().getOnlinePlayers())
                if(p.getUniqueId().equals(uuid)
                    return p;
     
            throw new IllegalArgumentException();
        }
    
     
    com. BOY and MrSnare like this.
  5. Offline

    stink123456

    Bukkit.getPlayer(uuid);
    :p or Bukkit.getOfflinePlayer(uuid);
     
  6. Offline

    deathline75

    Code:java
    1. if (Bukkit.getOfflinePlayer(uuid) != null && Bukkit.getOfflinePlayer(uuid).isOnline()) {
    2. // Do stuff
    3. }

    Hope that helped!
     
Thread Status:
Not open for further replies.

Share This Page