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.

Support for parameters in middle of command nodes

See original GitHub issue

A 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:open
  • Created 5 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
aikarcommented, Apr 21, 2020

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.

0reactions
Sven65commented, Apr 21, 2020

Alright! Keep us updated 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Handle Command-line Arguments in Node.js Scripts
Node.js supports a list of passed arguments, known as an argument vector. The argument vector is an array available from process.argv in ...
Read more >
Node configuration parameters - IBM
Node configuration parameters. You need the following information for node configuration: APPN support: Level of APPN support for the node:.
Read more >
Passing ROS arguments to nodes via the command-line
All ROS nodes take a set of arguments that allow various properties to be reconfigured. Examples include configuring the name/namespace of the node, ......
Read more >
Node Parameters - TIBCO Product Documentation
It defines the actions that Command Center can perform on this node. The valid values are as follows: ALL - NODE, PROFILE, AUDIT,...
Read more >
system node show - ONTAP 9.8
The system node show command displays information about the nodes in a cluster. You can limit output to specific types of information and...
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