Getting each player on UUID list (Off & Online) always cast offline

Discussion in 'Spigot Discussion' started by Ohwnead, Jul 10, 2018.

Thread Status:
Not open for further replies.
  1. Hello, i'm trying to make a chest when open list all player head from UUID list, but it always cast it offlinePlayer,
    I tryed lot of way, an idea ? Thanks :p

    Code (Text):
    // s return UUID as String
                  ItemStack pHead = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                            if (Bukkit.getPlayer(s) != null && Bukkit.getPlayer(s).isOnline())
                            {
                                Player p = Bukkit.getPlayer(s);

                                SkullMeta pSkull = (SkullMeta) pHead.getItemMeta();
                                pSkull.setDisplayName(p.getName());
                                ArrayList<String> lore = new ArrayList<String>();
                                lore.add(s);
                                lore.add("Le joueur est §6en Ligne§r");
                                pSkull.setLore(lore);
                                pSkull.setOwner(p.getName());
                                pHead.setItemMeta(pSkull);

                            }
                            if (Bukkit.getPlayer(s) == null || !Bukkit.getPlayer(s).isOnline())
                            {
                                OfflinePlayer p = Bukkit.getOfflinePlayer(UUID.fromString(s));

                                SkullMeta pSkull = (SkullMeta) pHead.getItemMeta();
                                pSkull.setDisplayName(p.getName());
                                ArrayList<String> lore = new ArrayList<String>();
                                lore.add(s);
                                lore.add("Le joueur est §6Hors-Ligne§r");
                                pSkull.setLore(lore);
                                pSkull.setOwner(p.getName());
                                pHead.setItemMeta(pSkull);

                            }
     
  2. Why don't you use
    Code (Java):
    Bukkit#getOnlinePlayers
    , so iterate the collection and do whatever you want?
     
    • Friendly Friendly x 1
  3. It's from an UUID list, so player can be Offline
    I need to be with this list as entry.
     
  4. Oh I thought that you wanted to fill chest with online players heads..
    So.. where is the problem? :p
     
    • Friendly Friendly x 1
  5. The problem is either if the player is online or offline, he's casted as offline

    I'll try to cast all player as Offline and test if #isOnline()
     
  6. Obv, Player instance can't be get with UUID. You can get only OfflinePlayer through UUID. Just iterate over UUID list and check if the player is online. So you could write a function that returns the player online from the UUID
     
    • Winner Winner x 1
  7. I'hve see this at same time x), thanks for help, i'm to tired for remebering this xD

    new add :
    Code (Text):
    UUID u = UUID.fromString(s);
                                OfflinePlayer p = Bukkit.getPlayer(u);
    Thanks
    Solved & Wrong section
     
Thread Status:
Not open for further replies.