项目作者: dags-

项目描述 :
Another command annotation processing thing
高级语言: Java
项目地址: git://github.com/dags-/CommandBus.git
创建时间: 2016-01-11T16:37:03Z
项目社区:https://github.com/dags-/CommandBus

开源协议:

下载


CommandBus

Another command annotation processing thing

Release

Features:

  • Write commands as Java methods
  • Easy registration - by class, object, or even by package
  • Optional command flags
  • Generates command usage and help texts
  • Automatically generates & registers permissions
  • Generates per-plugin markdown tables of all commands/permissions/descriptions

Example Code:

  1. @Plugin(id = "example", name = "Example", version = "1.0", description = "Example plugin")
  2. public class ExamplePlugin {
  3. @Listener
  4. public void init(GameInitializationEvent event) {
  5. CommandBus.create().register(this).submit();
  6. }
  7. /**
  8. * Sends a 'hello world' message to the command source
  9. */
  10. @Command("hello world")
  11. public void example0(@Src Player src) {
  12. Fmt.stress("hello world!").tell(src);
  13. }
  14. /**
  15. * Sends the <message> to the given <player>
  16. */
  17. @Permission
  18. @Description("Teleport the player to the world")
  19. @Command("example tp <player> <world>")
  20. public void example1(@Src CommandSource src, Player target, World world) {
  21. Fmt.info("Teleported ").stress(target).info(" to world ").stress(world).tell(src);
  22. Fmt.stress(src.getName()).info(" teleported you to ").stress(world).tell(target);
  23. target.setLocation(world.getSpawnLocation());
  24. }
  25. /**
  26. * Sends the <message> to all players matching <match>
  27. */
  28. @Permission
  29. @Description("Send a private message")
  30. @Command("example pma <match> <message>")
  31. public void example2(@Src Player src, Collection<Player> targets, @Join String message) {
  32. Fmt.stress("You -> All: ").info(message).tell(src);
  33. Fmt.stress("%s -> You: ", src.getName()).info(message).tell(targets);
  34. }
  35. /**
  36. * Prints the value of the optional 'bool' flag
  37. */
  38. @Flag("bool")
  39. @Permission
  40. @Description("An example command that accepts flags")
  41. @Command("example flags")
  42. public void example3(@Src Player src, Flags flags) {
  43. boolean bool = flags.getOr("bool", false);
  44. Fmt.info("Bool: ").stress(bool).tell(src);
  45. }
  46. /**
  47. * Prints the list of BlockTypes back to the user
  48. */
  49. @Permission
  50. @Description("An example command that accepts varargs")
  51. @Command("example varargs <block>")
  52. public void example4(@Src CommandSource src, BlockType... blocks) {
  53. for (int i = 0; i < blocks.length; i++) {
  54. Fmt.info("Block #%s: ", i).stress(blocks[i].getName()).tell(src);
  55. }
  56. }
  57. }