From e98cf1f2b5cf924bb9268cec7d1df12282256632 Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Thu, 23 Nov 2023 20:58:09 +0500 Subject: [PATCH] Hide all unrelated config entries --- .../distanthorizons/core/config/Config.java | 10 ++++++++++ .../core/config/file/ConfigFileHandling.java | 5 +++++ .../core/config/types/ConfigEntry.java | 15 +++++++++++++-- .../distanthorizons/core/world/DhClientWorld.java | 2 +- .../distanthorizons/core/world/DhServerWorld.java | 4 ++-- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index e6eea5f1c..ef7e0a69e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -155,6 +155,7 @@ public class Config .build(); public static ConfigEntry lodChunkRenderDistanceRadius = new ConfigEntry.Builder() + .enableOnServer() .setMinDefaultMax(32, 128, 4096) .comment("The radius of the mod's render distance. (measured in chunks)") .setPerformance(EConfigEntryPerformance.HIGH) @@ -660,6 +661,7 @@ public class Config public static class WorldGenerator { public static ConfigEntry enableDistantGeneration = new ConfigEntry.Builder() + .enableOnServer() .set(true) .comment("" + " Should Distant Horizons slowly generate LODs \n" @@ -670,6 +672,7 @@ public class Config .build(); public static ConfigEntry distantGeneratorMode = new ConfigEntry.Builder() + .enableOnServer() .set(EDhApiDistantGeneratorMode.FEATURES) .comment("" + "How detailed should LODs be generated outside the vanilla render distance? \n" @@ -711,6 +714,7 @@ public class Config .build(); public static ConfigEntry worldGenerationTimeoutLengthInSeconds = new ConfigEntry.Builder() + .enableOnServer() .setMinDefaultMax(5, 60, 60 * 10/*10 minutes*/ ) .comment("" + "How long should a world generator thread run for before timing out? \n" @@ -754,6 +758,7 @@ public class Config public static class LodBuilding { public static ConfigEntry minTimeBetweenChunkUpdatesInSeconds = new ConfigEntry.Builder() + .enableOnServer() .setMinDefaultMax(0, 1, 60) .comment("" + "Determines how long must pass between LOD chunk updates before another. \n" @@ -819,6 +824,7 @@ public class Config public static class ServerNetworking { public static ConfigEntry enableServerNetworking = new ConfigEntry.Builder() + .enableOnServer() .set(true) .comment("" + "Attention: \n" @@ -833,6 +839,7 @@ public class Config .build(); public static ConfigEntry requestRateLimit = new ConfigEntry.Builder() + .enableOnServer() .setMinDefaultMax(1, 20, 100) .comment("" + "Limits the amount of sent/processed LOD requests concurrently. \n" @@ -842,6 +849,7 @@ public class Config .build(); public static ConfigEntry enableRealTimeUpdates = new ConfigEntry.Builder() + .enableOnServer() .set(false) .comment("" + "Enables real time updates from server." @@ -849,6 +857,7 @@ public class Config .build(); public static ConfigEntry enablePostRelogUpdate = new ConfigEntry.Builder() + .enableOnServer() .set(false) .comment("" + "Enables updating of LODs after relog." @@ -856,6 +865,7 @@ public class Config .build(); public static ConfigEntry serverPort = new ConfigEntry.Builder() + .enableOnServer() .set(25049) .comment("" + "The port on the server that's used for sending LOD data." diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java index b63d5cae1..a465908ff 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java @@ -192,6 +192,8 @@ public class ConfigFileHandling public void saveEntry(ConfigEntry entry, CommentedFileConfig workConfig) { if (!entry.getAppearance().showInFile) return; + if (SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class).isDedicatedServer() && !entry.isEnabledOnServer()) + return; if (entry.getTrueValue() == null) throw new IllegalArgumentException("Entry [" + entry.getNameWCategory() + "] is null, this may be a problem with [" + configBase.modName + "]. Please contact the authors"); @@ -254,6 +256,9 @@ public class ConfigFileHandling ) return; + if (SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class).isDedicatedServer() && !entry.isEnabledOnServer()) + return; + nightConfig.setComment(entry.getNameWCategory(), " " + entry.getComment().replaceAll("\n", "\n ") + "\n "); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java index 12bb99e36..b15e5a14e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java @@ -44,6 +44,7 @@ public class ConfigEntry extends AbstractConfigType> implem private T min; private T max; private final ArrayList listenerList; + private final boolean enabledOnServer; // API control // /** @@ -57,13 +58,14 @@ public class ConfigEntry extends AbstractConfigType> implem /** Creates the entry */ - private ConfigEntry(EConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean allowApiOverride, EConfigEntryPerformance performance, ArrayList listenerList) + private ConfigEntry(EConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean enabledOnServer, boolean allowApiOverride, EConfigEntryPerformance performance, ArrayList listenerList) { super(appearance, value); this.comment = comment; this.min = min; this.max = max; + this.enabledOnServer = enabledOnServer; this.allowApiOverride = allowApiOverride; this.performance = performance; this.listenerList = listenerList; @@ -179,6 +181,8 @@ public class ConfigEntry extends AbstractConfigType> implem if (validness == 1) this.value = (T) NumberUtil.getMaximum(this.value.getClass()); } + public boolean isEnabledOnServer() { return this.enabledOnServer; } + @Override public String getComment() { return this.comment; } @Override @@ -297,6 +301,7 @@ public class ConfigEntry extends AbstractConfigType> implem private String tmpComment = null; private T tmpMin = null; private T tmpMax = null; + protected boolean tmpEnabledOnServer = false; private boolean tmpUseApiOverwrite = true; private EConfigEntryPerformance tmpPerformance = EConfigEntryPerformance.DONT_SHOW; protected ArrayList tmpIConfigListener = new ArrayList<>(); @@ -334,6 +339,12 @@ public class ConfigEntry extends AbstractConfigType> implem return this; } + public Builder enableOnServer() + { + this.tmpEnabledOnServer = true; + return this; + } + public Builder setUseApiOverwrite(boolean newUseApiOverwrite) { this.tmpUseApiOverwrite = newUseApiOverwrite; @@ -376,7 +387,7 @@ public class ConfigEntry extends AbstractConfigType> implem public ConfigEntry build() { - return new ConfigEntry<>(this.tmpAppearance, this.tmpValue, this.tmpComment, this.tmpMin, this.tmpMax, this.tmpUseApiOverwrite, this.tmpPerformance, this.tmpIConfigListener); + return new ConfigEntry<>(this.tmpAppearance, this.tmpValue, this.tmpComment, this.tmpMin, this.tmpMax, this.tmpEnabledOnServer, this.tmpUseApiOverwrite, this.tmpPerformance, this.tmpIConfigListener); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java index 9a4261939..de242b2e0 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java @@ -65,7 +65,7 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld if (Config.Client.Advanced.Multiplayer.ServerNetworking.enableServerNetworking.get()) { - // TODO server specific configs + // TODO per server configs NetworkClient networkClient = new NetworkClient(MC_CLIENT.getCurrentServerIp().split(":")[0], Config.Client.Advanced.Multiplayer.ServerNetworking.serverPort.get()); this.networkState = new ClientNetworkState(networkClient, MC_CLIENT.getPlayerUUID()); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java index ae0ae691a..b7134364f 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java @@ -19,6 +19,7 @@ package com.seibel.distanthorizons.core.world; +import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.file.structure.LocalSaveStructure; import com.seibel.distanthorizons.core.level.DhServerLevel; import com.seibel.distanthorizons.core.level.IDhLevel; @@ -51,8 +52,7 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld this.saveStructure = new LocalSaveStructure(); this.levels = new HashMap<>(); - // TODO move to global payload once server specific configs are implemented - NetworkServer networkServer = new NetworkServer(25049); + NetworkServer networkServer = new NetworkServer(Config.Client.Advanced.Multiplayer.ServerNetworking.serverPort.get()); this.remotePlayerConnectionHandler = new RemotePlayerConnectionHandler(networkServer); LOGGER.info("Started "+DhServerWorld.class.getSimpleName()+" of type "+this.environment);