Add override for Publics in GameModeConfig.Schematic

This commit is contained in:
2026-10-21 08:22:05 +02:00
parent c238b9bdf2
commit c4b46e4431
3 changed files with 44 additions and 23 deletions
@@ -617,6 +617,15 @@ public final class GameModeConfig<M, W> {
*/ */
public final List<SchematicType> SubTypes; public final List<SchematicType> SubTypes;
/**
* List of publics that should be used. Mainly useful for an Event Mode
* where a subset of the regular publics should be used without duplicating
* those in the Database.
*
* @implSpec {@code []} by default, thus the GameModes publics are used.
*/
public final List<Integer> Publics;
/** /**
* Shortcut of the schematic type * Shortcut of the schematic type
* *
@@ -725,6 +734,7 @@ public final class GameModeConfig<M, W> {
Inset = new InsetConfig(loader.with("Inset")); Inset = new InsetConfig(loader.with("Inset"));
Type = null; Type = null;
SubTypesStrings = loader.getStringList("SubTypes"); SubTypesStrings = loader.getStringList("SubTypes");
Publics = loader.getIntList("Publics");
SubTypes = new ArrayList<>(); SubTypes = new ArrayList<>();
Shortcut = loader.getString("Shortcut", ""); Shortcut = loader.getString("Shortcut", "");
Material = loader.getMaterial("Material", "STONE_BUTTON"); Material = loader.getMaterial("Material", "STONE_BUTTON");
@@ -20,19 +20,14 @@
package de.steamwar.fightsystem.ai; package de.steamwar.fightsystem.ai;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightSchematic;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import java.util.List;
import java.util.Random;
public class DummyAI extends AI { public class DummyAI extends AI {
private static final Random random = new Random();
public DummyAI(FightTeam team) { public DummyAI(FightTeam team) {
super(team, SteamwarUser.get("public")); super(team, SteamwarUser.get("public"));
@@ -41,8 +36,7 @@ public class DummyAI extends AI {
@Override @Override
public SchematicNode chooseSchematic() { public SchematicNode chooseSchematic() {
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB()); return FightSchematic.getPublicSchematic().orElseThrow();
return publics.get(random.nextInt(publics.size()));
} }
@Override @Override
@@ -46,6 +46,7 @@ import org.bukkit.util.Vector;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Random; import java.util.Random;
import java.util.logging.Level; import java.util.logging.Level;
@@ -109,11 +110,18 @@ public class FightSchematic extends StateDependent {
clipboard = null; clipboard = null;
} }
@Override private static final Random random = new Random();
public void enable() {
if (FightState.getFightState() == FightState.SPECTATE) return; public static Optional<SchematicNode> getPublicSchematic() {
List<Integer> publicsOverridden = Config.GameModeConfig.Schematic.Publics;
if (!publicsOverridden.isEmpty()) {
int publicId = publicsOverridden.get(random.nextInt(publicsOverridden.size()));
SchematicNode schematicNode = SchematicNode.getSchematicNode(publicId);
if (schematicNode != null) {
return Optional.of(schematicNode);
}
}
if (clipboard == null) {
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB()); List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB());
if (publics.isEmpty()) { if (publics.isEmpty()) {
for (SchematicType type : Config.GameModeConfig.Schematic.SubTypes) { for (SchematicType type : Config.GameModeConfig.Schematic.SubTypes) {
@@ -123,17 +131,26 @@ public class FightSchematic extends StateDependent {
} }
} }
if (publics.isEmpty()) { if (publics.isEmpty()) {
return; return Optional.empty();
} }
} }
return Optional.of(publics.get(random.nextInt(publics.size())));
}
setSchematic(publics.get(new Random().nextInt(publics.size()))); @Override
public void enable() {
if (FightState.getFightState() == FightState.SPECTATE) return;
if (clipboard == null) {
Optional<SchematicNode> schematicNode = getPublicSchematic();
if (schematicNode.isEmpty()) return;
setSchematic(schematicNode.get());
} }
if (ArenaMode.AntiReplay.contains(Config.mode)) { if (ArenaMode.AntiReplay.contains(Config.mode)) {
boolean changeRotation = false; boolean changeRotation = false;
if (Config.GameModeConfig.WinConditions.contains(Winconditions.RANDOM_ROTATE)) { if (Config.GameModeConfig.WinConditions.contains(Winconditions.RANDOM_ROTATE)) {
changeRotation = new Random().nextBoolean(); changeRotation = random.nextBoolean();
usedRotate = rotate ^ changeRotation; usedRotate = rotate ^ changeRotation;
} }
if (team.isBlue()) { if (team.isBlue()) {