package net.minecraft.commands.execution; import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.ContextChain; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.ExecutionCommandSource; import org.jspecify.annotations.Nullable; public interface CustomCommandExecutor { void run(T sender, ContextChain currentStep, ChainModifiers modifiers, ExecutionControl output); interface CommandAdapter extends CustomCommandExecutor, Command { @Override default int run(final CommandContext context) throws CommandSyntaxException { throw new UnsupportedOperationException("This function should not run"); } } abstract class WithErrorHandling> implements CustomCommandExecutor { public final void run(final T sender, final ContextChain currentStep, final ChainModifiers modifiers, final ExecutionControl output) { try { this.runGuarded(sender, currentStep, modifiers, output); } catch (CommandSyntaxException e) { this.onError(e, sender, modifiers, output.tracer()); sender.callback().onFailure(); } } protected void onError(final CommandSyntaxException e, final T sender, final ChainModifiers modifiers, final @Nullable TraceCallbacks tracer) { sender.handleError(e, modifiers.isForked(), tracer); } protected abstract void runGuarded(T sender, ContextChain currentStep, ChainModifiers modifiers, ExecutionControl output) throws CommandSyntaxException; } }