diff --git a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java index 2292ed86..7c6d369a 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java +++ b/CommonCore/SQL/src/de/steamwar/sql/GameModeConfig.java @@ -617,6 +617,15 @@ public final class GameModeConfig { */ public final List 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 Publics; + /** * Shortcut of the schematic type * @@ -725,6 +734,7 @@ public final class GameModeConfig { Inset = new InsetConfig(loader.with("Inset")); Type = null; SubTypesStrings = loader.getStringList("SubTypes"); + Publics = loader.getIntList("Publics"); SubTypes = new ArrayList<>(); Shortcut = loader.getString("Shortcut", ""); Material = loader.getMaterial("Material", "STONE_BUTTON"); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java index f4a5bfb0..f74ad6b9 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java @@ -20,19 +20,14 @@ package de.steamwar.fightsystem.ai; 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.states.FightState; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; -import java.util.List; -import java.util.Random; - public class DummyAI extends AI { - private static final Random random = new Random(); - public DummyAI(FightTeam team) { super(team, SteamwarUser.get("public")); @@ -41,8 +36,7 @@ public class DummyAI extends AI { @Override public SchematicNode chooseSchematic() { - List publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB()); - return publics.get(random.nextInt(publics.size())); + return FightSchematic.getPublicSchematic().orElseThrow(); } @Override diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index c8174349..014b9181 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -46,6 +46,7 @@ import org.bukkit.util.Vector; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.logging.Level; @@ -109,31 +110,47 @@ public class FightSchematic extends StateDependent { clipboard = null; } + private static final Random random = new Random(); + + public static Optional getPublicSchematic() { + List 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); + } + } + + List publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB()); + if (publics.isEmpty()) { + for (SchematicType type : Config.GameModeConfig.Schematic.SubTypes) { + publics = SchematicNode.getAllSchematicsOfType(0, type.toDB()); + if (!publics.isEmpty()) { + break; + } + } + if (publics.isEmpty()) { + return Optional.empty(); + } + } + return Optional.of(publics.get(random.nextInt(publics.size()))); + } + @Override public void enable() { if (FightState.getFightState() == FightState.SPECTATE) return; if (clipboard == null) { - List publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB()); - if (publics.isEmpty()) { - for (SchematicType type : Config.GameModeConfig.Schematic.SubTypes) { - publics = SchematicNode.getAllSchematicsOfType(0, type.toDB()); - if (!publics.isEmpty()) { - break; - } - } - if (publics.isEmpty()) { - return; - } - } - - setSchematic(publics.get(new Random().nextInt(publics.size()))); + Optional schematicNode = getPublicSchematic(); + if (schematicNode.isEmpty()) return; + setSchematic(schematicNode.get()); } if (ArenaMode.AntiReplay.contains(Config.mode)) { boolean changeRotation = false; if (Config.GameModeConfig.WinConditions.contains(Winconditions.RANDOM_ROTATE)) { - changeRotation = new Random().nextBoolean(); + changeRotation = random.nextBoolean(); usedRotate = rotate ^ changeRotation; } if (team.isBlue()) {