From 0a090c8bb3b53b1bdb50750efd2a624eb5cd0a6a Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Wed, 17 Jun 2026 21:46:38 +0100 Subject: [PATCH] fix(config): keep server/forced-host defaults empty in code Move the example servers, try order, and forced hosts out of the model's field defaults and into default-velocity.yml only. Previously, removing a section caused the loader to substitute the bundled examples, which reference servers the user may not have and then fail validation. With empty code defaults, a removed or emptied section now yields an empty collection and the examples are seeded solely on first-start from the documented default file. Co-Authored-By: Claude Opus 4.8 --- .../proxy/config/ConfigurationLoader.java | 2 +- .../proxy/config/VelocityConfiguration.java | 20 +++++++++---------- .../proxy/config/ConfigurationLoaderTest.java | 20 +++++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/ConfigurationLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/config/ConfigurationLoader.java index 1b265e0d0..c6003b969 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/ConfigurationLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/ConfigurationLoader.java @@ -259,7 +259,7 @@ public final class ConfigurationLoader { public VelocityConfiguration.Servers deserialize(final Type type, final ConfigurationNode node) throws SerializationException { final Map servers = new LinkedHashMap<>(); - List attemptConnectionOrder = ImmutableList.of("lobby"); + List attemptConnectionOrder = ImmutableList.of(); for (final Map.Entry entry : node.childrenMap().entrySet()) { final String key = entry.getKey().toString(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 981efd02f..77628a043 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -472,12 +472,11 @@ public class VelocityConfiguration implements ProxyConfig { static class Servers { - private Map servers = ImmutableMap.of( - "lobby", "127.0.0.1:30066", - "factions", "127.0.0.1:30067", - "minigames", "127.0.0.1:30068" - ); - private List attemptConnectionOrder = ImmutableList.of("lobby"); + // Example entries live in default-velocity.yml, not here: the code default must stay empty so + // that a user who removes the section gets an empty map rather than resurrected examples that + // reference servers they no longer have. + private Map servers = ImmutableMap.of(); + private List attemptConnectionOrder = ImmutableList.of(); Servers() { } @@ -526,11 +525,10 @@ public class VelocityConfiguration implements ProxyConfig { static class ForcedHosts { - private Map> forcedHosts = ImmutableMap.of( - "lobby.example.com", ImmutableList.of("lobby"), - "factions.example.com", ImmutableList.of("factions"), - "minigames.example.com", ImmutableList.of("minigames") - ); + // Example entries live in default-velocity.yml, not here: the code default must stay empty so + // that removing the section yields no forced hosts rather than examples pointing at servers the + // user does not have (which would fail validation). + private Map> forcedHosts = ImmutableMap.of(); ForcedHosts() { } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/config/ConfigurationLoaderTest.java b/proxy/src/test/java/com/velocitypowered/proxy/config/ConfigurationLoaderTest.java index c5a0143d1..f56ebba1b 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/config/ConfigurationLoaderTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/config/ConfigurationLoaderTest.java @@ -179,6 +179,26 @@ class ConfigurationLoaderTest { assertEquals(secret.toString(), node.node("forwarding-secret-file").getString()); } + /** + * Removing the {@code forced-hosts}/{@code try} sections must leave them empty rather than + * resurrecting the bundled example entries, which would reference servers the user does not have + * and fail validation. + */ + @Test + void removedSectionsDoNotResurrectDefaults(@TempDir final Path dir) throws IOException { + final Path path = dir.resolve("velocity.yml"); + Files.writeString(path, """ + servers: + only: "1.2.3.4:25565" + """, StandardCharsets.UTF_8); + + final VelocityConfiguration config = ConfigurationLoader.load(path); + + assertEquals(ImmutableMap.of("only", "1.2.3.4:25565"), config.getServers()); + assertTrue(config.getForcedHosts().isEmpty()); + assertTrue(config.getAttemptConnectionOrder().isEmpty()); + } + private static void assertConfig(final VelocityConfiguration config) { assertEquals(123, config.getShowMaxPlayers()); assertFalse(config.isOnlineMode());