@Commander( name ="say", description ="test say command", alias = {"sa","s"})publicclassTestSayCommandimplementsCommandNode { @CommandArg(order =0, identifier ="message")privateString message; @Overridepublicvoidexecute(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) {thrownewArgumentParseException("&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); //內部解析returnnewLocation(world, x, y, z); });
you can also inject ArgParserService into your injectable instance.