Skip to content

Commit 33ab28a

Browse files
Merge pull request #525 from ArikSquad/feat/bw
BedWars Gamemode
2 parents e75a5a7 + 4c30780 commit 33ab28a

778 files changed

Lines changed: 34384 additions & 1812 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ jobs:
5757
service.api/build/libs/*.jar
5858
service.datamutex/build/libs/*.jar
5959
service.party/build/libs/*.jar
60-
service.darkauction/build/libs/*.jar
60+
service.orchestrator/build/libs/*.jar
61+
service.darkauction/build/libs/*.jar

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ build/
4949
/configuration/skyblock/islands/*
5050
/configuration/hypixel_prototype_lobby/
5151
.gradle/
52+
/configuration/bedwars/*.polar
53+
/server/proxy/logs/
54+
/server/proxy/lang/
55+
/server/forwarding.secret
56+
/configuration/logs/

commons/src/main/java/net/swofty/commons/ServerType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum ServerType {
1414
PROTOTYPE_LOBBY(false),
1515
BEDWARS_LOBBY(false),
1616
BEDWARS_GAME(false),
17+
BEDWARS_CONFIGURATOR(false)
1718
;
1819

1920
private final boolean isSkyBlock;

commons/src/main/java/net/swofty/commons/ServiceType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public enum ServiceType {
88
DATA_MUTEX,
99
PARTY,
1010
DARK_AUCTION,
11+
ORCHESTRATOR
1112
;
1213
}

commons/src/main/java/net/swofty/commons/StringUtility.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
66
import net.minestom.server.instance.block.Block;
77
import net.minestom.server.item.Material;
8-
import net.swofty.commons.statistics.ItemStatistic;
8+
import net.swofty.commons.skyblock.statistics.ItemStatistic;
99

1010
import java.math.RoundingMode;
1111
import java.text.DecimalFormat;
1212
import java.text.SimpleDateFormat;
1313
import java.util.ArrayList;
14+
import java.util.Arrays;
1415
import java.util.List;
1516
import java.util.concurrent.TimeUnit;
1617
import java.util.regex.Matcher;
@@ -260,6 +261,16 @@ public static List<String> splitByWordAndLength(String string, int splitLength)
260261
return result;
261262
}
262263

264+
public static List<String> splitByNewLine(String string) {
265+
return new ArrayList<>(Arrays.asList(string.split("\n", -1)));
266+
}
267+
268+
public static List<String> splitByNewLine(String string, String lineStarter) {
269+
List<String> lines = new ArrayList<>(Arrays.asList(string.split("\n", -1)));
270+
lines.replaceAll(s -> lineStarter + s);
271+
return lines;
272+
}
273+
263274
public static double random(double min, double max) {
264275
return Math.random() * (max - min) + min;
265276
}
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
package net.swofty.commons.bedwars;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.time.DayOfWeek;
7+
import java.time.ZoneOffset;
8+
import java.time.ZonedDateTime;
9+
import java.time.temporal.TemporalAdjusters;
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
13+
@Getter
14+
public class BedWarsModeStats {
15+
private final Map<String, Long> wins;
16+
private final Map<String, Long> finalKills;
17+
private final Map<String, Long> bedsBroken;
18+
private final Map<String, Long> losses;
19+
private final Map<String, Long> bedsLost;
20+
private final Map<String, Long> kills;
21+
private final Map<String, Long> deaths;
22+
private final Map<String, Long> finalDeaths;
23+
private final Map<String, Long> winstreaks;
24+
25+
@Setter private long dailyResetTimestamp;
26+
@Setter private long weeklyResetTimestamp;
27+
@Setter private long monthlyResetTimestamp;
28+
29+
public BedWarsModeStats() {
30+
this.wins = new HashMap<>();
31+
this.finalKills = new HashMap<>();
32+
this.bedsBroken = new HashMap<>();
33+
this.losses = new HashMap<>();
34+
this.bedsLost = new HashMap<>();
35+
this.kills = new HashMap<>();
36+
this.deaths = new HashMap<>();
37+
this.finalDeaths = new HashMap<>();
38+
this.winstreaks = new HashMap<>();
39+
initializeResetTimestamps();
40+
}
41+
42+
public BedWarsModeStats(Map<String, Long> wins, Map<String, Long> finalKills, Map<String, Long> bedsBroken,
43+
Map<String, Long> losses, Map<String, Long> bedsLost, Map<String, Long> kills,
44+
Map<String, Long> deaths, Map<String, Long> finalDeaths, Map<String, Long> winstreaks,
45+
long dailyResetTimestamp, long weeklyResetTimestamp, long monthlyResetTimestamp) {
46+
this.wins = new HashMap<>(wins);
47+
this.finalKills = new HashMap<>(finalKills);
48+
this.bedsBroken = new HashMap<>(bedsBroken);
49+
this.losses = new HashMap<>(losses);
50+
this.bedsLost = new HashMap<>(bedsLost);
51+
this.kills = new HashMap<>(kills);
52+
this.deaths = new HashMap<>(deaths);
53+
this.finalDeaths = new HashMap<>(finalDeaths);
54+
this.winstreaks = new HashMap<>(winstreaks);
55+
this.dailyResetTimestamp = dailyResetTimestamp;
56+
this.weeklyResetTimestamp = weeklyResetTimestamp;
57+
this.monthlyResetTimestamp = monthlyResetTimestamp;
58+
}
59+
60+
private void initializeResetTimestamps() {
61+
this.dailyResetTimestamp = computeNextDailyReset();
62+
this.weeklyResetTimestamp = computeNextWeeklyReset();
63+
this.monthlyResetTimestamp = computeNextMonthlyReset();
64+
}
65+
66+
public static BedWarsModeStats empty() {
67+
return new BedWarsModeStats();
68+
}
69+
70+
public void checkAndResetExpiredPeriods() {
71+
long now = System.currentTimeMillis();
72+
73+
if (now >= dailyResetTimestamp) {
74+
resetPeriod(BedwarsLeaderboardPeriod.DAILY);
75+
dailyResetTimestamp = computeNextDailyReset();
76+
}
77+
78+
if (now >= weeklyResetTimestamp) {
79+
resetPeriod(BedwarsLeaderboardPeriod.WEEKLY);
80+
weeklyResetTimestamp = computeNextWeeklyReset();
81+
}
82+
83+
if (now >= monthlyResetTimestamp) {
84+
resetPeriod(BedwarsLeaderboardPeriod.MONTHLY);
85+
monthlyResetTimestamp = computeNextMonthlyReset();
86+
}
87+
}
88+
89+
private static long computeNextDailyReset() {
90+
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
91+
ZonedDateTime nextReset = now.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
92+
return nextReset.toInstant().toEpochMilli();
93+
}
94+
95+
private static long computeNextWeeklyReset() {
96+
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
97+
ZonedDateTime nextReset = now.with(TemporalAdjusters.next(DayOfWeek.MONDAY))
98+
.withHour(0).withMinute(0).withSecond(0).withNano(0);
99+
return nextReset.toInstant().toEpochMilli();
100+
}
101+
102+
private static long computeNextMonthlyReset() {
103+
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
104+
ZonedDateTime nextReset = now.with(TemporalAdjusters.firstDayOfNextMonth())
105+
.withHour(0).withMinute(0).withSecond(0).withNano(0);
106+
return nextReset.toInstant().toEpochMilli();
107+
}
108+
109+
private String key(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
110+
return mode.getKey() + ":" + period.getKey();
111+
}
112+
113+
public long getWins(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
114+
return wins.getOrDefault(key(mode, period), 0L);
115+
}
116+
117+
public long getFinalKills(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
118+
return finalKills.getOrDefault(key(mode, period), 0L);
119+
}
120+
121+
public long getBedsBroken(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
122+
return bedsBroken.getOrDefault(key(mode, period), 0L);
123+
}
124+
125+
public long getLosses(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
126+
return losses.getOrDefault(key(mode, period), 0L);
127+
}
128+
129+
public long getBedsLost(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
130+
return bedsLost.getOrDefault(key(mode, period), 0L);
131+
}
132+
133+
public long getKills(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
134+
return kills.getOrDefault(key(mode, period), 0L);
135+
}
136+
137+
public long getDeaths(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
138+
return deaths.getOrDefault(key(mode, period), 0L);
139+
}
140+
141+
public long getFinalDeaths(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
142+
return finalDeaths.getOrDefault(key(mode, period), 0L);
143+
}
144+
145+
public long getWinstreak(BedwarsLeaderboardMode mode) {
146+
return winstreaks.getOrDefault(mode.getKey(), 0L);
147+
}
148+
149+
public void addWin(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
150+
wins.merge(key(mode, period), 1L, Long::sum);
151+
}
152+
153+
public void addFinalKill(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
154+
finalKills.merge(key(mode, period), 1L, Long::sum);
155+
}
156+
157+
public void addBedBroken(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
158+
bedsBroken.merge(key(mode, period), 1L, Long::sum);
159+
}
160+
161+
public void addLoss(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
162+
losses.merge(key(mode, period), 1L, Long::sum);
163+
}
164+
165+
public void addBedLost(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
166+
bedsLost.merge(key(mode, period), 1L, Long::sum);
167+
}
168+
169+
public void addKill(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
170+
kills.merge(key(mode, period), 1L, Long::sum);
171+
}
172+
173+
public void addDeath(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
174+
deaths.merge(key(mode, period), 1L, Long::sum);
175+
}
176+
177+
public void addFinalDeath(BedwarsLeaderboardMode mode, BedwarsLeaderboardPeriod period) {
178+
finalDeaths.merge(key(mode, period), 1L, Long::sum);
179+
}
180+
181+
public void incrementWinstreak(BedwarsLeaderboardMode mode) {
182+
winstreaks.merge(mode.getKey(), 1L, Long::sum);
183+
}
184+
185+
public void resetWinstreak(BedwarsLeaderboardMode mode) {
186+
winstreaks.put(mode.getKey(), 0L);
187+
}
188+
189+
public void recordWin(BedwarsLeaderboardMode mode) {
190+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
191+
addWin(mode, period);
192+
}
193+
incrementWinstreak(mode);
194+
}
195+
196+
public void recordFinalKill(BedwarsLeaderboardMode mode) {
197+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
198+
addFinalKill(mode, period);
199+
}
200+
}
201+
202+
public void recordBedBroken(BedwarsLeaderboardMode mode) {
203+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
204+
addBedBroken(mode, period);
205+
}
206+
}
207+
208+
public void recordLoss(BedwarsLeaderboardMode mode) {
209+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
210+
addLoss(mode, period);
211+
}
212+
resetWinstreak(mode);
213+
}
214+
215+
public void recordBedLost(BedwarsLeaderboardMode mode) {
216+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
217+
addBedLost(mode, period);
218+
}
219+
}
220+
221+
public void recordKill(BedwarsLeaderboardMode mode) {
222+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
223+
addKill(mode, period);
224+
}
225+
}
226+
227+
public void recordDeath(BedwarsLeaderboardMode mode) {
228+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
229+
addDeath(mode, period);
230+
}
231+
}
232+
233+
public void recordFinalDeath(BedwarsLeaderboardMode mode) {
234+
for (BedwarsLeaderboardPeriod period : BedwarsLeaderboardPeriod.values()) {
235+
addFinalDeath(mode, period);
236+
}
237+
}
238+
239+
public void resetPeriod(BedwarsLeaderboardPeriod period) {
240+
for (BedwarsLeaderboardMode mode : BedwarsLeaderboardMode.values()) {
241+
String k = key(mode, period);
242+
wins.remove(k);
243+
finalKills.remove(k);
244+
bedsBroken.remove(k);
245+
losses.remove(k);
246+
bedsLost.remove(k);
247+
kills.remove(k);
248+
deaths.remove(k);
249+
finalDeaths.remove(k);
250+
}
251+
}
252+
253+
public BedWarsModeStats copy() {
254+
return new BedWarsModeStats(wins, finalKills, bedsBroken,
255+
losses, bedsLost, kills, deaths, finalDeaths, winstreaks,
256+
dailyResetTimestamp, weeklyResetTimestamp, monthlyResetTimestamp);
257+
}
258+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package net.swofty.commons.bedwars;
2+
3+
import lombok.Getter;
4+
import org.jetbrains.annotations.Nullable;
5+
6+
@Getter
7+
public enum BedwarsGameType {
8+
SOLO(0, "Solo", 1, 8),
9+
DOUBLES(1, "Doubles", 2, 8),
10+
THREE_THREE_THREE_THREE(2, "3v3v3v3", 3, 4),
11+
FOUR_FOUR_FOUR_FOUR(3, "4v4v4v4", 4, 4),
12+
FOUR_FOUR(4, "4v4", 4, 2),
13+
ULTIMATE_DOUBLES(5, "Ultimate", 2, 8),
14+
ULTIMATE_FOURS(6, "Ultimate", 4, 4);
15+
16+
private final int id;
17+
private final String displayName;
18+
private final int teamSize;
19+
private final int teams;
20+
21+
BedwarsGameType(int id, String displayName, int teamSize, int teams) {
22+
this.id = id;
23+
this.displayName = displayName;
24+
this.teamSize = teamSize;
25+
this.teams = teams;
26+
}
27+
28+
public int maxPlayers() {
29+
return teamSize * teams;
30+
}
31+
32+
@Nullable
33+
public static BedwarsGameType from(String field) {
34+
for (BedwarsGameType type : values()) {
35+
if (type.name().equalsIgnoreCase(field)) {
36+
return type;
37+
}
38+
}
39+
return null;
40+
}
41+
42+
@Nullable
43+
public static BedwarsGameType fromDisplayName(String displayName) {
44+
for (BedwarsGameType type : values()) {
45+
if (type.displayName.equalsIgnoreCase(displayName)) {
46+
return type;
47+
}
48+
}
49+
return null;
50+
}
51+
52+
@Nullable
53+
public static BedwarsGameType fromId(int id) {
54+
for (BedwarsGameType type : values()) {
55+
if (type.id == id) {
56+
return type;
57+
}
58+
}
59+
return null;
60+
}
61+
62+
public boolean isDoublesSolo() {
63+
return this == SOLO || this == DOUBLES || this == ULTIMATE_DOUBLES;
64+
}
65+
}

0 commit comments

Comments
 (0)