@Commander(
name = "say",
description = "test say command",
alias = {"sa", "s"}
)
public class TestSayCommand implements CommandNode {
@CommandArg(order = 0, identifier = "message")
private String message;
@Override
public void execute(CommandSender commandSender) {
Bukkit.broadcastMessage(commandSender.getName()+" says: "+message);
}
}
when you input /say this is a text , message argument will be "this is a text"
Using parser inside argument parser creation
when you create anargument parser like org.bukkit.Location , you will find that x y z is a double class,then you can use the parser inside your creation.
argumentManager.registerParser(Location.class, (args, sender, parser) -> {
World world;
if (!(sender instanceof Player)) {
world = Bukkit.getWorld(args.next());
} else {
world = ((Player) sender).getWorld();
}
if (world == null) {
throw new ArgumentParseException("&cunknown world");
}
var x = parser.tryParse(Double.class, args, sender); //內部解析
var y = parser.tryParse(Double.class, args, sender); //內部解析
var z = parser.tryParse(Double.class, args, sender); //內部解析
return new Location(world, x, y, z);
});
you can also inject ArgParserService into your injectable instance.