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
@@ -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<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.GameModeConfig.Schematic.Type.toDB());
return publics.get(random.nextInt(publics.size()));
return FightSchematic.getPublicSchematic().orElseThrow();
}
@Override
@@ -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<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);
}
}
List<SchematicNode> 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<SchematicNode> 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> 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()) {