Posted August 31, 20223 yr Hi there! I've surprisingly found very little resources on Google/YouTube for this. I'm trying to make a custom command: /speed #. I'm doing the following: public SpeedCommand(final CommandDispatcher<CommandSourceStack> dispatcher) { dispatcher.register(Commands.literal("speed") .then(Commands.argument("amount", IntegerArgumentType.integer())) .requires(source -> { /*try { return ServerLifecycleHooks.getCurrentServer().getPlayerList().isOp(source.getPlayerOrException().getGameProfile()); } catch (CommandSyntaxException e) { e.printStackTrace(); return false; }*/ return source.hasPermission(3); }) .executes(command -> { final ServerPlayer player = command.getSource().getPlayerOrException(); player.flyingSpeed = MathTools.clamp(IntegerArgumentType.getInteger(command, "amount"), 1, 4); return 1; }) ); } In game, when typing "/speed", it shows the suggestion for me to include the "amount" argument. However, when I do include it, "/speed 1", it says that it's an unknown or incomplete command. Any ideas?
August 31, 20223 yr 1. `requires` should be first in the chain, having a permission level of 2. 2. Don't clamp the number, use the static constructor that bounds an integer between a min and max value.
August 31, 20223 yr Also your brackets are in the wrong place. You have literal().then(argument()).executes() when it should be literal().then(argument().executes()) otherwise the execute can't see the argument. Edited August 31, 20223 yr by warjort Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
August 31, 20223 yr Author 22 minutes ago, ChampionAsh5357 said: 1. `requires` should be first in the chain, having a permission level of 2. 2. Don't clamp the number, use the static constructor that bounds an integer between a min and max value. Thank you!
August 31, 20223 yr Author 11 minutes ago, warjort said: Also your brackets are in the wrong place. You have literal().then(argument()).executes() when it should be literal().then(argument().executes()) otherwise the execute can't see the argument. That makes sense. I appreciate it!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.