ArgProvider .java

net.minecraft.server.commands.ArgProvider (interface): members: buildList, child, wrap, access, Factory, parent, create. imports: ArgumentBuilder, Builder.

net.minecraft.server.commandsinterface55 linesserver1.9 KB

API Surface (2)

T access(final CommandContext<CommandSourceStack> context)
ArgumentBuilder<CommandSourceStack, ?> wrap(final ArgumentBuilder<CommandSourceStack, ?> parent, final Function<ArgumentBuilder<CommandSourceStack, ?>, ArgumentBuilder<CommandSourceStack, ?>> function)

Fields & Constants (2)

parent
child

Code Graph: Dependencies (3)

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

Full Source

ArgProvider.java55 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server.commands;
2
3
import com.google.common.collect.ImmutableList;
4
import com.google.common.collect.ImmutableList.Builder;
5
import com.mojang.brigadier.builder.ArgumentBuilder;
6
import com.mojang.brigadier.context.CommandContext;
7
import com.mojang.brigadier.exceptions.CommandSyntaxException;
8
import java.util.List;
9
import java.util.function.Function;
10
import java.util.function.Supplier;
11
import net.minecraft.commands.CommandSourceStack;
12
import net.minecraft.commands.Commands;
13
14
public interface ArgProvider<T> {
15
	T access(CommandContext<CommandSourceStack> context) throws CommandSyntaxException;
16
17
	ArgumentBuilder<CommandSourceStack, ?> wrap(
18
		ArgumentBuilder<CommandSourceStack, ?> parent, Function<ArgumentBuilder<CommandSourceStack, ?>, ArgumentBuilder<CommandSourceStack, ?>> function
19
	);
20
21
	static <T> ArgProvider<T> create(
22
		final String key, final Supplier<ArgumentBuilder<CommandSourceStack, ?>> child, final InCommandFunction<CommandContext<CommandSourceStack>, T> access
23
	) {
24
		return new ArgProvider<T>() {
25
			@Override
26
			public T access(final CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
27
				return access.apply(context);
28
			}
29
30
			@Override
31
			public ArgumentBuilder<CommandSourceStack, ?> wrap(
32
				final ArgumentBuilder<CommandSourceStack, ?> parent,
33
				final Function<ArgumentBuilder<CommandSourceStack, ?>, ArgumentBuilder<CommandSourceStack, ?>> function
34
			) {
35
				return parent.then(Commands.literal(key).then(function.apply(child.get())));
36
			}
37
		};
38
	}
39
40
	static <T> List<ArgProvider<T>> buildList(final String argName, final List<ArgProvider.Factory<T>> factories) {
41
		Builder<ArgProvider<T>> result = ImmutableList.builderWithExpectedSize(factories.size());
42
43
		for (ArgProvider.Factory<T> factory : factories) {
44
			result.add(factory.create(argName));
45
		}
46
47
		return result.build();
48
	}
49
50
	@FunctionalInterface
51
	interface Factory<T> {
52
		ArgProvider<T> create(String arg);
53
	}
54
}
55

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