Skip to content

Commit bcbc300

Browse files
committed
feat: unified generators and fixed stuff
1 parent ee34f73 commit bcbc300

15 files changed

Lines changed: 165 additions & 162 deletions

File tree

commons/src/main/java/net/swofty/commons/bedwars/map/BedWarsMapsConfig.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package net.swofty.commons.bedwars.map;
22

33
import lombok.Getter;
4-
import net.swofty.commons.bedwars.BedwarsGameType;
54
import lombok.Setter;
5+
import net.swofty.commons.bedwars.BedwarsGameType;
66

77
import java.util.List;
88
import java.util.Map;
@@ -24,7 +24,7 @@ public static class MapEntry {
2424
@Setter
2525
public static class MapConfiguration {
2626
private List<BedwarsGameType> types;
27-
private Map<String, TeamGeneratorConfig> generator;
27+
private GeneratorSpeed generatorSpeed;
2828
private MapBounds bounds;
2929
private Map<TeamKey, MapTeam> teams;
3030
private MapLocations locations;
@@ -45,12 +45,6 @@ public static class MapBounds {
4545
private MinMax z;
4646
}
4747

48-
@Getter
49-
@Setter
50-
public static class TeamGeneratorConfig {
51-
private int delay;
52-
private int amount;
53-
}
5448

5549
@Getter
5650
@Setter
@@ -106,18 +100,38 @@ public String chatColor() {
106100
}
107101

108102
public enum GeneratorSpeed {
109-
SLOW(0.7f),
110-
MEDIUM(1.4f),
111-
FAST(2f),
112-
SUPER_FAST(2.2f);
103+
// Base speed: 2 iron every 3 seconds (0.666... per second)
104+
SLOW(2, 60, 1, 160), // 2 iron/3s, 1 gold/8s
105+
MEDIUM(4, 60, 2, 160), // 4 iron/3s, 2 gold/8s (2x speed)
106+
FAST(6, 60, 3, 160), // 6 iron/3s, 3 gold/8s (3x speed)
107+
SUPER_FAST(7, 60, 3, 160); // 7 iron/3s, 3 gold/8s (3.3x speed)
108+
109+
@Getter
110+
private final int ironAmount; // items per drop
111+
@Getter
112+
private final int ironDelayTicks; // ticks between drops (60 ticks = 3 seconds)
113+
@Getter
114+
private final int goldAmount; // items per drop
115+
@Getter
116+
private final int goldDelayTicks; // ticks between drops (160 ticks = 8 seconds)
113117

114-
public final float ironSpeed; // per second
115118
// These values are consistent among maps
116-
public final float goldDelay = 8f;
117119
public final int diamondMax = 4;
118120
public final int emeraldMax = 2;
119-
GeneratorSpeed(float speed) {
120-
this.ironSpeed = speed;
121+
122+
GeneratorSpeed(int ironAmount, int ironDelayTicks, int goldAmount, int goldDelayTicks) {
123+
this.ironAmount = ironAmount;
124+
this.ironDelayTicks = ironDelayTicks;
125+
this.goldAmount = goldAmount;
126+
this.goldDelayTicks = goldDelayTicks;
127+
}
128+
129+
public int getIronDelaySeconds() {
130+
return ironDelayTicks / 20;
131+
}
132+
133+
public int getGoldDelaySeconds() {
134+
return goldDelayTicks / 20;
121135
}
122136
}
123137

configuration/bedwars/maps.json

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@
99
"DOUBLES",
1010
"ULTIMATE_DOUBLES"
1111
],
12-
"generator": {
13-
"iron": {
14-
"delay": 3,
15-
"amount": 2
16-
},
17-
"gold": {
18-
"delay": 8,
19-
"amount": 1
20-
}
21-
},
12+
"generatorSpeed": "SLOW",
2213
"bounds": {
2314
"x": {
2415
"min": -100,
@@ -400,16 +391,6 @@
400391
"DOUBLES",
401392
"ULTIMATE_DOUBLES"
402393
],
403-
"generator": {
404-
"gold": {
405-
"delay": 8,
406-
"amount": 1
407-
},
408-
"iron": {
409-
"delay": 3,
410-
"amount": 2
411-
}
412-
},
413394
"bounds": {
414395
"x": {
415396
"min": -100.0,
@@ -825,7 +806,8 @@
825806
}
826807
]
827808
}
828-
}
809+
},
810+
"generatorSpeed": "SLOW"
829811
}
830812
},
831813
{
@@ -837,16 +819,6 @@
837819
"DOUBLES",
838820
"ULTIMATE_DOUBLES"
839821
],
840-
"generator": {
841-
"gold": {
842-
"delay": 8,
843-
"amount": 1
844-
},
845-
"iron": {
846-
"delay": 3,
847-
"amount": 2
848-
}
849-
},
850822
"bounds": {
851823
"x": {
852824
"min": -100.0,
@@ -1264,7 +1236,8 @@
12641236
}
12651237
]
12661238
}
1267-
}
1239+
},
1240+
"generatorSpeed": "SLOW"
12681241
}
12691242
},
12701243
{
@@ -1276,16 +1249,6 @@
12761249
"DOUBLES",
12771250
"ULTIMATE_DOUBLES"
12781251
],
1279-
"generator": {
1280-
"gold": {
1281-
"delay": 8,
1282-
"amount": 1
1283-
},
1284-
"iron": {
1285-
"delay": 3,
1286-
"amount": 2
1287-
}
1288-
},
12891252
"bounds": {
12901253
"x": {
12911254
"min": -100.0,
@@ -1703,7 +1666,8 @@
17031666
}
17041667
]
17051668
}
1706-
}
1669+
},
1670+
"generatorSpeed": "SLOW"
17071671
}
17081672
}
17091673
]

type.bedwarsconfigurator/src/main/java/net/swofty/type/bedwarsconfigurator/autosetup/AutoSetupSession.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ public class AutoSetupSession {
2424
private final Map<TeamKey, TeamConfig> teams = new EnumMap<>(TeamKey.class);
2525
private final List<Position> diamondGenerators = new ArrayList<>();
2626
private final List<Position> emeraldGenerators = new ArrayList<>();
27-
private int ironDelay = 3;
28-
private int ironAmount = 2;
29-
private int goldDelay = 8;
30-
private int goldAmount = 1;
27+
private GeneratorSpeed generatorSpeed = GeneratorSpeed.SLOW;
3128
private int diamondAmount = 1;
3229
private int diamondMax = 4;
3330
private int emeraldAmount = 1;
@@ -93,10 +90,7 @@ public void clear() {
9390
teams.clear();
9491
diamondGenerators.clear();
9592
emeraldGenerators.clear();
96-
ironDelay = 3;
97-
ironAmount = 2;
98-
goldDelay = 8;
99-
goldAmount = 1;
93+
generatorSpeed = GeneratorSpeed.SLOW;
10094
diamondAmount = 1;
10195
diamondMax = 4;
10296
emeraldAmount = 1;
@@ -137,17 +131,8 @@ public void loadFromMapEntry(BedWarsMapsConfig.MapEntry entry) {
137131
}
138132

139133
// Load generator settings
140-
if (config.getGenerator() != null) {
141-
var ironGen = config.getGenerator().get("iron");
142-
if (ironGen != null) {
143-
ironDelay = ironGen.getDelay();
144-
ironAmount = ironGen.getAmount();
145-
}
146-
var goldGen = config.getGenerator().get("gold");
147-
if (goldGen != null) {
148-
goldDelay = goldGen.getDelay();
149-
goldAmount = goldGen.getAmount();
150-
}
134+
if (config.getGeneratorSpeed() != null) {
135+
generatorSpeed = config.getGeneratorSpeed();
151136
}
152137

153138
// Load teams
@@ -217,17 +202,7 @@ public MapEntry toMapEntry() {
217202
config.setTypes(new ArrayList<>(gameTypes));
218203

219204
// Generator config
220-
Map<String, MapEntry.MapConfiguration.TeamGeneratorConfig> generatorConfig = new HashMap<>();
221-
MapEntry.MapConfiguration.TeamGeneratorConfig ironConfig = new MapEntry.MapConfiguration.TeamGeneratorConfig();
222-
ironConfig.setDelay(ironDelay);
223-
ironConfig.setAmount(ironAmount);
224-
generatorConfig.put("iron", ironConfig);
225-
226-
MapEntry.MapConfiguration.TeamGeneratorConfig goldConfig = new MapEntry.MapConfiguration.TeamGeneratorConfig();
227-
goldConfig.setDelay(goldDelay);
228-
goldConfig.setAmount(goldAmount);
229-
generatorConfig.put("gold", goldConfig);
230-
config.setGenerator(generatorConfig);
205+
config.setGeneratorSpeed(generatorSpeed);
231206

232207
// Bounds
233208
if (hasBounds()) {

type.bedwarsconfigurator/src/main/java/net/swofty/type/bedwarsconfigurator/commands/AutoSetupCommand.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minestom.server.instance.Instance;
1313
import net.swofty.commons.bedwars.BedwarsGameType;
1414
import net.swofty.commons.bedwars.map.BedWarsMapsConfig;
15+
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.GeneratorSpeed;
1516
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.PitchYawPosition;
1617
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.Position;
1718
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.TeamKey;
@@ -598,17 +599,43 @@ private void registerMapInfoCommand(MinestomCommand command) {
598599
}
599600

600601
private void registerGeneratorSettingsCommand(MinestomCommand command) {
602+
// Speed setting command
603+
var speedArg = ArgumentType.String("speed");
604+
speedArg.setSuggestionCallback((sender, ctx, suggestion) -> {
605+
suggestion.addEntry(new SuggestionEntry("SLOW"));
606+
suggestion.addEntry(new SuggestionEntry("MEDIUM"));
607+
suggestion.addEntry(new SuggestionEntry("FAST"));
608+
suggestion.addEntry(new SuggestionEntry("SUPER_FAST"));
609+
});
610+
611+
command.addSyntax((sender, context) -> {
612+
if (!(sender instanceof Player player)) return;
613+
if (!permissionCheck(sender)) return;
614+
615+
String speedStr = context.get(speedArg);
616+
AutoSetupSession session = AutoSetupSession.getOrCreate(player.getUuid(), player.getInstance());
617+
618+
try {
619+
GeneratorSpeed speed = GeneratorSpeed.valueOf(speedStr.toUpperCase());
620+
session.setGeneratorSpeed(speed);
621+
player.sendMessage(Component.text("§aSet generator speed to " + speed.name() +
622+
" (" + speed.getIronAmount() + " iron/" + speed.getIronDelaySeconds() + "s, " +
623+
speed.getGoldAmount() + " gold/" + speed.getGoldDelaySeconds() + "s)"));
624+
} catch (IllegalArgumentException e) {
625+
player.sendMessage(Component.text("§cInvalid speed: " + speedStr));
626+
}
627+
628+
}, ArgumentType.Literal("generator"), ArgumentType.Literal("speed"), speedArg);
629+
630+
// Diamond/Emerald settings (unchanged)
601631
var genTypeArg = ArgumentType.String("gentype");
602632
genTypeArg.setSuggestionCallback((sender, ctx, suggestion) -> {
603-
suggestion.addEntry(new SuggestionEntry("iron"));
604-
suggestion.addEntry(new SuggestionEntry("gold"));
605633
suggestion.addEntry(new SuggestionEntry("diamond"));
606634
suggestion.addEntry(new SuggestionEntry("emerald"));
607635
});
608636

609637
var settingArg = ArgumentType.String("setting");
610638
settingArg.setSuggestionCallback((sender, ctx, suggestion) -> {
611-
suggestion.addEntry(new SuggestionEntry("delay"));
612639
suggestion.addEntry(new SuggestionEntry("amount"));
613640
suggestion.addEntry(new SuggestionEntry("max"));
614641
});
@@ -626,14 +653,6 @@ private void registerGeneratorSettingsCommand(MinestomCommand command) {
626653
AutoSetupSession session = AutoSetupSession.getOrCreate(player.getUuid(), player.getInstance());
627654

628655
switch (genType.toLowerCase()) {
629-
case "iron" -> {
630-
if (setting.equals("delay")) session.setIronDelay(value);
631-
else if (setting.equals("amount")) session.setIronAmount(value);
632-
}
633-
case "gold" -> {
634-
if (setting.equals("delay")) session.setGoldDelay(value);
635-
else if (setting.equals("amount")) session.setGoldAmount(value);
636-
}
637656
case "diamond" -> {
638657
if (setting.equals("amount")) session.setDiamondAmount(value);
639658
else if (setting.equals("max")) session.setDiamondMax(value);

type.bedwarsgame/src/main/java/net/swofty/type/bedwarsgame/events/ActionGameDeath.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
import net.minestom.server.tag.Tag;
2121
import net.minestom.server.timer.Task;
2222
import net.minestom.server.timer.TaskSchedule;
23+
import net.swofty.commons.bedwars.map.BedWarsMapsConfig;
24+
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.MapTeam;
25+
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.TeamKey;
2326
import net.swofty.type.bedwarsgame.TypeBedWarsGameLoader;
2427
import net.swofty.type.bedwarsgame.game.Game;
2528
import net.swofty.type.bedwarsgame.game.GameStatus;
2629
import net.swofty.type.bedwarsgame.shop.impl.AxeShopItem;
2730
import net.swofty.type.bedwarsgame.shop.impl.PickaxeShopItem;
2831
import net.swofty.type.bedwarsgame.user.BedWarsPlayer;
29-
import net.swofty.commons.bedwars.map.BedWarsMapsConfig;
30-
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.MapTeam;
31-
import net.swofty.commons.bedwars.map.BedWarsMapsConfig.TeamKey;
3232
import net.swofty.type.generic.event.EventNodes;
3333
import net.swofty.type.generic.event.HypixelEvent;
3434
import net.swofty.type.generic.event.HypixelEventClass;
@@ -172,9 +172,19 @@ public void run(PlayerDeathEvent event) {
172172
}
173173

174174
String teamName = player.getTag(Tag.String("team"));
175+
TeamKey teamKey = game.getTeamManager().getTeamKeyByName(teamName);
176+
if (teamName != null && teamKey == null) {
177+
Logger.warn("Player {} has team tag '{}' that does not match any TeamKey", player.getUsername(), teamName);
178+
}
175179
TextColor victimTeamTextColor = NamedTextColor.GRAY;
180+
if (teamKey != null) {
181+
TextColor parsedColor = NamedTextColor.NAMES.value(teamKey.chatColor().toLowerCase());
182+
if (parsedColor != null) {
183+
victimTeamTextColor = parsedColor;
184+
}
185+
}
176186

177-
boolean bedExists = game.getTeamManager().getTeamBedStatus().getOrDefault(teamName, false);
187+
boolean bedExists = teamKey != null && game.getTeamManager().isBedAlive(teamKey);
178188

179189
Component deathMessage = calculateDeathMessage(player, victimTeamTextColor);
180190

@@ -218,12 +228,9 @@ public void run(PlayerDeathEvent event) {
218228
player.teleport(new Pos(waitingPos.x(), waitingPos.y(), waitingPos.z()));
219229
player.setGameMode(GameMode.ADVENTURE);
220230
} else {
221-
TeamKey playerTeamKey = game.getTeamManager().getTeamKeyByName(teamName);
222-
MapTeam playerTeam = playerTeamKey != null
223-
? game.getMapEntry().getConfiguration().getTeams().get(playerTeamKey)
224-
: null;
231+
MapTeam playerTeam = game.getMapEntry().getConfiguration().getTeams().get(teamKey);
225232

226-
if (playerTeam != null && playerTeamKey != null) {
233+
if (playerTeam != null) {
227234
BedWarsMapsConfig.PitchYawPosition spawnPos = playerTeam.getSpawn();
228235
player.teleport(new Pos(spawnPos.x(), spawnPos.y(), spawnPos.z(), spawnPos.pitch(), spawnPos.yaw()));
229236
player.setGameMode(GameMode.SURVIVAL);
@@ -245,7 +252,7 @@ public void run(PlayerDeathEvent event) {
245252
}
246253

247254
// equip the player with team armor
248-
game.getTeamManager().equipTeamArmor(player, playerTeamKey);
255+
game.getTeamManager().equipTeamArmor(player, teamKey);
249256

250257
Integer protectionLevel = player.getTag(Tag.Integer("upgrade_reinforced_armor"));
251258
if (protectionLevel != null) {

0 commit comments

Comments
 (0)