Skip to content

Commit

Permalink
Making MessageMaker a bit readable
Browse files Browse the repository at this point in the history
  • Loading branch information
fulcanelly committed Jul 6, 2020
1 parent 4422bc8 commit 8b176b9
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/main/java/me/fulcanelly/tgbridge/utils/StatCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map.Entry;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -194,20 +194,29 @@ synchronized void update() {
private class MessageMaker {

String result = new String("Played time: \n\n");

String get() {

<T extends Entry<String, Stats> > int comparator(T a, T b) {
return (int)( b.getValue().total_time - a.getValue().total_time );
}

void builder(Entry<String, Stats> pair) {
String player = pair.getKey();
Stats stat = pair.getValue();

result += String.format(
" 🏳️‍🌈 `%s` %s\n", player, stat.toString()
);
}

void buildUp() {
stats.entrySet()
.stream()
.sorted((a, b) -> (int)(a.getValue().total_time - b.getValue().total_time))
.forEach(pair -> {
String player = pair.getKey();
Stats stat = pair.getValue();

result += String.format(
" 🏳️‍🌈 %s %s\n", UsefulStuff.formatMarkdown(player), stat.toString()
);
});
.sorted(this::comparator)
.forEach(this::builder);
}

String get() {
this.buildUp();
return result;
}
}
Expand Down

0 comments on commit 8b176b9

Please sign in to comment.