Jump to content

Recommended Posts

Posted (edited)

I am trying to find out if there is a way to have different requirements based off of one of the arguments in a command. 

for example:

/testCommand string String
/testCommand player Elrol_Arrowsend

 

so the first one, would require a string, because the prior argument is string, and the second would need a PlayerEntity because the prior command is player.
 

I saw something about forks and I am thinking that it might be what I am looking for, but I am not too sure, so I figured I would ask.

Edited by Elrol_Arrowsend
Solved
Posted

You need to create a literal argument (Commands.literal) for "string" and call requires/then/execute on that as necessary and do the same for "player". In your main command registration (where you call CommandDispatcher#register), create a literal argument for "testcommand" and call then on it with the result of each literal method chain.

 

If string and player are more like separate commands than modes of the same command, you can move each sub-command into its own class with a static method that returns an ArgumentBuilder<CommandSource, ?> (the result of the literal method chain) and call these methods in the then calls of the main command registration.

 

See ForgeCommand or my TestMod3Command for examples of this.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.