下面列出了org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer#com.mojang.brigadier.CommandDispatcher 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Inject(method = "onGameJoin", at = @At("RETURN"))
private void onOnGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {
if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
onSynchronizeTags(new SynchronizeTagsS2CPacket(new RegistryTagManager()));
Protocol_1_12_2 protocol = (Protocol_1_12_2) ConnectionInfo.protocol;
List<Recipe<?>> recipes = new ArrayList<>();
List<RecipeInfo<?>> recipeInfos = protocol.getCraftingRecipes();
for (int i = 0; i < recipeInfos.size(); i++) {
recipes.add(recipeInfos.get(i).create(new Identifier(String.valueOf(i))));
}
onSynchronizeRecipes(new SynchronizeRecipesS2CPacket(recipes));
CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<>();
Commands_1_12_2.registerAll(dispatcher, null);
onCommandTree(new CommandTreeS2CPacket(dispatcher.getRoot()));
TabCompletionManager.requestCommandList();
}
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("recipe")
.then(literal("give")
.then(argument("player", players())
.then(literal("*")
.executes(ctx -> 0))
.then(argument("recipe", identifier())
.suggests(SuggestionProviders.ASK_SERVER)
.executes(ctx -> 0))))
.then(literal("take")
.then(argument("player", players())
.then(literal("*")
.executes(ctx -> 0))
.then(argument("recipe", identifier())
.suggests(SuggestionProviders.ASK_SERVER)
.executes(ctx -> 0)))));
}
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) {
if (aliases.length == 0) {
return;
}
String mainName = aliases[0];
LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName)
.executes(executor)
.then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString())
.suggests(suggestor)
.executes(executor)
);
LiteralCommandNode<T> node = dispatcher.register(command);
for (int i = 1; i < aliases.length; i++) {
dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node));
}
}
public static void register(ForgeSparkMod mod, FMLServerStartingEvent event) {
MinecraftServer server = event.getServer();
ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(mod, server);
CommandDispatcher<CommandSource> dispatcher = event.getCommandDispatcher();
registerCommands(dispatcher, plugin, plugin, "spark");
PermissionAPI.registerNode("spark", DefaultPermissionLevel.OP, "Access to the spark command");
}
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
LiteralArgumentBuilder command = Commands.literal(COMMAND)
.then(BoxCommandBuilder.build(BOX))
.then(BeaconCommandBuilder.build(BEACON))
.then(LineCommandBuilder.build(LINE))
.then(SphereCommandBuilder.build(SPHERE))
.then(Commands.literal(ArgumentNames.CLEAR)
.executes(context -> {
CustomBoxProvider.clear();
CustomBeaconProvider.clear();
CustomLineProvider.clear();
CustomSphereProvider.clear();
CommandHelper.feedback(context, "bbor.commands.custom.cleared.all");
return 0;
}));
commandDispatcher.register(command);
}
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> camera = literal("c").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandCameramode)).
executes((c) -> cameraMode(c.getSource(), c.getSource().getPlayer())).
then(argument("player", EntityArgumentType.player()).
executes( (c) -> cameraMode(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));
LiteralArgumentBuilder<ServerCommandSource> survival = literal("s").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandCameramode)).
executes((c) -> survivalMode(
c.getSource(),
c.getSource().getPlayer())).
then(argument("player", EntityArgumentType.player()).
executes( (c) -> survivalMode(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));
dispatcher.register(camera);
dispatcher.register(survival);
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("whitelist")
.then(literal("on")
.executes(ctx -> 0))
.then(literal("off")
.executes(ctx -> 0))
.then(literal("list")
.executes(ctx -> 0))
.then(literal("add")
.then(argument("player", word())
.suggests(SuggestionProviders.ASK_SERVER)
.executes(ctx -> 0)))
.then(literal("remove")
.then(argument("player", word())
.suggests(SuggestionProviders.ASK_SERVER)
.executes(ctx -> 0)))
.then(literal("reload")
.executes(ctx -> 0)));
}
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("counter").executes((context)
-> listAllCounters(context.getSource(), false)).requires((player) ->
CarpetSettings.hopperCounters);
literalargumentbuilder.
then((CommandManager.literal("reset").executes( (p_198489_1_)->
resetCounter(p_198489_1_.getSource(), null))));
for (DyeColor enumDyeColor: DyeColor.values())
{
String color = enumDyeColor.toString();
literalargumentbuilder.
then((CommandManager.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
literalargumentbuilder.then(CommandManager.literal(color).
then(CommandManager.literal("reset").executes((context) ->
resetCounter(context.getSource(), color))));
literalargumentbuilder.then(CommandManager.literal(color).
then(CommandManager.literal("realtime").executes((context) ->
displayCounter(context.getSource(), color, true))));
}
dispatcher.register(literalargumentbuilder);
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("title")
.then(argument("player", players())
.then(literal("title")
.then(argument("value", text())
.executes(ctx -> 0)))
.then(literal("subtitle")
.then(argument("value", text())
.executes(ctx -> 0)))
.then(literal("actionbar")
.then(argument("value", text())
.executes(ctx -> 0)))
.then(literal("clear")
.executes(ctx -> 0))
.then(literal("reset")
.executes(ctx -> 0))
.then(literal("times")
.then(argument("fadeIn", integer())
.then(argument("stay", integer())
.then(argument("fadeOut", integer())
.executes(ctx -> 0)))))));
}
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) {
if (aliases.length == 0) {
return;
}
String mainName = aliases[0];
LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName)
.executes(executor)
.then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString())
.suggests(suggestor)
.executes(executor)
);
LiteralCommandNode<T> node = dispatcher.register(command);
for (int i = 1; i < aliases.length; i++) {
dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node));
}
}
private void checkCommandRegistered() {
CommandDispatcher<CommandSource> dispatcher = getPlayerCommandDispatcher();
if (dispatcher == null) {
return;
}
try {
if (dispatcher != this.dispatcher) {
this.dispatcher = dispatcher;
registerCommands(this.dispatcher, c -> Command.SINGLE_SUCCESS, this, "sparkc", "sparkclient");
FabricSparkGameHooks.INSTANCE.setChatSendCallback(this::onClientChat);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
for (String category : new String[] {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"}) {
dispatcher.register(literal("playsound")
.then(argument("sound", identifier())
.suggests((ctx, builder) -> CommandSource.suggestIdentifiers(Registry.SOUND_EVENT.getIds(), builder))
.then(literal(category)
.then(argument("player", players())
.executes(ctx -> 0)
.then(argument("pos", vec3())
.executes(ctx -> 0)
.then(argument("volume", floatArg(0))
.executes(ctx -> 0)
.then(argument("pitch", doubleArg(0, 2))
.executes(ctx -> 0)
.then(argument("minVolume", doubleArg(0, 1))
.executes(ctx -> 0)))))))));
}
}
public static void registerCarpetCommands(CommandDispatcher<ServerCommandSource> dispatcher)
{
TickCommand.register(dispatcher);
ProfileCommand.register(dispatcher);
CounterCommand.register(dispatcher);
LogCommand.register(dispatcher);
SpawnCommand.register(dispatcher);
PlayerCommand.register(dispatcher);
CameraModeCommand.register(dispatcher);
InfoCommand.register(dispatcher);
DistanceCommand.register(dispatcher);
PerimeterInfoCommand.register(dispatcher);
DrawCommand.register(dispatcher);
ScriptCommand.register(dispatcher);
MobAICommand.register(dispatcher);
// registering command of extensions that has registered before either server is created
// for all other, they will have them registered when they add themselves
extensions.forEach(e -> e.registerCommands(dispatcher));
currentCommandDispatcher = dispatcher;
if (FabricLoader.getInstance().isDevelopmentEnvironment())
TestCommand.register(dispatcher);
}
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
LiteralArgumentBuilder<ServerCommandSource> command = literal("perimeterinfo").
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPerimeterInfo)).
executes( (c) -> perimeterDiagnose(
c.getSource(),
new BlockPos(c.getSource().getPosition()),
null)).
then(argument("center position", BlockPosArgumentType.blockPos()).
executes( (c) -> perimeterDiagnose(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "center position"),
null)).
then(argument("mob",EntitySummonArgumentType.entitySummon()).
suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
executes( (c) -> perimeterDiagnose(
c.getSource(),
BlockPosArgumentType.getBlockPos(c, "center position"),
EntitySummonArgumentType.getEntitySummon(c, "mob").toString()
))));
dispatcher.register(command);
}
public static void registerClientCommands(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
SeedCommand.register(commandDispatcher);
SpawningSphereCommand.register(commandDispatcher);
CustomCommand.register(commandDispatcher);
ConfigCommand.register(commandDispatcher);
StructuresCommand.register(commandDispatcher);
}
public Commands(Plugin plugin, CommandDispatcher<S> dispatcher, Function<S, CommandSource> commandSourceInterface) {
this.plugin = plugin;
this.dispatcher = dispatcher;
this.commandSourceInterface = commandSourceInterface;
this.helper = new CommandHelper(plugin);
init();
}
@Override
public void registerCommands(CommandDispatcher<CommandSource> dispatcher, Set<String> serverCommands) {
super.registerCommands(dispatcher, serverCommands);
BrigadierRemover.of(dispatcher).get("advancement").remove();
BrigadierRemover.of(dispatcher).get("function").remove();
BrigadierRemover.of(dispatcher).get("recipe").remove();
BrigadierRemover.of(dispatcher).get("reload").remove();
Commands_1_12_2.registerVanilla(dispatcher, serverCommands, "achievement", AchievementCommand::register);
}
@Setup
public void setup() {
dispatcher = new CommandDispatcher<>();
dispatcher.register(literal("command").executes(c -> 0));
dispatcher.register(literal("redirect").redirect(dispatcher.getRoot()));
dispatcher.register(literal("fork").fork(dispatcher.getRoot(), o -> Lists.newArrayList(new Object(), new Object(), new Object())));
simple = dispatcher.parse("command", new Object());
singleRedirect = dispatcher.parse("redirect command", new Object());
forkedRedirect = dispatcher.parse("fork command", new Object());
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("give")
.then(argument("player", players())
.then(argument("item", item())
.executes(ctx -> 0)
.then(argument("count", integer(1, 64))
.executes(ctx -> 0)
.then(argument("damage", integer(0, Short.MAX_VALUE))
.executes(ctx -> 0)
.then(argument("nbt", nbtCompound())
.executes(ctx -> 0)))))));
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("testforblock")
.then(argument("pos", blockPos())
.then(argument("block", testBlockState())
.executes(ctx -> 0)
.then(argument("nbt", nbtCompound())
.executes(ctx -> 0)))));
}
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
LiteralArgumentBuilder command = Commands.literal(COMMAND)
.then(Commands.literal(LOAD)
.executes(context -> {
LoadSavesScreen.show();
return 0;
}))
.then(Commands.literal(ArgumentNames.CLEAR)
.executes(context -> {
ClientInterop.clearStructures();
return 0;
}));
commandDispatcher.register(command);
}
public static void registerAll(CommandDispatcher<CommandSource> dispatcher, Set<String> serverCommands) {
((Protocol_1_12_2) ConnectionInfo.protocol).registerCommands(dispatcher, serverCommands);
if (serverCommands != null) {
for (String command : serverCommands) {
if (dispatcher.getRoot().getChild(command) == null) {
dispatcher.register(literal(command)
.executes(ctx -> 0)
.then(argument("args", StringArgumentType.greedyString())
.suggests(SuggestionProviders.ASK_SERVER)
.executes(ctx -> 0)));
}
}
}
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("stopsound")
.then(argument("player", players())
.executes(ctx -> 0)
.then(argument("category", enumArg("master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"))
.executes(ctx -> 0)
.then(argument("sound", identifier())
.suggests((ctx, builder) -> CommandSource.suggestIdentifiers(Registry.SOUND_EVENT.getIds(), builder))
.executes(ctx -> 0)))));
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("debug")
.then(literal("start")
.executes(ctx -> 0))
.then(literal("stop")
.executes(ctx -> 0)));
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("effect")
.then(argument("target", entities())
.then(literal("clear")
.executes(ctx -> 0))
.then(argument("effect", mobEffect())
.executes(ctx -> 0)
.then(argument("seconds", integer(0, 1000000))
.executes(ctx -> 0)
.then(argument("amplifier", integer(0, 255))
.executes(ctx -> 0)
.then(argument("hideParticles", bool())
.executes(ctx -> 0)))))));
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("replaceitem")
.then(literal("block")
.then(argument("pos", blockPos())
.then(tail())))
.then(literal("entity")
.then(argument("target", entities())
.then(tail()))));
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("teleport")
.then(argument("victim", entities())
.then(argument("pos", blockPos())
.executes(ctx -> 0)
.then(argument("rot", rotation())
.executes(ctx -> 0)))));
}
private void checkCommandRegistered() {
CommandDispatcher<ISuggestionProvider> dispatcher = getPlayerCommandDispatcher();
if (dispatcher == null) {
return;
}
try {
if (dispatcher != this.dispatcher) {
this.dispatcher = dispatcher;
registerCommands(this.dispatcher, context -> Command.SINGLE_SUCCESS, this, "sparkc", "sparkclient");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("setblock")
.then(argument("pos", blockPos())
.then(argument("block", blockState())
.executes(ctx -> 0)
.then(argument("oldBlockHandling", enumArg("replace", "destroy", "keep"))
.executes(ctx -> 0)
.then(argument("nbt", nbtCompound())
.executes(ctx -> 0))))));
}
public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(literal("testforblocks")
.then(argument("pos1", blockPos())
.then(argument("pos2", blockPos())
.then(argument("pos", blockPos())
.executes(ctx -> 0)
.then(argument("mode", enumArg("masked", "all"))
.executes(ctx -> 0))))));
}