(I have only tested this with 2 players)
I am making a Minecraft koth plugin, I have a sorting system to sort the players based on their score but when a player overtakes another player, instead of having the score of 2 players it has 2 times 1 player.
The code:
List<String> keys = new ArrayList<String>();
List<Integer> values = new ArrayList<Integer>();
for (Map.Entry<String, Integer> _ : playerScores.entrySet()) {
String key = null;
Integer value = null;
for (Map.Entry<String, Integer> entry : playerScores.entrySet()) {
if (value == null) {
value = entry.getValue();
key = entry.getKey();
} else {
if (keys.contains(key)) {
value = entry.getValue();
key = entry.getKey();
} else {
if (value < entry.getValue()) {
value = entry.getValue();
key = entry.getKey();
}
}
}
}
values.add(value);
keys.add(key);
}
playerScores is a hashmap with the player uuid (String) as key and the score (Integer) as value.
If you want to tell me something like that I'm bad at java or that's it better to do something else first, please don't I have heard it enough.