Skip to content

Commit a4ead53

Browse files
committed
add kill/assist streaks
1 parent 2f20791 commit a4ead53

File tree

7 files changed

+244
-3
lines changed

7 files changed

+244
-3
lines changed

src/main/java/net/azisaba/lgwneo/config/LeonGunWarNeoConfig.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import net.azisaba.lgwneo.sql.MySQLConnectionData;
88
import org.bukkit.configuration.file.FileConfiguration;
99

10+
import java.util.*;
11+
import java.util.function.Function;
12+
import java.util.stream.Collectors;
13+
1014
@Getter
1115
@RequiredArgsConstructor
1216
public class LeonGunWarNeoConfig {
@@ -18,6 +22,12 @@ public class LeonGunWarNeoConfig {
1822

1923
private String serverName;
2024

25+
private Map<Integer, Map.Entry<List<String>, List<String>>> streaks;
26+
private Map<Integer, Map.Entry<List<String>, List<String>>> killLevels;
27+
private String removed;
28+
29+
private Map<Integer, Map.Entry<List<String>, List<String>>> assistLevels;
30+
2131
/**
2232
* Configを読み込みます
2333
*
@@ -54,6 +64,50 @@ public LeonGunWarNeoConfig load() {
5464
mySQLHostname, mySQLPort, mySQLUsername, mySQLPassword, mySQLDatabase);
5565

5666
serverName = conf.getString("server-name");
67+
68+
streaks = new HashMap<>();
69+
conf.getConfigurationSection("streaks").getValues(false).keySet().stream()
70+
.map(Integer::valueOf)
71+
.collect(
72+
Collectors.toMap(
73+
Function.identity(),
74+
count -> {
75+
List<String> messages = conf.getStringList("streaks." + count + ".messages");
76+
List<String> commands = conf.getStringList("streaks." + count + ".commands");
77+
return new AbstractMap.SimpleEntry<>(messages, commands);
78+
}))
79+
.forEach(streaks::put);
80+
streaks = Collections.unmodifiableMap(streaks);
81+
82+
killLevels = new HashMap<>();
83+
conf.getConfigurationSection("levels").getValues(false).keySet().stream()
84+
.map(Integer::valueOf)
85+
.collect(
86+
Collectors.toMap(
87+
Function.identity(),
88+
count -> {
89+
List<String> messages = conf.getStringList("killLevels." + count + ".messages");
90+
List<String> commands = conf.getStringList("killLevels." + count + ".commands");
91+
return new AbstractMap.SimpleEntry<>(messages, commands);
92+
}))
93+
.forEach(killLevels::put);
94+
killLevels = Collections.unmodifiableMap(killLevels);
95+
96+
removed = conf.getString("removed");
97+
98+
assistLevels = new HashMap<>();
99+
conf.getConfigurationSection("levels").getValues(false).keySet().stream()
100+
.map(Integer::valueOf)
101+
.collect(
102+
Collectors.toMap(
103+
Function.identity(),
104+
count -> {
105+
List<String> messages = conf.getStringList("assistLevels." + count + ".messages");
106+
List<String> commands = conf.getStringList("assistLevels." + count + ".commands");
107+
return new AbstractMap.SimpleEntry<>(messages, commands);
108+
}))
109+
.forEach(assistLevels::put);
110+
assistLevels = Collections.unmodifiableMap(assistLevels);
57111
return this;
58112
}
59113
}

src/main/java/net/azisaba/lgwneo/listener/GlobalMatchListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void onKill(PlayerDeathEvent e) {
6767
// キル数とデス数をカウントする
6868
if (match.getKillDeathAssistCounter() != null) {
6969
match.getKillDeathAssistCounter().addKills(killer.getUniqueId());
70-
match.getKillDeathAssistCounter().addDeaths(e.getEntity().getUniqueId());
70+
match.getKillDeathAssistCounter().addDeaths(e.getEntity().getUniqueId(), killer.getUniqueId());
7171
}
7272
}
7373

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package net.azisaba.lgwneo.match;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import net.azisaba.lgwneo.LeonGunWarNeo;
5+
import net.azisaba.lgwneo.match.mode.Match;
6+
import net.azisaba.lgwneo.util.Chat;
7+
import org.bukkit.Bukkit;
8+
import org.bukkit.entity.Player;
9+
10+
import java.util.List;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
import java.util.UUID;
14+
import java.util.concurrent.atomic.AtomicInteger;
15+
16+
@RequiredArgsConstructor
17+
public class AssistStreaks {
18+
19+
private final LeonGunWarNeo plugin;
20+
private final Map<UUID, AtomicInteger> streaksMap = new HashMap<>();
21+
22+
public void removedBy(UUID uuid) {
23+
streaksMap.remove(uuid);
24+
}
25+
26+
public AtomicInteger get(UUID uuid) {
27+
streaksMap.putIfAbsent(uuid, new AtomicInteger(0));
28+
return streaksMap.get(uuid);
29+
}
30+
31+
public void add(UUID uuid) {
32+
// カウントを追加
33+
int streaks = get(uuid).incrementAndGet();
34+
Player player = Bukkit.getPlayer(uuid);
35+
36+
// 報酬を付与
37+
plugin.getLeonGunWarNeoConfig().getAssistLevels().entrySet().stream()
38+
.filter(entry -> streaks % entry.getKey() == 0)
39+
.map(Map.Entry::getValue)
40+
.map(Map.Entry::getValue)
41+
.flatMap(List::stream)
42+
.map(command -> Chat.f(command, player.getName()))
43+
.forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
44+
Match match = plugin.getMatchOrganizer().getMatchFromPlayer(player);
45+
// アシストストリークをお知らせ
46+
plugin.getLeonGunWarNeoConfig().getAssistLevels().entrySet().stream()
47+
.filter(entry -> streaks % entry.getKey() == 0)
48+
.map(Map.Entry::getValue)
49+
.map(Map.Entry::getKey)
50+
.flatMap(List::stream)
51+
.map(message -> Chat.f(message, LeonGunWarNeo.getChatPrefix(), player.getDisplayName()))
52+
.forEach(match::broadcastMessage);
53+
}
54+
55+
}

src/main/java/net/azisaba/lgwneo/match/KillDeathAssistCounter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.UUID;
66
import java.util.concurrent.atomic.AtomicInteger;
77
import lombok.RequiredArgsConstructor;
8+
import net.azisaba.lgwneo.match.mode.Match;
89

910
/**
1011
* プレイヤーの1試合でのキル数デス数アシスト数を記録するクラス
@@ -14,6 +15,8 @@
1415
@RequiredArgsConstructor
1516
public class KillDeathAssistCounter {
1617

18+
private final Match match;
19+
1720
private final HashMap<UUID, AtomicInteger> kills = new HashMap<>();
1821
private final HashMap<UUID, AtomicInteger> deaths = new HashMap<>();
1922
private final HashMap<UUID, AtomicInteger> assists = new HashMap<>();
@@ -27,6 +30,7 @@ public class KillDeathAssistCounter {
2730
*/
2831
public void addKills(UUID uuid) {
2932
kills.computeIfAbsent(uuid, k -> new AtomicInteger()).incrementAndGet();
33+
match.getKillStreaks().add(uuid);
3034
}
3135

3236
/**
@@ -62,8 +66,10 @@ public void addKills(UUID uuid, UUID victim) {
6266
*
6367
* @param uuid デス数を追加するプレイヤーのUUID
6468
*/
65-
public void addDeaths(UUID uuid) {
69+
public void addDeaths(UUID uuid, UUID killer) {
6670
deaths.computeIfAbsent(uuid, k -> new AtomicInteger()).incrementAndGet();
71+
match.getKillStreaks().removedBy(uuid, killer);
72+
match.getAssistStreaks().removedBy(uuid);
6773
}
6874

6975
/**
@@ -73,6 +79,7 @@ public void addDeaths(UUID uuid) {
7379
*/
7480
public void addAssists(UUID uuid) {
7581
assists.computeIfAbsent(uuid, k -> new AtomicInteger()).incrementAndGet();
82+
match.getAssistStreaks().add(uuid);
7683
}
7784

7885
/**
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package net.azisaba.lgwneo.match;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import net.azisaba.lgwneo.LeonGunWarNeo;
5+
import net.azisaba.lgwneo.match.mode.LeaderDeathMatch;
6+
import net.azisaba.lgwneo.match.mode.Match;
7+
import net.azisaba.lgwneo.util.Chat;
8+
import org.bukkit.Bukkit;
9+
import org.bukkit.entity.Player;
10+
11+
import java.util.List;
12+
import java.util.HashMap;
13+
import java.util.Map;
14+
import java.util.UUID;
15+
import java.util.concurrent.atomic.AtomicInteger;
16+
17+
@RequiredArgsConstructor
18+
public class KillStreaks {
19+
20+
private final LeonGunWarNeo plugin;
21+
22+
private final Map<UUID, AtomicInteger> streaksMap = new HashMap<>();
23+
24+
public void removedBy(UUID uuid, UUID killerU) {
25+
Player player = Bukkit.getPlayer(uuid);
26+
Player killer = Bukkit.getPlayer(killerU);
27+
int streaks = get(uuid).get();
28+
int minStreaks =
29+
plugin.getLeonGunWarNeoConfig().getStreaks().entrySet().stream()
30+
.sorted(Map.Entry.comparingByKey())
31+
.map(Map.Entry::getKey)
32+
.findFirst()
33+
.orElse(-1);
34+
35+
if (killer != null && streaks >= minStreaks) {
36+
Match match = plugin.getMatchOrganizer().getMatchFromPlayer(uuid);
37+
match.broadcastMessage(
38+
Chat.f(
39+
plugin.getLeonGunWarNeoConfig().getRemoved(),
40+
LeonGunWarNeo.getChatPrefix(),
41+
killer.getDisplayName(),
42+
player.getDisplayName()
43+
)
44+
);
45+
}
46+
47+
streaksMap.remove(player.getUniqueId());
48+
}
49+
50+
public AtomicInteger get(UUID uuid) {
51+
streaksMap.putIfAbsent(uuid, new AtomicInteger(0));
52+
return streaksMap.get(uuid);
53+
}
54+
55+
private void giveRewards(int streaks, UUID uuid) {
56+
Player player = Bukkit.getPlayer(uuid);
57+
plugin.getLeonGunWarNeoConfig().getStreaks().entrySet().stream()
58+
.filter(entry -> streaks == entry.getKey())
59+
.map(Map.Entry::getValue)
60+
.map(Map.Entry::getValue)
61+
.flatMap(List::stream)
62+
.map(command -> Chat.f(command, player.getName()))
63+
.forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
64+
plugin.getLeonGunWarNeoConfig().getKillLevels().entrySet().stream()
65+
.filter(entry -> streaks % entry.getKey() == 0)
66+
.map(Map.Entry::getValue)
67+
.map(Map.Entry::getValue)
68+
.flatMap(List::stream)
69+
.map(command -> Chat.f(command, player.getName()))
70+
.forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
71+
}
72+
73+
public void add(UUID uuid) {
74+
// カウントを追加
75+
int streaks = get(uuid).incrementAndGet();
76+
Match match = plugin.getMatchOrganizer().getMatchFromPlayer(uuid);
77+
Player player = Bukkit.getPlayer(uuid);
78+
// 報酬を付与
79+
giveRewards(streaks, uuid);
80+
if (match instanceof LeaderDeathMatch) {
81+
if (((LeaderDeathMatch)match).getTeamLeaderMap().containsValue(uuid)) {
82+
giveRewards(streaks, uuid);
83+
player.sendMessage(Chat.f("{0}&7あなたはリーダーなので &e2倍 &7の報酬を受け取りました!", LeonGunWarNeo.getChatPrefix()));
84+
}
85+
}
86+
87+
// キルストリークをお知らせ
88+
plugin.getLeonGunWarNeoConfig().getStreaks().entrySet().stream()
89+
.filter(entry -> streaks == entry.getKey())
90+
.map(Map.Entry::getValue)
91+
.map(Map.Entry::getKey)
92+
.flatMap(List::stream)
93+
.map(message -> Chat.f(message, LeonGunWarNeo.getChatPrefix(), player.getDisplayName()))
94+
.forEach(match::broadcastMessage);
95+
plugin.getLeonGunWarNeoConfig().getKillLevels().entrySet().stream()
96+
.filter(entry -> streaks % entry.getKey() == 0)
97+
.map(Map.Entry::getValue)
98+
.map(Map.Entry::getKey)
99+
.flatMap(List::stream)
100+
.map(message -> Chat.f(message, LeonGunWarNeo.getChatPrefix(), player.getDisplayName()))
101+
.forEach(match::broadcastMessage);
102+
}
103+
104+
}

src/main/java/net/azisaba/lgwneo/match/mode/LeaderDeathMatch.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import lombok.Setter;
2222
import net.azisaba.lgwneo.LeonGunWarNeo;
2323
import net.azisaba.lgwneo.animation.MatchResultAnimation;
24+
import net.azisaba.lgwneo.match.AssistStreaks;
2425
import net.azisaba.lgwneo.match.KillDeathAssistCounter;
26+
import net.azisaba.lgwneo.match.KillStreaks;
2527
import net.azisaba.lgwneo.match.component.MatchResult;
2628
import net.azisaba.lgwneo.match.component.MatchStatus;
2729
import net.azisaba.lgwneo.match.component.MatchTeam;
@@ -72,6 +74,7 @@ public class LeaderDeathMatch implements Match {
7274
private final HashMap<MatchTeam, Set<Player>> teamPlayerMap = new HashMap<>();
7375
private final HashMap<MatchTeam, Set<UUID>> offlineTeamPlayerMap = new HashMap<>();
7476
private final Set<Party> queueingParties = new HashSet<>();
77+
@Getter
7578
private final HashMap<MatchTeam, UUID> teamLeaderMap = new HashMap<>();
7679

7780
@Getter
@@ -80,7 +83,7 @@ public class LeaderDeathMatch implements Match {
8083
private final FlexibleCountdownTask matchCountdownTask = new FlexibleCountdownTask(600);
8184

8285
@Getter
83-
private final KillDeathAssistCounter killDeathAssistCounter = new KillDeathAssistCounter();
86+
private final KillDeathAssistCounter killDeathAssistCounter = new KillDeathAssistCounter(this);
8487

8588
@Getter
8689
private final HashMap<MatchTeam, AtomicInteger> scoreMap = new HashMap<>();
@@ -99,6 +102,11 @@ public class LeaderDeathMatch implements Match {
99102

100103
private final HashMap<MatchTeam, ItemStack> chestPlateMap = new HashMap<>();
101104

105+
@Getter
106+
private final KillStreaks killStreaks = new KillStreaks(plugin);
107+
@Getter
108+
private final AssistStreaks assistStreaks = new AssistStreaks(plugin);
109+
102110
@Override
103111
public Map<String, Object> getMatchInformationAsMap() {
104112
HashMap<String, Object> data = new HashMap<>();
@@ -367,6 +375,11 @@ public Location getRespawnLocationFor(Player player) {
367375
return null;
368376
}
369377

378+
@Override
379+
public void broadcastMessage(String message){
380+
this.getParticipatePlayers().forEach(Player::sendMessage);
381+
}
382+
370383
/**
371384
* 試合でのプレイヤーのチームを取得する
372385
*

src/main/java/net/azisaba/lgwneo/match/mode/Match.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import java.util.Map;
44
import java.util.Set;
55
import java.util.concurrent.CompletableFuture;
6+
7+
import net.azisaba.lgwneo.match.AssistStreaks;
68
import net.azisaba.lgwneo.match.KillDeathAssistCounter;
9+
import net.azisaba.lgwneo.match.KillStreaks;
710
import net.azisaba.lgwneo.match.component.MatchStatus;
811
import net.azisaba.lgwneo.party.Party;
912
import net.azisaba.lgwneo.world.map.MatchMap;
@@ -128,4 +131,9 @@ public interface Match {
128131
* @return 試合で使用しているKillDeathAssistCounterインスタンス
129132
*/
130133
KillDeathAssistCounter getKillDeathAssistCounter();
134+
135+
void broadcastMessage(String message);
136+
137+
KillStreaks getKillStreaks();
138+
AssistStreaks getAssistStreaks();
131139
}

0 commit comments

Comments
 (0)