com.mojang.brigadier.CommandDispatcher Java Examples
The following examples show how to use
com.mojang.brigadier.CommandDispatcher.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForgeSparkPlugin.java From spark with GNU General Public License v3.0 | 7 votes |
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)); } }
Example #2
Source File: FabricSparkPlugin.java From spark with GNU General Public License v3.0 | 6 votes |
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)); } }
Example #3
Source File: CounterCommand.java From fabric-carpet with MIT License | 6 votes |
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); }
Example #4
Source File: CarpetServer.java From fabric-carpet with MIT License | 6 votes |
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); }
Example #5
Source File: CameraModeCommand.java From fabric-carpet with MIT License | 6 votes |
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); }
Example #6
Source File: TitleCommand.java From multiconnect with MIT License | 6 votes |
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))))))); }
Example #7
Source File: WhitelistCommand.java From multiconnect with MIT License | 6 votes |
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))); }
Example #8
Source File: CustomCommand.java From BoundingBoxOutlineReloaded with MIT License | 6 votes |
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); }
Example #9
Source File: ForgeServerSparkPlugin.java From spark with GNU General Public License v3.0 | 6 votes |
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"); }
Example #10
Source File: RecipeCommand.java From multiconnect with MIT License | 6 votes |
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))))); }
Example #11
Source File: PerimeterInfoCommand.java From fabric-carpet with MIT License | 6 votes |
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); }
Example #12
Source File: MixinClientPlayNetworkHandler.java From multiconnect with MIT License | 6 votes |
@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(); } }
Example #13
Source File: PlaySoundCommand.java From multiconnect with MIT License | 6 votes |
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))))))))); } }
Example #14
Source File: FabricClientSparkPlugin.java From spark with GNU General Public License v3.0 | 6 votes |
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(); } }
Example #15
Source File: TriggerCommand.java From multiconnect with MIT License | 5 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("trigger") .then(argument("objective", word()) .suggests(SuggestionProviders.ASK_SERVER) .then(literal("add") .then(argument("value", integer()) .executes(ctx -> 0))) .then(literal("set") .then(argument("value", integer()) .executes(ctx -> 0))))); }
Example #16
Source File: InfoCommand.java From fabric-carpet with MIT License | 5 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> command = literal("info"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandInfo)). then(literal("block"). then(argument("block position", BlockPosArgumentType.blockPos()). executes( (c) -> infoBlock( c.getSource(), BlockPosArgumentType.getBlockPos(c, "block position"), null)). then(literal("grep"). then(argument("regexp",greedyString()). executes( (c) -> infoBlock( c.getSource(), BlockPosArgumentType.getBlockPos(c, "block position"), getString(c, "regexp"))))))). then(literal("entity"). then(argument("entity selector", EntityArgumentType.entities()). executes( (c) -> infoEntities( c.getSource(), EntityArgumentType.getEntities(c,"entity selector"), null)). then(literal("grep"). then(argument("regexp",greedyString()). executes( (c) -> infoEntities( c.getSource(), EntityArgumentType.getEntities(c,"entity selector"), getString(c, "regexp"))))))); dispatcher.register(command); }
Example #17
Source File: ForgeClientSparkPlugin.java From spark with GNU General Public License v3.0 | 5 votes |
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(); } }
Example #18
Source File: NMS_1_14_3.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public void resendPackets(Player player) { CraftPlayer craftPlayer = (CraftPlayer) player; CraftServer craftServer = (CraftServer) Bukkit.getServer(); @SuppressWarnings("resource") net.minecraft.server.v1_14_R1.CommandDispatcher nmsDispatcher = craftServer.getServer().commandDispatcher; nmsDispatcher.a(craftPlayer.getHandle()); }
Example #19
Source File: PingCommand.java From carpet-extra with GNU Lesser General Public License v3.0 | 5 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> command = literal("ping"). requires( (player) -> CarpetExtraSettings.commandPing). executes( c -> { ServerPlayerEntity playerEntity = c.getSource().getPlayer(); int ping = playerEntity.pingMilliseconds; playerEntity.sendMessage(new LiteralText("Your ping is: " + ping + " ms")); return 1; }); dispatcher.register(command); }
Example #20
Source File: TestForBlockCommand.java From multiconnect with MIT License | 5 votes |
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))))); }
Example #21
Source File: ExecuteBenchmarks.java From brigadier with MIT License | 5 votes |
@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()); }
Example #22
Source File: GiveCommand.java From multiconnect with MIT License | 5 votes |
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))))))); }
Example #23
Source File: ClientInterop.java From BoundingBoxOutlineReloaded with MIT License | 5 votes |
public static void registerClientCommands(CommandDispatcher<ISuggestionProvider> commandDispatcher) { SeedCommand.register(commandDispatcher); SpawningSphereCommand.register(commandDispatcher); CustomCommand.register(commandDispatcher); ConfigCommand.register(commandDispatcher); StructuresCommand.register(commandDispatcher); }
Example #24
Source File: SetblockCommand.java From multiconnect with MIT License | 5 votes |
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)))))); }
Example #25
Source File: TeleportCommand.java From multiconnect with MIT License | 5 votes |
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))))); }
Example #26
Source File: LogCommand.java From fabric-carpet with MIT License | 5 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("log"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandLog)). executes((context) -> listLogs(context.getSource())). then(CommandManager.literal("clear"). executes( (c) -> unsubFromAll(c.getSource(), c.getSource().getName())). then(CommandManager.argument("player", StringArgumentType.word()). suggests( (c, b)-> suggestMatching(c.getSource().getPlayerNames(),b)). executes( (c) -> unsubFromAll(c.getSource(), getString(c, "player"))))); literalargumentbuilder.then(CommandManager.argument("log name",StringArgumentType.word()). suggests( (c, b)-> suggestMatching(LoggerRegistry.getLoggerNames(),b)). executes( (c)-> toggleSubscription(c.getSource(), c.getSource().getName(), getString(c, "log name"))). then(CommandManager.literal("clear"). executes( (c) -> unsubFromLogger( c.getSource(), c.getSource().getName(), getString(c, "log name")))). then(CommandManager.argument("option", StringArgumentType.greedyString()). suggests( (c, b) -> suggestMatching( (LoggerRegistry.getLogger(getString(c, "log name"))==null ?new String[]{} :LoggerRegistry.getLogger(getString(c, "log name")).getOptions()), b)). executes( (c) -> subscribePlayer( c.getSource(), c.getSource().getName(), getString(c, "log name"), getString(c, "option"))). then(CommandManager.argument("player", StringArgumentType.word()). suggests( (c, b) -> suggestMatching(c.getSource().getPlayerNames(),b)). executes( (c) -> subscribePlayer( c.getSource(), getString(c, "player"), getString(c, "log name"), getString(c, "option")))))); dispatcher.register(literalargumentbuilder); }
Example #27
Source File: TestForBlocksCommand.java From multiconnect with MIT License | 5 votes |
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)))))); }
Example #28
Source File: NMS_1_16_R1.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public void resendPackets(Player player) { CraftPlayer craftPlayer = (CraftPlayer) player; CraftServer craftServer = (CraftServer) Bukkit.getServer(); net.minecraft.server.v1_16_R1.CommandDispatcher nmsDispatcher = craftServer.getServer().getCommandDispatcher(); nmsDispatcher.a(craftPlayer.getHandle()); }
Example #29
Source File: NMS_1_13_2.java From 1.13-Command-API with Apache License 2.0 | 5 votes |
@Override public void resendPackets(Player player) { CraftPlayer craftPlayer = (CraftPlayer) player; CraftServer craftServer = (CraftServer) Bukkit.getServer(); net.minecraft.server.v1_13_R2.CommandDispatcher nmsDispatcher = craftServer.getServer().commandDispatcher; nmsDispatcher.a(craftPlayer.getHandle()); }
Example #30
Source File: FillCommand.java From multiconnect with MIT License | 5 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("fill") .then(argument("pos1", blockPos()) .then(argument("pos2", blockPos()) .then(argument("block", blockState()) .executes(ctx -> 0) .then(argument("oldBlockHandling", enumArg("replace", "destroy", "keep", "hollow", "outline")) .executes(ctx -> 0) .then(argument("nbt", nbtCompound()) .executes(ctx -> 0))))))); }