#Sorting System

1 messages · Page 1 of 1 (latest)

uncut imp
#

(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.

brave vesselBOT
# uncut imp (I have only tested this with 2 players) I am making a Minecraft koth plugin, I...

Detected code, here are some useful tools:

Formatted 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);
}
#

<@&987246652869971988> please have a look, thanks.

brave vesselBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

spice zephyr
# uncut imp (I have only tested this with 2 players) I am making a Minecraft koth plugin, I...

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.
Or maybe you should actually learn java, at least parallel to making your plugins 🙂

I don't really understand what you are trying to do, are you trying to make two lists sorted by scores ?
But then, why don't you make a class instead of having to play with two distinct lists ?

uncut imp
spice zephyr
#

so are you trying to sort those two lists or not ?

spice zephyr
#

then why don't you make a class instead of having two lists ?

#

also, which version of java are you using ?

#

@uncut imp