コード例 #1
0
  /**
   * Adds the methods on <code>handler</code> annotated with {@link FlexHandler} to the dispatcher
   * tree.
   *
   * @param plugin the plugin to bind the commands to. Theoretically this parameter can take the
   *     value <code>null</code>; however it is recommended to pass a valid {@link Plugin} to aid
   *     server administrators in debugging problems.
   * @param handler the object to extract handling methods from
   */
  public void addHandler(Plugin plugin, Object handler) {
    if (plugin != null) {
      clients.add(plugin);
    }

    try {
      for (Method m : handler.getClass().getMethods()) {
        if (m.isAnnotationPresent(FlexHandler.class)) {
          FlexHandler annotation = m.getAnnotation(FlexHandler.class);
          String[] path = annotation.value().split(" ");
          String rootName = path[0];

          FlexMethodHandlingContext hctx = new FlexMethodHandlingContext(plugin, handler, m);
          hctx.validate();

          root.add(path, hctx);
        }
      }
    } catch (FlexBuildingException e) {
      logException(plugin, e, "Error when building command trees: " + e.toString());
    }
  }
コード例 #2
0
 /**
  * Executes the given command, returning its success.
  *
  * @param sender the source of the command
  * @param cmd the command which was executed
  * @param label the alias of the command which was used
  * @param args the command arguments passed
  * @return <code>true</code> if the command succeeded, else <code>false</code>
  */
 public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
   FlexCommandContext ctx = new FlexCommandContext(sender, cmd, label, args);
   return root.dispatch(ctx);
 }
コード例 #3
0
 /**
  * Creates an alias under <code>aliasPath</code> for the command tree under <code>originalPath
  * </code>.
  *
  * @param originalPath the path to use as the source. Example: <code>{"myplugin", "group", "add"}
  *     </code>.
  * @param aliasPath the path to use as the destination. Example: <code>{"addgroup"}</code>.
  */
 public void alias(String[] originalPath, String[] aliasPath) {
   FlexDispatcher source = root.traverse(originalPath);
   root.extend(aliasPath, source);
 }