Skip to content

Commit 5a9f8ba

Browse files
committed
refactor: clean up generator config
1 parent 543035b commit 5a9f8ba

File tree

5 files changed

+77
-76
lines changed

5 files changed

+77
-76
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public static class MapConfiguration {
2828
private MapBounds bounds;
2929
private Map<TeamKey, MapTeam> teams;
3030
private MapLocations locations;
31-
// instead of a string, use an enum.
32-
private Map<String, GlobalGenerator> global_generator;
31+
private Map<GlobalGeneratorKey, GlobalGenerator> globalGenerator;
3332

3433
@Getter
3534
@Setter
@@ -70,6 +69,10 @@ public record TwoBlockPosition(Position feet, Position head) {
7069
public record MinMax(double min, double max) {
7170
}
7271

72+
public enum GlobalGeneratorKey {
73+
IRON, GOLD, DIAMOND, EMERALD
74+
}
75+
7376
public enum TeamKey {
7477
RED("Red", "§c", 0xFF5555),
7578
BLUE("Blue", "§9", 0x5555FF),

configuration/bedwars/maps.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@
326326
"z": 0
327327
}
328328
},
329-
"global_generator": {
330-
"diamond": {
329+
"globalGenerator": {
330+
"DIAMOND": {
331331
"amount": 1,
332332
"max": 4,
333333
"locations": [
@@ -353,7 +353,7 @@
353353
}
354354
]
355355
},
356-
"emerald": {
356+
"EMERALD": {
357357
"amount": 1,
358358
"max": 2,
359359
"locations": [
@@ -753,8 +753,8 @@
753753
"z": 0.0
754754
}
755755
},
756-
"global_generator": {
757-
"diamond": {
756+
"globalGenerator": {
757+
"DIAMOND": {
758758
"amount": 1,
759759
"max": 4,
760760
"locations": [
@@ -780,7 +780,7 @@
780780
}
781781
]
782782
},
783-
"emerald": {
783+
"EMERALD": {
784784
"amount": 1,
785785
"max": 2,
786786
"locations": [
@@ -1183,8 +1183,8 @@
11831183
"z": 3.5
11841184
}
11851185
},
1186-
"global_generator": {
1187-
"diamond": {
1186+
"globalGenerator": {
1187+
"DIAMOND": {
11881188
"amount": 1,
11891189
"max": 4,
11901190
"locations": [
@@ -1210,7 +1210,7 @@
12101210
}
12111211
]
12121212
},
1213-
"emerald": {
1213+
"EMERALD": {
12141214
"amount": 1,
12151215
"max": 2,
12161216
"locations": [
@@ -1613,8 +1613,8 @@
16131613
"z": 0.0
16141614
}
16151615
},
1616-
"global_generator": {
1617-
"diamond": {
1616+
"globalGenerator": {
1617+
"DIAMOND": {
16181618
"amount": 1,
16191619
"max": 4,
16201620
"locations": [
@@ -1640,7 +1640,7 @@
16401640
}
16411641
]
16421642
},
1643-
"emerald": {
1643+
"EMERALD": {
16441644
"amount": 1,
16451645
"max": 2,
16461646
"locations": [

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void setBoundsMax(double x, double y, double z) {
9292
}
9393

9494
public TeamConfig getOrCreateTeam(TeamKey key) {
95-
return teams.computeIfAbsent(key, k -> new TeamConfig());
95+
return teams.computeIfAbsent(key, _ -> new TeamConfig());
9696
}
9797

9898
public void clear() {
@@ -186,16 +186,16 @@ public void loadFromMapEntry(BedWarsMapsConfig.MapEntry entry) {
186186
}
187187

188188
// Load global generators
189-
if (config.getGlobal_generator() != null) {
190-
var diamondGen = config.getGlobal_generator().get("diamond");
189+
if (config.getGlobalGenerator() != null) {
190+
var diamondGen = config.getGlobalGenerator().get(BedWarsMapsConfig.GlobalGeneratorKey.DIAMOND);
191191
if (diamondGen != null) {
192192
diamondAmount = diamondGen.getAmount();
193193
diamondMax = diamondGen.getMax();
194194
if (diamondGen.getLocations() != null) {
195195
diamondGenerators.addAll(diamondGen.getLocations());
196196
}
197197
}
198-
var emeraldGen = config.getGlobal_generator().get("emerald");
198+
var emeraldGen = config.getGlobalGenerator().get(BedWarsMapsConfig.GlobalGeneratorKey.EMERALD);
199199
if (emeraldGen != null) {
200200
emeraldAmount = emeraldGen.getAmount();
201201
emeraldMax = emeraldGen.getMax();
@@ -260,25 +260,24 @@ public MapEntry toMapEntry() {
260260
config.setLocations(locations);
261261

262262
// Global generators
263-
Map<String, MapEntry.MapConfiguration.GlobalGenerator> globalGenerators = new HashMap<>();
264-
263+
Map<BedWarsMapsConfig.GlobalGeneratorKey, MapEntry.MapConfiguration.GlobalGenerator> globalGenerators = new HashMap<>();
265264
if (!diamondGenerators.isEmpty()) {
266265
MapEntry.MapConfiguration.GlobalGenerator diamondGen = new MapEntry.MapConfiguration.GlobalGenerator();
267266
diamondGen.setAmount(diamondAmount);
268267
diamondGen.setMax(diamondMax);
269268
diamondGen.setLocations(new ArrayList<>(diamondGenerators));
270-
globalGenerators.put("diamond", diamondGen);
269+
globalGenerators.put(BedWarsMapsConfig.GlobalGeneratorKey.DIAMOND, diamondGen);
271270
}
272271

273272
if (!emeraldGenerators.isEmpty()) {
274273
MapEntry.MapConfiguration.GlobalGenerator emeraldGen = new MapEntry.MapConfiguration.GlobalGenerator();
275274
emeraldGen.setAmount(emeraldAmount);
276275
emeraldGen.setMax(emeraldMax);
277276
emeraldGen.setLocations(new ArrayList<>(emeraldGenerators));
278-
globalGenerators.put("emerald", emeraldGen);
277+
globalGenerators.put(BedWarsMapsConfig.GlobalGeneratorKey.EMERALD, emeraldGen);
279278
}
280279

281-
config.setGlobal_generator(globalGenerators);
280+
config.setGlobalGenerator(globalGenerators);
282281
entry.setConfiguration(config);
283282

284283
return entry;

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import net.minestom.server.MinecraftServer;
66
import net.minestom.server.command.builder.arguments.ArgumentType;
77
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
8+
import net.minestom.server.entity.GameMode;
89
import net.minestom.server.entity.Player;
910
import net.minestom.server.instance.InstanceContainer;
11+
import net.swofty.commons.bedwars.map.BedWarsMapsConfig;
1012
import net.swofty.type.bedwarsconfigurator.TypeBedWarsConfiguratorLoader;
1113
import net.swofty.type.bedwarsconfigurator.autosetup.AutoSetupSession;
12-
import net.swofty.commons.bedwars.map.BedWarsMapsConfig;
1314
import net.swofty.type.generic.command.CommandParameters;
1415
import net.swofty.type.generic.command.HypixelCommand;
1516
import net.swofty.type.generic.user.categories.Rank;
@@ -87,17 +88,19 @@ public void registerUsage(MinestomCommand command) {
8788

8889
if (selectedMap.getConfiguration() != null) {
8990
session.loadFromMapEntry(selectedMap);
90-
sender.sendMessage(Component.text("§aLoaded existing configuration for: " + selectedMap.getName()));
91+
player.sendMessage(Component.text("§aLoaded existing configuration for: " + selectedMap.getName()));
9192
} else {
92-
sender.sendMessage(Component.text("§eSelected map: " + selectedMap.getName() + " §7(no existing config)"));
93+
player.sendMessage(Component.text("§eSelected map: " + selectedMap.getName() + " §7(no existing config)"));
9394
}
9495
} else {
96+
player.setGameMode(GameMode.CREATIVE);
97+
player.setFlying(true);
9598
session.setMapName(mapId);
9699
session.clear();
97100
session.setMapId(mapId);
98101
session.setMapName(mapId);
99-
sender.sendMessage(Component.text("§eLoaded unconfigured map: §f" + mapId + " §7(starting fresh)"));
100-
sender.sendMessage(Component.text("§7Use §b/autosetup §7to automatically configure the map, or set things manually."));
102+
player.sendMessage(Component.text("§eLoaded unconfigured map: §f" + mapId + " §7(starting fresh)"));
103+
player.sendMessage(Component.text("§7Use §b/autosetup §7to automatically configure the map, or set things manually."));
101104
}
102105

103106
player.setInstance(mapInstance);

0 commit comments

Comments
 (0)