mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-06-21 09:47:44 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -259,7 +259,7 @@ public final class ConfigurationLoader {
|
||||
public VelocityConfiguration.Servers deserialize(final Type type, final ConfigurationNode node)
|
||||
throws SerializationException {
|
||||
final Map<String, String> servers = new LinkedHashMap<>();
|
||||
List<String> attemptConnectionOrder = ImmutableList.of("lobby");
|
||||
List<String> attemptConnectionOrder = ImmutableList.of();
|
||||
for (final Map.Entry<Object, ? extends ConfigurationNode> entry
|
||||
: node.childrenMap().entrySet()) {
|
||||
final String key = entry.getKey().toString();
|
||||
|
||||
@@ -472,12 +472,11 @@ public class VelocityConfiguration implements ProxyConfig {
|
||||
|
||||
static class Servers {
|
||||
|
||||
private Map<String, String> servers = ImmutableMap.of(
|
||||
"lobby", "127.0.0.1:30066",
|
||||
"factions", "127.0.0.1:30067",
|
||||
"minigames", "127.0.0.1:30068"
|
||||
);
|
||||
private List<String> 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<String, String> servers = ImmutableMap.of();
|
||||
private List<String> attemptConnectionOrder = ImmutableList.of();
|
||||
|
||||
Servers() {
|
||||
}
|
||||
@@ -526,11 +525,10 @@ public class VelocityConfiguration implements ProxyConfig {
|
||||
|
||||
static class ForcedHosts {
|
||||
|
||||
private Map<String, List<String>> 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<String, List<String>> forcedHosts = ImmutableMap.of();
|
||||
|
||||
ForcedHosts() {
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user