Since it seems it has been somewhat suggested that I do the command API, here’s what I got.
First off, I have Intake, which is a command processing library I spun off from WorldEdit 6. It’s usable, but it’s not finished by any means. The original pull request to pull it into WorldEdit is over a year old, never went through, and eventually was salvaged for a newer branch.
That said, it supports annotations, but usage of it is optional. An example of annotation usage is:
@Command(aliases = "age", desc = "Set age")
@Require("example.age")
public void setAge(Player player, @Optional @Default("20") int age) {
player.setAge(age);
player.message("Your age was set to: " + age);
}
Intake can automatically inject a Player
rather than, for example from Bukkit, a CommandSender
based on the type of parameter. It can also inject your own type of objects.
However, while that annotation code is a substantial part of Intake, you can still implement a command as a class:
class MyCommand implements CommandCallable {
void call(String arguments, CommandContext locals, String[] parentCommands) {
// do stuff
}
// ...
}
There are some “design designs” that had to be made at the time but could be up to discussion.
- Intake does not pass specifically the “command sender” as a special parameter. Rather, it has a “context” object the caller of the command can store several objects. A command would then, for example, get a sender using
context.get(Sender.class)
. The downside is that you do not have compile-time safety really, because there’s no guarantee that the context object contains, for example, the sender. The upside, however, is that you can store a bunch of different things on the context object. What’s everyone opinion on this? - It is not possible to know the name of parameters easily using the annotation method unless I add a
@Named("age")
annotation. The first problem is, prior to Java 8, Java did not store the names of parameters in compiled .class files. However, a workaround is to make use of the Paranamer library. While that works, parameter names aren’t great for documentation purposes, and localization is an issue. I’m really not sure what to do about this problem.
There are more of such decisions to make, but they will come to me at a later time. Ultimately, I’m not sure whether I plan to bundle in the annotation part, especially if I can’t resolve those problems.
- More information about Intake can be found here: https://github.com/sk89q/Intake/blob/master/README.md
- Wiki: https://github.com/sk89q/Intake/wiki