Solved Help in getting a player list from a certain hashMap

Discussion in 'Spigot Plugin Development' started by RoboBoy99, Jan 31, 2020.

  1. Hi so like the title says I'm trying to get the player list but I can't figure how to get it this code below is the closets I get but I'm not getting the full list
    players = public static HashMap<UUID, String> players = new HashMap<UUID, String>();

    public static String YourMembers(String clanName, Player player)
    for(OfflinePlayer pl : Bukkit.getOfflinePlayers())

    if (players.get(pl.getUniqueId()).matches(clanName))
    return null;
  2. Please wrap into [.CODE] [./CODE]
    To send the message, use Bukkit#getOnlinePlayers(). You can then send each a message
  3. I don't want to send a message to them I want to check which players are in that certain clan
    #3 RoboBoy99, Jan 31, 2020
    Last edited: Jan 31, 2020
  4. I can only assume what you want, is it this?
    Code (Java):
    final Map<UUID,String> players = new HashMap<>();

    if (players.contains(pl.getUniqueId())) {
  5. I want to get the UUID that equals to the string in the player's hashMap
    For example, if clan name is test I want to check which uuid is = to the clanName
  6. Just gonna suggest you make a Clan-class (not only but also because of) better readability. Then you'd have something like this:
    Code (Java):
    public class Clan {
        private Set<UUID> players;
        private String clanName;

        //constructor, getters, setters,...
        public boolean containsPlayer(Player player) {
            return players.contains(player.getUniqueId());
    Then you can simply do this:
    Code (Java):
    private final Set<Clan> clans = new HashSet<>();

    public void sendMessage(String message, Player toPlayer) {
        for (Clan clan: clans) {
            if (clan.containsPlayer(toPlayer)) {
  7. Is there maybe a way I can do that in a hashMap? I do have a Clan- class to
  8. Certainly, there is a way to do this in a HashMap, but for what reason?
    Maps are good, no question, but Object-orientation can help for a lot of reasons.
    If you are worried about performance, a HashSet is basically a HashMap (and, in fact, internally realized as one)
  9. I'm worried because I want to get the player from the group itself and I don't know how to use your code really
  10. Why couldn't you just do this?
    Code (Java):
            HashMap<UUID, String> players = new HashMap<>();
            for(UUID uuid : players.keySet()) {
                // Gets all UUIDs
            // or
            for(String string : players.values()) {
                // Gets all the key values
    You would be able to do whatever you want with the stuff inside the foreach loop
    NOTE: Untested
  11. Because I can't get the player who is in the selected clan name
  12. nvm I get it thx you
    #12 RoboBoy99, Feb 1, 2020
    Last edited: Feb 1, 2020