From b82f0573cd2b5220bf1ce3fb930095774b96fc36 Mon Sep 17 00:00:00 2001 From: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Date: Sun, 4 Aug 2024 22:15:23 +1000 Subject: [PATCH] Server MOTD Substitutions --- .../com/nomiceu/nomilabs/config/LabsConfig.java | 8 ++++++++ .../nomilabs/mixin/DedicatedServerMixin.java | 16 ++++++++++++++++ .../resources/assets/nomilabs/lang/en_us.lang | 1 + 3 files changed, 25 insertions(+) diff --git a/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java b/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java index 16936886..4545d463 100644 --- a/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java +++ b/src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java @@ -475,6 +475,14 @@ public static class Advanced { @Config.LangKey("config.nomilabs.advanced.language_modify_option") public LanguageModifyOption languageModifyOption = LanguageModifyOption.LABS; + @Config.Comment({ "Whether to enable Substitutions for the Server Properties MOTD.", + "Substitutions: {version} for the Modpack Formatted Version (from 'nomilabs-version.cfg'), {mode} for the Modpack Formatted Mode (from LabsModeHelper & the PackMode Mod).", + "Note: Only the First Substitution in the String is Replaced!", + "[default: false]" }) + @Config.RequiresMcRestart + @Config.LangKey("config.nomilabs.advanced.server_motd_substitutions") + public boolean serverMotdSubstitutions = false; + public static class WindowOverrides { @Config.Comment({ "Override for the Minecraft Window Title.", diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/DedicatedServerMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/DedicatedServerMixin.java index a7d752e0..83120f60 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/DedicatedServerMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/DedicatedServerMixin.java @@ -14,12 +14,15 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; import com.nomiceu.nomilabs.NomiLabs; +import com.nomiceu.nomilabs.config.LabsConfig; +import com.nomiceu.nomilabs.config.LabsVersionConfig; import com.nomiceu.nomilabs.mixinhelper.DifficultySettableServer; import com.nomiceu.nomilabs.util.LabsDifficultyHelper; import com.nomiceu.nomilabs.util.LabsModeHelper; @@ -34,6 +37,8 @@ *

* Allows for support of calling `setDifficultyForAllWorldsAndSave`, changing difficulty and saving to * `server.properties` on the fly. + *

+ * Also replaces {mode} and {server} with Labs Values if config says so. */ @Mixin(DedicatedServer.class) public abstract class DedicatedServerMixin extends MinecraftServer implements DifficultySettableServer { @@ -56,6 +61,17 @@ public void getLockedDifficulty(CallbackInfoReturnable cir) { if (locked != null) cir.setReturnValue(locked); } + @Redirect(method = "init", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/dedicated/DedicatedServer;setMOTD(Ljava/lang/String;)V")) + public void motdSubstitutions(DedicatedServer instance, String s) { + if (!LabsConfig.advanced.serverMotdSubstitutions) return; + + NomiLabs.LOGGER.info("Enabling Labs MOTD Substitutions..."); + instance.setMOTD(s.replace("{version}", LabsVersionConfig.formattedVersion) + .replace("{mode}", LabsModeHelper.getFormattedMode())); + } + @SuppressWarnings("LoggingSimilarMessage") @Inject(method = "init", at = @At("RETURN")) public void changeInitDifficulty(CallbackInfoReturnable cir) { diff --git a/src/main/resources/assets/nomilabs/lang/en_us.lang b/src/main/resources/assets/nomilabs/lang/en_us.lang index c0d56ff2..b0de56bb 100644 --- a/src/main/resources/assets/nomilabs/lang/en_us.lang +++ b/src/main/resources/assets/nomilabs/lang/en_us.lang @@ -87,6 +87,7 @@ config.nomilabs.advanced.ignore_biomes=BIOME Missing Registry Ignore List config.nomilabs.advanced.language_modify_option=Language Tab Modifier Mode config.nomilabs.advanced.window=Minecraft Window Title Overrides config.nomilabs.advanced.difficulty=Difficulty Overrides +config.nomilabs.advanced.server_motd_substitutions=Enable Server MOTD Substitutions config.nomilabs.advanced.tiers=Quest Tier Detector Settings config.nomilabs.advanced.tiers.normal_qb_ids=Normal Mode Quest IDs