Skip to content

Commit 031bd2d

Browse files
committed
新しいキルリーダになりました
1 parent e7f4070 commit 031bd2d

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/main/java/com/github/elic0de/hungergames/game/GameRecords.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import de.themoep.minedown.MineDown;
55

66
import java.util.*;
7+
import java.util.concurrent.atomic.AtomicInteger;
78

89
public class GameRecords {
910

10-
//全記録
11+
// 全記録
1112
private final Map<UUID, Long> records = new HashMap<>();
1213

1314
private final HungerGame game;
@@ -30,7 +31,9 @@ public int getRank(GameUser user) {
3031
public void addKill(GameUser user){
3132
final UUID uuid = user.getUniqueId();
3233
if (containsRecord(user)) {
33-
final long kills = records.get(uuid);
34+
final long kills = records.get(uuid) + 1;
35+
records.put(uuid, kills);
36+
sortAsync();
3437

3538
if (kills >= 3) {
3639
if (killLeader != null) {
@@ -41,12 +44,11 @@ public void addKill(GameUser user){
4144
}
4245
}
4346
} else {
44-
game.broadcast(new MineDown(String.format("&c%s&rが&c3キルで新しいキルリーダになりました", user.getUsername())));
47+
game.broadcast(new MineDown(String.format("&c%s&rが&c3&rキルで新しいキルリーダになりました", user.getUsername())));
4548
killLeader = uuid;
4649
}
4750
}
4851

49-
records.put(uuid, kills + 1);
5052
return;
5153
}
5254
records.put(uuid, 1L);
@@ -57,8 +59,8 @@ private boolean containsRecord(GameUser user){
5759
return records.containsKey(user.getUniqueId());
5860
}
5961

60-
public long personalBest(GameUser user){
61-
return records.getOrDefault(user.getUniqueId(), 0L);
62+
public long personalBest(UUID uuid){
63+
return records.getOrDefault(uuid, 0L);
6264
}
6365

6466
public void removeAllRecord() {
@@ -67,19 +69,18 @@ public void removeAllRecord() {
6769
sortAsync();
6870
}
6971

70-
public void sortAsync(){
72+
private void sortAsync(){
7173
final List<Map.Entry<UUID, Long>> list = new ArrayList<>(records.entrySet());
74+
final AtomicInteger position = new AtomicInteger();
7275

73-
//記録を昇順にソートする
74-
list.sort(Map.Entry.comparingByValue());
75-
76-
//最大で上位10件の記録をリストに追加する
77-
for(int index = 0; index < records.size(); index++){
78-
//ソート済みリストから記録を取得する
79-
Map.Entry<UUID, Long> record = list.get(index);
76+
// 記録を降順にソートする
77+
// 最大で上位10件の記録をリストに追加する
78+
list.stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).forEach(entry -> {
79+
rank.put(entry.getKey(), position.incrementAndGet());
80+
});
81+
}
8082

81-
UUID uuid = record.getKey();
82-
rank.put(uuid,index + 1);
83-
}
83+
public Map<UUID, Integer> getRank() {
84+
return rank;
8485
}
8586
}

0 commit comments

Comments
 (0)