Solved Command Args

Discussion in 'Plugin Development' started by x_Jake_s, Jul 23, 2016.

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

    x_Jake_s

    So i'm currently creating a very in-game editable blacklist plugin, basically every command in the plugin is sprouted of the base command /blacklist, so for example if you want to list the words you have blocked you type /blacklist word list and if you want to list blocks you type /blacklist block list. now I have a strong understanding of java however i don't understand how to solve this error.
    I have 5 commands attached to both block and word. so for example /blacklist block (list, add, remove, on, off) however I want to send a message to the player saying Invalid argument for example if they type /blacklist block shaljhtasl basically something random in the arg[2] area but i do not know how to get around this i have tried making a check system to check that its not one of the words above but its not working. If anyone has ideas i would love to know.

    below is just my base code without any of the actual useful code that the commands need because this is not going to be an open source plugin.

    Code:
            if (args.length == 2) {
                if (args[0].equalsIgnoreCase("word")) {
                    if (args[1].equalsIgnoreCase("list")) {
                        player.sendMessage("this would list words");
                    }
                    if (args[1].equals("add")) {
                        player.sendMessage("this would list words");
                    }
                    if (args[1].equals("remove")) {
                        player.sendMessage("this would list words");
                    }
                    if (args[1].equals("on")) {
                        player.sendMessage("this would list words");
                    }
                    if (args[1].equals("off")) {
                        player.sendMessage("this would list words");
                    }
                    if (args[1].equals("")) {
                        player.sendMessage("Invalid");
                    }
                }
            }
            return false;
            }
    }
    Update) wow don't i feel ridiculous ..... I made a very noobish error.... but I'm going to leave this post here incase other people make the error... here is the fix:
    Code:
            if (args.length == 2) {
                if (args[0].equalsIgnoreCase("word")) {
                    if (args[1].equalsIgnoreCase("list")) {
                        player.sendMessage("this would list words");
                        return true;
                    }
                    if (args[1].equals("add")) {
                        player.sendMessage("this would list words");
                        return true;
                    }
                    if (args[1].equals("remove")) {
                        player.sendMessage("this would list words");
                        return true;
                    }
                    if (args[1].equals("on")) {
                        player.sendMessage("this would list words");
                        return true;
                    }
                    if (args[1].equals("off")) {
                        player.sendMessage("this would list words");
                        return true;
                    }
                    player.sendMessage("Wrong argument!");
                    player.sendMessage("the argument you have written is: " + args[1]);
                    return false;
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Jul 23, 2016
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page