Example #1
0
  /**
   * Called when the sender is invalid for the command
   *
   * @param sender The sender of the command
   */
  public void invalidSender(CommandSender sender) {
    if (sender instanceof Player)
      sender.sendMessage("[" + plugin.getName() + "] You cannot use this command as a player");

    if (sender instanceof ConsoleCommandSender)
      sender.sendMessage("[" + plugin.getName() + "] You cannot use this command from the console");
  }
  public void registerCommands(Class<?> clazz, CommandContainer base) {
    Validate.notNull(clazz);

    Set<CommandContainer> commands =
        CommandContainer.create(clazz, base, instantiator, execution, logger);
    Iterator<CommandContainer> iterator = commands.iterator();

    while (iterator.hasNext()) {
      CommandContainer command = iterator.next();

      if (base == null) {
        if (commandMap.containsKey(command.getName())) {
          logger.warning("duplicate command " + command.getName() + "!");
          continue;
        }

        commandMap.put(command.getName(), command);

        PluginCommand bukkitCommand = plugin.getCommand(command.getName());
        if (bukkitCommand != null) {
          bukkitCommand.setExecutor(this);
        } else {
          logger.warning(
              "Command "
                  + command.getName()
                  + " registered but could not find a matching command for plugin "
                  + plugin.getName()
                  + ". Did you forget to add the command to your plugin.yml?");
        }
      } else {
        // Just add it as a child
        base.addChild(command);
      }
    }
  }
Example #3
0
  /**
   * Log a message in the debug file.
   *
   * @param message Message to be logged.
   */
  public void log(String message) {
    try {
      BufferedWriter output = new BufferedWriter(new FileWriter(file, true));

      output.write("[" + plugin.getName() + "] " + getDateAndTime() + " " + message);

      output.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #4
0
 /**
  * Called when a sub-command of the main command is not found
  *
  * @param sender The sender of the command
  * @param args The arguments of the command sent
  */
 public void commandNotFound(CommandSender sender, String[] args) {
   sender.sendMessage("[" + plugin.getName() + "] Command usage incorrect");
   sender.sendMessage("[" + plugin.getName() + "] Usage: " + usage);
 }
Example #5
0
 /**
  * Called when the sender do not have permission
  *
  * @param sender The sender of the command
  */
 public void noPermission(CommandSender sender) {
   sender.sendMessage("[" + plugin.getName() + "] You do not have permission");
 }