1.7.10 getting the two first values of an hashmap

Discussion in 'Spigot Plugin Development' started by iNoXs, Jan 18, 2020.

Thread Status:
Not open for further replies.
  1. So ive been working on a duel plugin lately, when the player is waiting for a random match the player is stored in an hashmap
    Code (Java):
        private Map<Player, String> pendingPlayers;
    the value String is the kit of the player
    then to make it easier , got an new hashmap with only the duplicated values in this case the kit
    so the hashmap is ordered by kitName like so

    Vanilla: {CraftPlayer{name=Name1}=Vanilla, CraftPlayer{name=Name2}=Vanilla}

    Code (Java):
    public void search(DuelRank duelRank, String kit) {

            pendingPlayers.keySet().stream().forEach(key -> {
                String value = pendingPlayers.get(key);
                HashMap<Player, String> duplicate = duplicates.get(value);

                if (duplicate == null) {
                    duplicate = new HashMap<>();

                    duplicates.put(value, duplicate);

                duplicate.put(key, value);

            System.out.println("Original: " + pendingPlayers);

            duplicates.forEach((key, value) -> {
                if (key.toString().equals(kit)) {
                    if (value.size() >= 2) {
                        System.out.println(value.keySet().toArray()[0] + " : " + value.keySet().toArray()[1]);
                                .start(new Duel(Bukkit.getPlayer(value.keySet().toArray()[0].toString()),
                                        plugin.getArenaManager().availableArenas().get(0), kit));

    however i get an error at ''Bukkit.getPlayer(value.keySet().toArray()[0].toString()''
    how can i get the first two values of my map ?

    thanks !!!
  2. The way a Map is usually built, there is no "first" value or "second" value.
    Also, why do you have 2 maps? This whole thing is confusing me. If you want a sorted map, simply use a Map that implements SortedMap, like LinkedTreeMap.
    Also, what kind of error do you get? Can we see the stack-trace?
Thread Status:
Not open for further replies.