Support for parameters in middle of command nodes
See original GitHub issueA format supported by Brigadier for Minecraft is:
/bossbar add <id> <name>
/bossbar set <id> color <color>
/bossbar set <id> name <newname>
/bossbar remove <id>
This is complicated to support, but desirable for defining a common parameter for a group of commands that all have same requirements, instead of duplicating it.
I’ve designed the following concept to represent this structure:
class BossBarCommand extends BaseCommand {
@CommandParameter("id")
NamespacedKey id;
@Subcommand("add <id>")
public void onAdd(CommandSender sender, String name) {}
@Subcommand("remove <id>")
public void onAdd(CommandSender sender) {}
@Subcommand("set <id>")
private class SetCommands extends BaseCommand {
@Subcommand("name")
public void onName(CommandSender sender, String name) { }
@Subcommand("color")
public void onName(CommandSender sender, Color color) { }
}
}
I think this is super clean and no boilerplate, however one main drawback: This is dangerous for when we add Asynchronous Execution of commands.
Proposed solution to async problem: Clone the BaseCommand instance anytime ASYNC dispatch occurs (won’t be as common). This seems inefficient, but commands aren’t exactly hot, nor would people be async’ing as much.
By cloning before switching to a new thread, the execution can get a snapshot of the parameter as it was. It would have to be highly documented, noting that you wouldn’t be able to mutate any fields on the class in an async dispatcher (but you could call into the objects it points to, it would not be a deep clone – the standard java clone), and that your responsible for concurrency still.
The clone would be just to avoid the instances field being updated for a 2nd command execution in the middle of the first. For sync commands, there is no need to clone.
Feedback?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top GitHub Comments
No haven’t had time due to other work, but have been thinking on doing some prep work to reorder internals to better prep for this and ease integration with Brigadier.
Alright! Keep us updated 😃