Command Problem

Discussion in 'Plugin Development' started by javoris767, Oct 15, 2012.

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

    javoris767

    Hello, I am very bad with commands x-x.
    I'm trying to do this...
    /votesql
    sends a message
    /votesql check
    sends a message
    /votesql check args[0]
    sends a message

    Here is what I have so far.
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                if(args.length == 0) {
                    sender.sendMessage(ChatColor.YELLOW + "/votesql reload -" + ChatColor.BLUE + " Reloads the config.");
                    sender.sendMessage(ChatColor.YELLOW + "/votesql test <vote> -" + ChatColor.BLUE + " Adds a string and 1 vote to the database.");
                }
                if(args.length == 1) {
                    if(args[0].equalsIgnoreCase("reload") && sender.hasPermission("votesql.reload")) {
                        plugin.reloadConfig();
                        sender.sendMessage(ChatColor.GREEN + "[" + "VoteSQL " + plugin.getDescription().getVersion() + "]: Config reloaded!");
                    }
                    if(args[0].equalsIgnoreCase("check") && sender.hasPermission("votesql.check")) {
                        sender.sendMessage(ChatColor.YELLOW + "/votesql test <vote> -" + ChatColor.BLUE + " Adds a string and 1 vote to the database.");
                    }
                    if(args.length == 2) {
                        if(args[0].equalsIgnoreCase("check") && sender.hasPermission("votesql.check")) {
                            plugin.addData(args[0]);
                            sender.sendMessage(ChatColor.GREEN + "[" + "VoteSQL " + plugin.getDescription().getVersion() + "]: Vote Passed!");
                        }
                    }
                }
                return false;
        }
    }
     
  2. if(args[0].equalsIgnoreCase("check") && sender.hasPermission("votesql.check")) {
    plugin.addData(args[0]);


    You are adding check to plugin.addData, I believe you wants addData(args[1])
     
  3. Offline

    javoris767

    Didn't work :/
     
  4. Offline

    Tirelessly

    Then addData doesn't work.

    Not to mention you didnt even check the command name..
     
  5. Offline

    javoris767

    I'm using this onenable
    Code:
    getCommand("votesql").setExecutor(new VoteSQLCommand(this));]/code]
     
  6. Offline

    Tirelessly

    It just seems like better practice to check the name.
     
  7. you aren't as bad whit commands as you think you are, I only see 1 mistake
    if(args.length == 1) {
    /* ... */
    if(args.length == 2) {
    /* ... */
    /* Only excuted if the arguments is 1 and 2 in lenght, what never happend */
    }
    }
     
  8. Offline

    javoris767

    Code:
    if(args.length == 2) {
                        if(args[0].equalsIgnoreCase("check") && sender.hasPermission("votesql.check")) {
                            plugin.addData(args[1]);
                            sender.sendMessage(ChatColor.GREEN + "[" + "VoteSQL " + plugin.getDescription().getVersion() + "]: Vote Passed!");
                        }
                    }
                }
                return false;
        }
    }
    Well, I'm confused. I've done this before with 1 command arg, but now im using 2 ( reload and check ). I don't know how to like let it only do plugin.addData on /votesql check :/
     
  9. Offline

    zachoooo

    Why don't you ever ask me for help?
     
  10. Offline

    javoris767

    You're a busy person D:

    McLuke500 ._.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
    zachoooo likes this.
  11. Offline

    McLuke500

    -_- jav and his commands
     
Thread Status:
Not open for further replies.

Share This Page