Solved Sorting Online UUIDS

Discussion in 'Plugin Development' started by johnnyD, Jul 2, 2020.

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

    johnnyD

    I am taking a list of uuids from a config file and trying to sort out the ones that are online.

    Heres what I have so far for my method, but I keep getting internal erros so im guessing something is null.
    Ex: https://gyazo.com/1a73d0b9f8800d2b43cd9c8336ab682b
     
  2. @johnnyD
    I would use UUID not string and loop through all online players and add the uuid to a list

    ArrayList<UUID> list = new ArrayList<UUID>();
    for(Player p : Bukkit.getOnlinePlayers()){
    list.add(p.getUniqueId());
    }
     
  3. Offline

    johnnyD

    Im looping through a list of uuids in a config, so I have to use a List<String> since .getStringList requires it.
     
  4. @johnnyD

    Code:
    ArrayList<String> onlinePlayers = new ArrayList<String>();
                for(String uuid : this.getConfig().getStringList("players")) {
                    for(Player p : Bukkit.getOnlinePlayers()) {
                        if(p.getUniqueId().toString().equals(uuid))
                            onlinePlayers.add(p.getName());
                    }
                }
                return onlinePlayers;
     
  5. Offline

    KarimAKL

    @johnnyD Do you want the offline players at the bottom (after online players) of the list or do you want to only have the online players in the list?

    Also, you can get a UUID from a string using UUID#fromString(String), so you don't need a list of type List<String>.
     
    Last edited by a moderator: Jul 3, 2020
  6. Offline

    johnnyD

    Thanks <3
     
Thread Status:
Not open for further replies.

Share This Page