Java Code Examples for com.mojang.brigadier.CommandDispatcher#register()
The following examples show how to use
com.mojang.brigadier.CommandDispatcher#register() .
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: MobAICommand.java From fabric-carpet with MIT License | 7 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> command = literal("track"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTrackAI)). then(argument("entity type", EntitySummonArgumentType.entitySummon()). suggests( (c, b) -> suggestMatching(MobAI.availbleTypes(), b)). then(literal("clear").executes( (c) -> { MobAI.clearTracking(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type"))); return 1; } )). then(argument("aspect", StringArgumentType.word()). suggests( (c, b) -> suggestMatching(MobAI.availableFor(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type"))),b)). executes( (c) -> { MobAI.startTracking( Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type")), MobAI.TrackingType.byName(StringArgumentType.getString(c, "aspect")) ); return 1; }))); dispatcher.register(command); }
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: 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 4
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 5
Source File: TickCommand.java From fabric-carpet with MIT License | 5 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("tick"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTick)). then(literal("rate"). executes((c) -> queryTps(c.getSource())). then(argument("rate", floatArg(0.1F, 500.0F)). suggests( (c, b) -> suggestMatching(new String[]{"20.0"},b)). executes((c) -> setTps(c.getSource(), getFloat(c, "rate"))))). then(literal("warp"). executes( (c)-> setWarp(c.getSource(), 0, null)). then(argument("ticks", integer(0,4000000)). suggests( (c, b) -> suggestMatching(new String[]{"3600","72000"},b)). executes((c) -> setWarp(c.getSource(), getInteger(c,"ticks"), null)). then(argument("tail command", greedyString()). executes( (c) -> setWarp( c.getSource(), getInteger(c,"ticks"), getString(c, "tail command")))))). then(literal("freeze").executes( (c)-> toggleFreeze(c.getSource(), false)). then(literal("deep").executes( (c)-> toggleFreeze(c.getSource(), true)))). then(literal("step"). executes((c) -> step(1)). then(argument("ticks", integer(1,72000)). suggests( (c, b) -> suggestMatching(new String[]{"20"},b)). executes((c) -> step(getInteger(c,"ticks"))))). then(literal("superHot").executes( (c)-> toggleSuperHot(c.getSource()))). then(literal("health"). executes( (c) -> healthReport(c.getSource(), 100)). then(argument("ticks", integer(20,24000)). executes( (c) -> healthReport(c.getSource(), getInteger(c, "ticks"))))). then(literal("entities"). executes((c) -> healthEntities(c.getSource(), 100)). then(argument("ticks", integer(20,24000)). executes((c) -> healthEntities(c.getSource(), getInteger(c, "ticks"))))); dispatcher.register(literalargumentbuilder); }
Example 6
Source File: SpawningSphereCommand.java From BoundingBoxOutlineReloaded with MIT License | 5 votes |
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) { LiteralArgumentBuilder command = Commands.literal(COMMAND) .then(Commands.literal(ArgumentNames.SET) .then(Commands.argument(ArgumentNames.POS, Arguments.point()) .executes(SpawningSphereCommand::setSphere)) .executes(SpawningSphereCommand::setSphere)) .then(Commands.literal(ArgumentNames.CLEAR) .executes(context -> { boolean cleared = SpawningSphereProvider.clear(); String format = cleared ? "bbor.commands.spawningSphere.cleared" : "bbor.commands.spawningSphere.notSet"; CommandHelper.feedback(context, format); return 0; })) .then(Commands.literal(CALCULATE_SPAWNABLE) .executes(context -> { if (!SpawningSphereProvider.hasSpawningSphereInDimension(Player.getDimensionId())) { CommandHelper.feedback(context, "bbor.commands.spawningSphere.notSet"); return 0; } Counts counts = new Counts(); World world = Minecraft.getInstance().world; SpawningSphereProvider.calculateSpawnableSpacesCount(pos -> { counts.spawnable++; if (world.getLightFor(LightType.SKY, pos) > 7) counts.nightSpawnable++; }); SpawningSphereProvider.setSpawnableSpacesCount(counts.spawnable); CommandHelper.feedback(context, "bbor.commands.spawningSphere.calculated", String.format("%,d", counts.spawnable), String.format("%,d", counts.nightSpawnable)); return 0; })); commandDispatcher.register(command); }
Example 7
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 8
Source File: ReplaceItemCommand.java From multiconnect with MIT License | 5 votes |
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())))); }
Example 9
Source File: EffectCommand.java From multiconnect with MIT License | 5 votes |
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))))))); }
Example 10
Source File: WorldborderCommand.java From multiconnect with MIT License | 5 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("worldborder") .then(literal("set") .then(argument("sizeInBlocks", doubleArg(1, 6E7)) .executes(ctx -> 0) .then(argument("timeInSeconds", longArg(0, Long.MAX_VALUE / 1000)) .executes(ctx -> 0)))) .then(literal("center") .then(argument("pos", vec2()) .executes(ctx -> 0))) .then(literal("damage") .then(literal("buffer") .then(argument("sizeInBlocks", doubleArg(0)) .executes(ctx -> 0))) .then(literal("amount") .then(argument("damagePerBlock", doubleArg(0)) .executes(ctx -> 0)))) .then(literal("warning") .then(literal("time") .then(argument("seconds", integer(0)) .executes(ctx -> 0))) .then(literal("distance") .then(argument("warningDistance", integer(0))))) .then(literal("get") .executes(ctx -> 0)) .then(literal("add") .then(argument("sizeInBlocks", doubleArg(-6E7, 6E7)) .executes(ctx -> 0) .then(argument("timeInSeconds", longArg(0, Long.MAX_VALUE / 1000)) .executes(ctx -> 0))))); }
Example 11
Source File: XPCommand.java From multiconnect with MIT License | 5 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("xp") .then(argument("amount", xp()) .executes(ctx -> 0) .then(argument("player", players()) .executes(ctx -> 0)))); }
Example 12
Source File: ClearCommand.java From multiconnect with MIT License | 5 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("clear") .executes(ctx -> 0) .then(argument("player", players()) .executes(ctx -> 0) .then(argument("item", item()) .executes(ctx -> 0) .then(argument("damage", integer(-1)) .executes(ctx -> 0) .then(argument("maxCount", integer(-1)) .executes(ctx -> 0) .then(argument("nbt", nbtCompound()) .executes(ctx -> 0))))))); }
Example 13
Source File: Commands_1_12_2.java From multiconnect with MIT License | 5 votes |
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))); } } } }
Example 14
Source File: ProfileCommand.java From fabric-carpet with MIT License | 5 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("profile"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandProfile)). executes( (c) -> healthReport(c.getSource(), 100)). then(literal("health"). executes( (c) -> healthReport(c.getSource(), 100)). then(argument("ticks", integer(20,24000)). executes( (c) -> healthReport(c.getSource(), getInteger(c, "ticks"))))). then(literal("entities"). executes((c) -> healthEntities(c.getSource(), 100)). then(argument("ticks", integer(20,24000)). executes((c) -> healthEntities(c.getSource(), getInteger(c, "ticks"))))); dispatcher.register(literalargumentbuilder); }
Example 15
Source File: DrawCommand.java From fabric-carpet with MIT License | 4 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> command = literal("draw"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)). then(literal("sphere"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(drawShape(c -> DrawCommand.drawSphere(c, false)))))). then(literal("ball"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(drawShape(c -> DrawCommand.drawSphere(c, true)))))). then(literal("diamond"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(drawShape(c -> DrawCommand.drawDiamond(c, true)))))). then(literal("pyramid"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"up","down"},b)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)). then(drawShape(c -> DrawCommand.drawPyramid(c, "square", true))))))))). then(literal("cone"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"up","down"},b)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)) .then(drawShape(c -> DrawCommand.drawPyramid(c, "circle", true))))))))). then(literal("cylinder"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)) .then(drawShape(c -> DrawCommand.drawPrism(c, "circle")))))))). then(literal("cuboid"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)) .then(drawShape(c -> DrawCommand.drawPrism(c, "square")))))))); dispatcher.register(command); }
Example 16
Source File: PlayerCommand.java From fabric-carpet with MIT License | 4 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("player") .requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPlayer)) .then(argument("player", StringArgumentType.word()) .suggests( (c, b) -> suggestMatching(getPlayers(c.getSource()), b)) .then(literal("stop").executes(PlayerCommand::stop)) .then(makeActionCommand("use", EntityPlayerActionPack.ActionType.USE)) .then(makeActionCommand("jump", EntityPlayerActionPack.ActionType.JUMP)) .then(makeActionCommand("attack", EntityPlayerActionPack.ActionType.ATTACK)) .then(makeActionCommand("drop", EntityPlayerActionPack.ActionType.DROP_ITEM)) .then(makeDropCommand("drop", false)) .then(makeActionCommand("dropStack", EntityPlayerActionPack.ActionType.DROP_STACK)) .then(makeDropCommand("dropStack", true)) .then(makeActionCommand("swapHands", EntityPlayerActionPack.ActionType.SWAP_HANDS)) .then(literal("kill").executes(PlayerCommand::kill)) .then(literal("shadow"). executes(PlayerCommand::shadow)) .then(literal("mount").executes(manipulation(ap -> ap.mount(true))) .then(literal("anything").executes(manipulation(ap -> ap.mount(false))))) .then(literal("dismount").executes(manipulation(EntityPlayerActionPack::dismount))) .then(literal("sneak").executes(manipulation(ap -> ap.setSneaking(true)))) .then(literal("unsneak").executes(manipulation(ap -> ap.setSneaking(false)))) .then(literal("sprint").executes(manipulation(ap -> ap.setSprinting(true)))) .then(literal("unsprint").executes(manipulation(ap -> ap.setSprinting(false)))) .then(literal("look") .then(literal("north").executes(manipulation(ap -> ap.look(Direction.NORTH)))) .then(literal("south").executes(manipulation(ap -> ap.look(Direction.SOUTH)))) .then(literal("east").executes(manipulation(ap -> ap.look(Direction.EAST)))) .then(literal("west").executes(manipulation(ap -> ap.look(Direction.WEST)))) .then(literal("up").executes(manipulation(ap -> ap.look(Direction.UP)))) .then(literal("down").executes(manipulation(ap -> ap.look(Direction.DOWN)))) .then(argument("direction", RotationArgumentType.rotation()) .executes(c -> manipulate(c, ap -> ap.look(RotationArgumentType.getRotation(c, "direction").toAbsoluteRotation(c.getSource()))))) ).then(literal("turn") .then(literal("left").executes(c -> manipulate(c, ap -> ap.turn(-90, 0)))) .then(literal("right").executes(c -> manipulate(c, ap -> ap.turn(90, 0)))) .then(literal("back").executes(c -> manipulate(c, ap -> ap.turn(180, 0)))) .then(argument("rotation", RotationArgumentType.rotation()) .executes(c -> manipulate(c, ap -> ap.turn(RotationArgumentType.getRotation(c, "rotation").toAbsoluteRotation(c.getSource()))))) ).then(literal("move").executes(c -> manipulate(c, EntityPlayerActionPack::stopMovement)) .then(literal("forward").executes(c -> manipulate(c, ap -> ap.setForward(1)))) .then(literal("backward").executes(c -> manipulate(c, ap -> ap.setForward(-1)))) .then(literal("left").executes(c -> manipulate(c, ap -> ap.setStrafing(1)))) .then(literal("right").executes(c -> manipulate(c, ap -> ap.setStrafing(-1)))) ).then(literal("spawn").executes(PlayerCommand::spawn) .then(literal("at").then(argument("position", Vec3ArgumentType.vec3()).executes(PlayerCommand::spawn) .then(literal("facing").then(argument("direction", RotationArgumentType.rotation()).executes(PlayerCommand::spawn) .then(literal("in").then(argument("dimension", DimensionArgumentType.dimension()).executes(PlayerCommand::spawn))) )) )) ) ); dispatcher.register(literalargumentbuilder); }
Example 17
Source File: KillCommand.java From multiconnect with MIT License | 4 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("kill") .executes(ctx -> 0) .then(argument("victim", entities()) .executes(ctx -> 0))); }
Example 18
Source File: EntityDataCommand.java From multiconnect with MIT License | 4 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("entitydata") .then(argument("entity", entities()) .then(argument("nbt", nbtCompound()) .executes(ctx -> 0)))); }
Example 19
Source File: DifficultyCommand.java From multiconnect with MIT License | 4 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("difficulty") .then(argument("newDifficulty", union(enumArg("peaceful", "easy", "normal", "hard", "p", "e", "n", "h").caseInsensitive(), integer(0, 3))) .executes(ctx -> 0))); }
Example 20
Source File: DefaultGamemodeCommand.java From multiconnect with MIT License | 4 votes |
public static void register(CommandDispatcher<CommandSource> dispatcher) { dispatcher.register(literal("gamemode") .then(argument("mode", union(enumArg("survival", "creative", "adventure", "spectator", "s", "c", "a", "sp"), integer(0, 3))) .executes(ctx -> 0))); }