Fix world border config loading and phase transition logic

Made DEFAULT_SIZE in GameConfig mutable and ensured it updates dynamically from the configuration. Corrected phase transition logic in RunningGame to prevent potential out-of-bounds errors. Updated capture radius and build version.
This commit is contained in:
Teriuihi 2025-02-09 04:30:19 +01:00
parent 4f8a7a0416
commit 4af509eb5f
3 changed files with 8 additions and 6 deletions

View File

@ -49,7 +49,7 @@ public class GameConfig extends AbstractConfig {
public static class WORLD_BORDER { public static class WORLD_BORDER {
private static final String prefix = "world-border."; private static final String prefix = "world-border.";
public static final double DEFAULT_SIZE = 140; public static double DEFAULT_SIZE = 140;
private static final HashMap<GamePhase, WorldBorderSettings> GAME_PHASE_WORLD_BORDER = new HashMap<>(); private static final HashMap<GamePhase, WorldBorderSettings> GAME_PHASE_WORLD_BORDER = new HashMap<>();
public static HashMap<GamePhase, WorldBorderSettings> getGAME_PHASE_WORLD_BORDER() { public static HashMap<GamePhase, WorldBorderSettings> getGAME_PHASE_WORLD_BORDER() {
@ -73,6 +73,8 @@ public class GameConfig extends AbstractConfig {
GAME_PHASE_WORLD_BORDER.put(phase, new WorldBorderSettings(worldBorderType, size)); GAME_PHASE_WORLD_BORDER.put(phase, new WorldBorderSettings(worldBorderType, size));
log.debug("Set {} phase world border type to {} blocks", phase.name(), size); log.debug("Set {} phase world border type to {} blocks", phase.name(), size);
} }
DEFAULT_SIZE = config.getDouble(prefix, "default-size", DEFAULT_SIZE);
} }
} }
@ -83,7 +85,7 @@ public class GameConfig extends AbstractConfig {
public static double x = 0; public static double x = 0;
public static double y = 0; public static double y = 0;
public static double z = 0; public static double z = 0;
public static double CAPTURE_RADIUS = 7; public static double CAPTURE_RADIUS = 5;
public static int WINNING_SCORE = 50; public static int WINNING_SCORE = 50;
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -34,7 +34,7 @@ public class RunningGame implements Runnable {
@Override @Override
public void run() { public void run() {
try { try {
GamePhase nextPhase = GamePhase.values().length < currentPhase.ordinal() ? null : GamePhase.values()[currentPhase.ordinal() + 1]; GamePhase nextPhase = (currentPhase.ordinal() + 1 < GamePhase.values().length) ? GamePhase.values()[currentPhase.ordinal() + 1] : null;
if (phaseStartTime == null) { if (phaseStartTime == null) {
phaseStartTime = Instant.now(); phaseStartTime = Instant.now();
nextPhaseActions(null, currentPhase, nextPhase); nextPhaseActions(null, currentPhase, nextPhase);
@ -42,7 +42,7 @@ public class RunningGame implements Runnable {
if (Duration.between(phaseStartTime, Instant.now()).compareTo(phaseDurations.get(currentPhase)) >= 0) { if (Duration.between(phaseStartTime, Instant.now()).compareTo(phaseDurations.get(currentPhase)) >= 0) {
GamePhase previousPhase = currentPhase; GamePhase previousPhase = currentPhase;
currentPhase = GamePhase.values()[currentPhase.ordinal() + 1]; currentPhase = GamePhase.values()[currentPhase.ordinal() + 1]; //TODO fix this running out of bounds
nextPhaseActions(previousPhase, currentPhase, nextPhase); nextPhaseActions(previousPhase, currentPhase, nextPhase);
phaseStartTime = Instant.now(); phaseStartTime = Instant.now();
} else if (nextPhase != null) { } else if (nextPhase != null) {

View File

@ -1,3 +1,3 @@
#Sat Feb 08 21:57:04 CET 2025 #Sat Feb 08 23:31:55 CET 2025
buildNumber=30 buildNumber=33
version=0.1 version=0.1