Skip to content

Commit eb9fc67

Browse files
committed
新たなキルリーダのやつ実装
1 parent 0c6783c commit eb9fc67

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.github.elic0de.hungergames.game;
2+
3+
import com.github.elic0de.hungergames.user.GameUser;
4+
import de.themoep.minedown.MineDown;
5+
6+
import java.util.*;
7+
8+
public class GameRecords {
9+
10+
//全記録
11+
private final Map<UUID, Long> records = new HashMap<>();
12+
13+
private final HungerGame game;
14+
15+
private Map<UUID, Integer> rank = new HashMap<>();
16+
17+
private UUID killLeader;
18+
19+
public GameRecords(HungerGame game) {
20+
this.game = game;
21+
sortAsync();
22+
}
23+
24+
public int getRank(GameUser user) {
25+
final UUID uuid = user.getUniqueId();
26+
if(rank.containsKey(uuid)) return rank.get(uuid);
27+
return -1;
28+
}
29+
30+
public void addKill(GameUser user){
31+
final UUID uuid = user.getUniqueId();
32+
if (containsRecord(user)) {
33+
final long kills = records.get(uuid);
34+
35+
if (kills >= 3) {
36+
if (killLeader != null) {
37+
if (getRank(user) == 1) {
38+
if (killLeader != uuid) {
39+
game.broadcast(new MineDown(String.format("&c%s&rが&c%s&rキルで新しいキルリーダになりました", user.getUsername(), Math.toIntExact(kills))));
40+
killLeader = uuid;
41+
}
42+
}
43+
} else {
44+
game.broadcast(new MineDown(String.format("&c%s&rが&c3キルで新しいキルリーダになりました", user.getUsername())));
45+
killLeader = uuid;
46+
}
47+
}
48+
49+
records.put(uuid, kills + 1);
50+
return;
51+
}
52+
records.put(uuid, 1L);
53+
sortAsync();
54+
}
55+
56+
private boolean containsRecord(GameUser user){
57+
return records.containsKey(user.getUniqueId());
58+
}
59+
60+
public long personalBest(GameUser user){
61+
return records.getOrDefault(user.getUniqueId(), 0L);
62+
}
63+
64+
public void removeAllRecord() {
65+
//すべてのレコードを削除する
66+
records.clear();
67+
sortAsync();
68+
}
69+
70+
public void sortAsync(){
71+
final List<Map.Entry<UUID, Long>> list = new ArrayList<>(records.entrySet());
72+
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);
80+
81+
UUID uuid = record.getKey();
82+
rank.put(uuid,index + 1);
83+
}
84+
}
85+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ public class HungerGame extends AbstractGame {
4848

4949
private DragonTrait dragonTrait;
5050

51+
private GameRecords records;
52+
5153
public HungerGame() {
5254
scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
5355
border = new GameBorder(this);
5456
deathChest = new DeathChest();
57+
records = new GameRecords(this);
5558
}
5659

5760
public void join(GameUser user) {
@@ -130,6 +133,10 @@ public void onDeath(GameUser user) {
130133
wonGame();
131134
}
132135

136+
if (user.getPlayer().getKiller() != null) {
137+
records.addKill(user);
138+
}
139+
133140
deathChest.generateChest(user);
134141
user.getPlayer().setGameMode(GameMode.SPECTATOR);
135142
user.getPlayer().getWorld().strikeLightningEffect(user.getPlayer().getLocation());
@@ -157,6 +164,7 @@ public void reset() {
157164
aliveTeams.clear();
158165
deadPlayers.clear();
159166
border.reset();
167+
records.removeAllRecord();
160168
if (dragonTrait != null) dragonTrait.reset();
161169
}
162170

0 commit comments

Comments
 (0)