Solved Keyset from HashMap

Discussion in 'Spigot Plugin Development' started by DevSnx, Feb 5, 2020.

Thread Status:
Not open for further replies.
  1. Hello, guys

    i will get the UUID from postion 1 from the LinkedHashMap (statsapi_kills)

    Code (Text):
        public LinkedHashMap<UUID, Integer> getStatsapi_kills() {
            return this.statsapi_kills;
        }

        public UUID getUUID(RankedType rankedType, int position){
            UUID uuid = null;
            if(rankedType == RankedType.KILLS){

                //get the #postion# from the hashmap getStatsapi_kills!

            }else if(rankedType == RankedType.DEATHS){

            }else if(rankedType == RankedType.WINS){

            }else if(rankedType == RankedType.GAMES){

            }
            return uuid;
        }

        public Integer getValues(RankedType rankedType, UUID uuid){
            int value = 0;
            if(rankedType == RankedType.KILLS){
                value = getStatsapi_kills().get(uuid);
            }else if(rankedType == RankedType.DEATHS){
                value = getStatsapi_deaths().get(uuid);
            }else if(rankedType == RankedType.WINS){
                value = getStatsapi_wins().get(uuid);
            }else if(rankedType == RankedType.GAMES){
                value = getStatsapi_games().get(uuid);
            }
            return value;
        }
     
  2. I do not understand exactly what you want to do, if this is what I think, you want to recover the uuid of the player being the first in a ranking, knowing that all the players as well as their number of kills are in this HashMap?
     
  3. So i will 2 methods
    - getRanking(UUID uuid) = return the rank;
    - getPlayerUUIDFromRanking(int rank) = return the uuid;
     
  4. Okay I understood, here is the method :

    1. Put all of your players in the HashMap (which you normally did)
    2. Sort your HashMap by decreasing order (from the player with the most kills to the one with the least)
    3. Get the player's index, which will correspond to his rank starting from 0
     
  5. I have it :D but step 3 is wrong
     
  6. I do not understand, you had already done steps 1 and 2 in your code? And it's step 3 that doesn't work?
    Can you send me your code?


    And what language do you speak ?
     
  7. look this https://hastebin.com/uqicaqiziv.cs
    iam dont know at line 119.. :D

    German
     
  8. done!, but thanks for help
     
    • Like Like x 1
Thread Status:
Not open for further replies.