CustomCommandExecutor .java

net.minecraft.commands.execution.CustomCommandExecutor (interface, 37 lines): members: WithErrorHandling, CommandAdapter, run. imports: Command, Nullable.

net.minecraft.commands.executioninterface37 linescommon1.5 KB

API Surface (3)

void run(final T sender, final ContextChain<T> currentStep, final ChainModifiers modifiers, final ExecutionControl<T> output)
void onError(final CommandSyntaxException e, final T sender, final ChainModifiers modifiers, final @Nullable TraceCallbacks tracer)
void runGuarded(T sender, ContextChain<T> currentStep, ChainModifiers modifiers, ExecutionControl<T> output)

String literals (1)

"This function should not run"

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

CustomCommandExecutor.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.commands.execution;
2
3
import com.mojang.brigadier.Command;
4
import com.mojang.brigadier.context.CommandContext;
5
import com.mojang.brigadier.context.ContextChain;
6
import com.mojang.brigadier.exceptions.CommandSyntaxException;
7
import net.minecraft.commands.ExecutionCommandSource;
8
import org.jspecify.annotations.Nullable;
9
10
public interface CustomCommandExecutor<T> {
11
	void run(T sender, ContextChain<T> currentStep, ChainModifiers modifiers, ExecutionControl<T> output);
12
13
	interface CommandAdapter<T> extends CustomCommandExecutor<T>, Command<T> {
14
		@Override
15
		default int run(final CommandContext<T> context) throws CommandSyntaxException {
16
			throw new UnsupportedOperationException("This function should not run");
17
		}
18
	}
19
20
	abstract class WithErrorHandling<T extends ExecutionCommandSource<T>> implements CustomCommandExecutor<T> {
21
		public final void run(final T sender, final ContextChain<T> currentStep, final ChainModifiers modifiers, final ExecutionControl<T> output) {
22
			try {
23
				this.runGuarded(sender, currentStep, modifiers, output);
24
			} catch (CommandSyntaxException e) {
25
				this.onError(e, sender, modifiers, output.tracer());
26
				sender.callback().onFailure();
27
			}
28
		}
29
30
		protected void onError(final CommandSyntaxException e, final T sender, final ChainModifiers modifiers, final @Nullable TraceCallbacks tracer) {
31
			sender.handleError(e, modifiers.isForked(), tracer);
32
		}
33
34
		protected abstract void runGuarded(T sender, ContextChain<T> currentStep, ChainModifiers modifiers, ExecutionControl<T> output) throws CommandSyntaxException;
35
	}
36
}
37

Decompiled Minecraft 26.3 source of CustomCommandExecutor (net/minecraft/commands/execution/CustomCommandExecutor.java) with Mojang official mappings, stored verbatim on the site.