From 26acbf92e1e05261399b7314450c50928d6cca7f Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:01:16 -0700 Subject: [PATCH] Simplify default exception handler registration --- .../fabric/FabricServerCommandManager.java | 6 +----- .../internal/ModdedExceptionHandler.java | 21 +++++++++++++++++-- .../neoforge/NeoForgeCommandManager.java | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java index df617303..82b86eee 100644 --- a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java +++ b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java @@ -107,11 +107,7 @@ public FabricServerCommandManager( } ModdedParserMappings.registerServer(this); - ModdedExceptionHandler.registerDefaults( - this, - CommandSourceStack::sendFailure, - CommandSourceStack::getTextName - ); + ModdedExceptionHandler.registerDefaults(this); } /** diff --git a/cloud-minecraft-modded-common/src/main/java/org/incendo/cloud/minecraft/modded/internal/ModdedExceptionHandler.java b/cloud-minecraft-modded-common/src/main/java/org/incendo/cloud/minecraft/modded/internal/ModdedExceptionHandler.java index 152a2d1b..70c0fbf3 100644 --- a/cloud-minecraft-modded-common/src/main/java/org/incendo/cloud/minecraft/modded/internal/ModdedExceptionHandler.java +++ b/cloud-minecraft-modded-common/src/main/java/org/incendo/cloud/minecraft/modded/internal/ModdedExceptionHandler.java @@ -30,6 +30,7 @@ import java.util.function.BiConsumer; import java.util.function.Function; import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; @@ -40,6 +41,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.framework.qual.DefaultQualifier; import org.incendo.cloud.CommandManager; +import org.incendo.cloud.brigadier.BrigadierManagerHolder; import org.incendo.cloud.exception.ArgumentParseException; import org.incendo.cloud.exception.CommandExecutionException; import org.incendo.cloud.exception.InvalidCommandSenderException; @@ -81,17 +83,32 @@ default void handle(final ExceptionContext context) throws Throwable { */ void handle(S source, C sender, T throwable) throws Throwable; + /** + * Registers the default handlers. + * + * @param commandManager the command manager + * @param command manager type + * @param command sender type + */ + static & BrigadierManagerHolder> void registerDefaults( + final M commandManager + ) { + registerDefaults(commandManager, CommandSourceStack::sendFailure, CommandSourceStack::getTextName); + } + /** * Registers the default handlers. * * @param commandManager the command manager * @param sendError error message sender * @param getName name getter + * @param command manager type * @param command sender type * @param command source type */ - static void registerDefaults( - final CommandManager commandManager, + static & BrigadierManagerHolder> void registerDefaults( + final M commandManager, final BiConsumer sendError, final Function getName ) { diff --git a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java index e835771c..b3bcac3c 100644 --- a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java +++ b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java @@ -70,7 +70,7 @@ protected NeoForgeCommandManager( this.senderMapper.map(dummyCommandSourceProvider.get()), this ), senderMapper); - ModdedExceptionHandler.registerDefaults(this, CommandSourceStack::sendFailure, CommandSourceStack::getTextName); + ModdedExceptionHandler.registerDefaults(this); registrationHandler.initialize(this); this.captionRegistry().registerProvider(new ModdedDefaultCaptionsProvider<>()); this.registerCommandPreProcessor(new ModdedPreprocessor<>(senderMapper));