From 6adccfd46ace8e9d0e103fdd453cdf1480167e29 Mon Sep 17 00:00:00 2001 From: altrisi Date: Wed, 25 Jan 2023 17:54:49 +0100 Subject: [PATCH] Some minor cleanup in CarpetServer - Fully remove late registration handling - That removes the reference to the command dispatcher - Fix displaced comment - Simplify "don't mixin to register" checking --- src/main/java/carpet/CarpetServer.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/java/carpet/CarpetServer.java b/src/main/java/carpet/CarpetServer.java index 930ddff6..ea0f34c3 100644 --- a/src/main/java/carpet/CarpetServer.java +++ b/src/main/java/carpet/CarpetServer.java @@ -42,12 +42,10 @@ import net.minecraft.server.level.ServerPlayer; public class CarpetServer // static for now - easier to handle all around the code, its one anyways { public static MinecraftServer minecraft_server; - private static CommandDispatcher currentCommandDispatcher; public static CarpetScriptServer scriptServer; public static carpet.settings.SettingsManager settingsManager; // to change type to api type, can't change right now because of binary and source compat public static final List extensions = new ArrayList<>(); - // Separate from onServerLoaded, because a server can be loaded multiple times in singleplayer /** * Registers a {@link CarpetExtension} to be managed by Carpet.
* Should be called before Carpet's startup, like in Fabric Loader's @@ -58,22 +56,16 @@ public class CarpetServer // static for now - easier to handle all around the co { extensions.add(extension); // Stop the stupid practice of extensions mixing into Carpet just to register themselves - if (StackWalker.getInstance().walk(stream -> stream.anyMatch(el -> - el.getClassName() == CarpetServer.class.getName() && !el.getMethodName().equals("manageExtension") - ))) { + if (StackWalker.getInstance().walk(stream -> stream.skip(1) + .anyMatch(el -> el.getClassName() == CarpetServer.class.getName()))) + { CarpetSettings.LOG.warn(""" Extension '%s' is registering itself using a mixin into Carpet instead of a regular ModInitializer! This is stupid and will crash the game in future versions!""".formatted(extension.getClass().getSimpleName())); } - - // for extensions that come late to the party, we used to handle them, but we've been giving them warnings about - // it for a while. Cause a crash - if (currentCommandDispatcher != null) - { - throw new IllegalStateException("Extension %s tried to register too late!".formatted(extension.getClass().getSimpleName())); - } } + // Separate from onServerLoaded, because a server can be loaded multiple times in singleplayer // Gets called by Fabric Loader from a ServerModInitializer and a ClientModInitializer, in both to allow extensions // to register before this call in a ModInitializer (declared in fabric.mod.json) public static void onGameStarted() @@ -150,7 +142,6 @@ public class CarpetServer // static for now - easier to handle all around the co extensions.forEach(e -> { e.registerCommands(dispatcher, commandBuildContext); }); - currentCommandDispatcher = dispatcher; if (environment != Commands.CommandSelection.DEDICATED) PerfCommand.register(dispatcher); @@ -191,7 +182,6 @@ public class CarpetServer // static for now - easier to handle all around the co if (scriptServer != null) scriptServer.onClose(); scriptServer = null; ServerNetworkHandler.close(); - currentCommandDispatcher = null; LoggerRegistry.stopLoggers(); HUDController.resetScarpetHUDs();