aikar / aikar/commands

Support for parameters in middle of command nodes

未关闭
#145 6 条评论 6 个 reaction 已指派 0 人 在 GitHub 查看
core help wanted
主要语言
Java
星标
628
派生
150
PR 合并指标
30 天内没有已合并 PR

描述

A format supported by Brigadier for Minecraft is:

```
/bossbar add
/bossbar set color
/bossbar set name
/bossbar remove
```
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:
```java
class BossBarCommand extends BaseCommand {
@CommandParameter("id")
NamespacedKey id;

@Subcommand("add ")
public void onAdd(CommandSender sender, String name) {}
@Subcommand("remove ")
public void onAdd(CommandSender sender) {}

@Subcommand("set ")
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 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。