question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CustomArgumentInfo.previousArgs is empty (should contain PlayerArgument)

See original GitHub issue

CommandAPI version: 8.4.1

Minecraft version: 1.18.2

Shading the CommandAPI? yes

What I did:

My plugin stores “profiles” (just an object in memory) for all players. Admins should be able to access profiles by other players, for that purpose I have two arguments. SenderOwnedProfileArgument, which gets the player who is the command sender and gets their profiles, which works perfectly. TargetOwnedProfileArgument, for the admin commands, which gets a previous arg, casts it to a player and follows the same procedure, this breaks.

This is the code for the custom argument which breaks: https://www.toptal.com/developers/hastebin/cubihezazu.java This is the line where I add the arguments: .withArguments(new PlayerArgument("target"), new TargetOwnedProfileArgument(this.plugin.getAPI().getPlayerList(), messages, "profile", 0).get()) This is the command I run: /adminprofiles profile BeefDevClone a

The withArguments method is called on a subcommand (profile) which is later added to adminprofiles as a subcommand. BeefDevClone is supposed to be the player argument (name of my account), and a is the name of one BeefDevClone’s profiles.

What actually happened:

After I executed the command I get a Error in executing command adminprofiles profile BeefDevClone a - a<--[HERE]. Printing inside the function which creates the argument (before line 35 in the code). Shows that the previousArgs array is empty, even though the player argument is before the custom one. This causes the call in line 35 to fail because the array is empty (I assume an ArrayIndexOutOfBoundsException is thrown somewhere.).

Sadly no error logs apart from this.

What should have happened:

The PlayerArgument is added to the array, the custom argument gets it and executes normally.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JorelAlicommented, Aug 11, 2022

Fixed in 8.5.1.

1reaction
JorelAlicommented, Jul 10, 2022

@willkroboth

The loop that adds objects to the array returned by CustomArgumentInfo#previousArgs breaks once it gets to an argument with the node name equal to the argument for which it is generating the previous arguments. This works as intended if there are no arguments with the same name, which is not necessarily a valid assumption.

Well yes, but technically no. Brigadier requires required arguments to have different names (i.e. it applies to all arguments except literal arguments). Arguments with the same name do conflict internally as well in Brigadier (implemented in CommandContext#getArgument, which uses a map of argument names to parsed arguments). I’m fairly certain simply omitting the case of literal arguments would be sufficient.

Everything else you said about calling the generatePreviousArguments multiple times sounds pretty plausible however! I’m all for any performance improvements 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Whats the pythonic way to handle empty *args when creating ...
Is there a way to pass an "entire set" argument to SubsetOutput , so you can bury the conditional inside its call rather...
Read more >
The leftover arguments are empty in Click 6.0 Context #473
I have been trying to reproduce this issue, I have attempted to use Click 5.0, 6.0, 7.0 on both Python 2.7, Python 3.6....
Read more >
Empty string breaks command line - Unix StackExchange
The ls utility does not like an empty argument because there is no file or directory that has an empty name. – Kusalananda...
Read more >
Safe Args fromBundle() doesn't handle a null Bundle when ...
Hi I'm facing a similar issue. My OrdersFragment has one nullable argument called Option: <argument android:name="option" app:argType="string"
Read more >
70955 – Empty string as a program argument not accepted.
You need to log in before you can comment on or make changes to this bug. ... I have a collegue who cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found