Command Arguments problem

Discussion in 'Plugin Development' started by ehArcher, Nov 22, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ehArcher

    Alright, so i'm making a plugin to where it will log all staff members commnands (ban, tempban, unban, kick, mute). So i'm making a couple of commands, enable, disable, and version. I have all the argument commands written out. When I type /actionlogger it lists all the arguments for it, and when I do /actionlogger version It just does the same thing as /actionlogger.

    Here's my code.
    Code:
    package io.github.ehArcher.ActionLogger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class ActionLogger extends JavaPlugin{
       
        public void onEnable() {
            getLogger().info("onEnable has been invoked!");
        }
     
        public void onDisable() {
            getLogger().info("onDisble has been invoked!");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("actionlogger")) {
                Player player = (Player) sender;
                player.sendMessage(ChatColor.BLUE + "-----------------------");
                player.sendMessage(ChatColor.YELLOW + "'/al argument'");
                player.sendMessage(ChatColor.BLUE + "'----------------------");
                player.sendMessage(ChatColor.YELLOW + "'/al enable'");
                player.sendMessage(ChatColor.YELLOW + "'/al disable'");
                player.sendMessage(ChatColor.YELLOW + "'/al version'");
            }
            if(args.length > 1) {
                Player player = (Player) sender;
                if(args[1].equalsIgnoreCase("enable")) {
                    player.sendMessage(ChatColor.RED + "ActionLogger is now enabled!");
                }
                else if(args[1].equalsIgnoreCase("disable")) {
                    player.sendMessage(ChatColor.RED + "ActionLogger is now disabled!");
                }
                else if(args[1].equalsIgnoreCase("version")) {
                    player.sendMessage(ChatColor.BLUE + "------------------------------");
                    player.sendMessage(ChatColor.YELLOW + "Version: 0.1");
                    player.sendMessage(ChatColor.YELLOW + "Author: ehArcher");
                    player.sendMessage(ChatColor.BLUE + "------------------------------");
                }
            }
                return true;
        }
    }
    Here's my plugin.yml
    Code:
    name: ActionLogger
    description: ActionLogger v0.1
    main: io.github.ehArcher.ActionLogger.ActionLogger
    version: 0.1
     
    commands:
      actionlogger:
        description: Plugin to log staff members commands.
        permission: actionlogger.use
        permission-message: Insufficient permissions - "actionlogger.use"
      actionlogger version:
        description: ActionLogger information.
        permission: actionlogger.info
        permission-message: Insufficient permissions - "actionlogger.info"
      actionlogger enable:
        description: Enables ActionLogger.
        permission: actionlogger.enable
        permission-message: Insufficient permissions - "actionlogger.enable"
      actionlogger disable:
        description: Disables ActionLogger.
        permission: actionlogger.disable
        permission-message: Insufficient permissions - "actionlogger.disable"
    What am I doing wrong?
     
  2. Offline

    LazyLemons

    ehArcher Arrays are numbered with indices starting at 0. The first element would be accessed at index 0. Instead of using 'args[1]', use 'args[0]' to get the first argument.
     
  3. ehArcher
    Code:
    commands:
      actionlogger:
          description: This.
          usage: /<command> [arguments]
          arguments:
            this:
                description: An arg.
    permissions:
      my.perm:
          #You get the idea...
     
Thread Status:
Not open for further replies.

Share This Page