Handling multiple commands.

Discussion in 'Plugin Development' started by Josvth, Feb 29, 2012.

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

    Josvth

    Hello,

    I've been struggling with commands finding the best way to register multiple commands.

    An example, in my Random Spawn plugin I have 11 commands. This is how I register them:

    Code:
     
    infoCommand infoCommand;
    helpCommand helpCommand;
    reloadCommand reloadCommand;
    setfirstspawnCommand setfirstspawnCommand;
    tpfirstspawnCommand tpfirstspawnCommand;
    unsetfirstspawnCommand unsetfirstspawnCommand;
    setareaCommand setareaCommand;
    enableCommand enableCommand;
    usebedsCommand usebedsCommand;
    keeprandomspawnsCommand keeprandomspawnsCommand;
    randomspawnonfirstjoinCommand randomspawnonfirstjoinCommand;
     
    (...)
     
    public void registerCommands(){
     
            this.helpCommand = new helpCommand(this.plugin);
            this.plugin.getCommand("rshelp").setExecutor(helpCommand);
           
            this.reloadCommand = new reloadCommand(this.plugin);
            this.plugin.getCommand("rsreload").setExecutor(reloadCommand);
     
            this.infoCommand = new infoCommand(this.plugin);
            this.plugin.getCommand("rsinfo").setExecutor(infoCommand);
           
            this.enableCommand = new enableCommand(this.plugin);
            this.plugin.getCommand("rsenable").setExecutor(enableCommand);
            this.plugin.getCommand("rsdisable").setExecutor(enableCommand);
           
           
            this.setareaCommand = new setareaCommand(this.plugin);
            this.plugin.getCommand("rssetarea").setExecutor(setareaCommand);
           
            this.usebedsCommand = new usebedsCommand(this.plugin);
            this.plugin.getCommand("rsusebeds").setExecutor(usebedsCommand);
           
            this.keeprandomspawnsCommand = new keeprandomspawnsCommand(this.plugin);
            this.plugin.getCommand("rskeeprandomspawns").setExecutor(keeprandomspawnsCommand);
            this.plugin.getCommand("rskeepspawns").setExecutor(keeprandomspawnsCommand);
           
            this.randomspawnonfirstjoinCommand = new randomspawnonfirstjoinCommand(this.plugin);
            this.plugin.getCommand("rsrandomspawnonfirstjoin").setExecutor(randomspawnonfirstjoinCommand);
            this.plugin.getCommand("rsfirstjoin").setExecutor(randomspawnonfirstjoinCommand);
           
           
            this.setfirstspawnCommand = new setfirstspawnCommand(this.plugin);
            this.plugin.getCommand("rssetfirstspawn").setExecutor(setfirstspawnCommand);
            this.plugin.getCommand("rssetfs").setExecutor(setfirstspawnCommand);
     
            this.tpfirstspawnCommand = new tpfirstspawnCommand(this.plugin);
            this.plugin.getCommand("rstpfirstspawn").setExecutor(tpfirstspawnCommand);
            this.plugin.getCommand("rstpfs").setExecutor(tpfirstspawnCommand);
           
            this.unsetfirstspawnCommand = new unsetfirstspawnCommand(this.plugin);
            this.plugin.getCommand("rsunsetfirstspawn").setExecutor(unsetfirstspawnCommand);
            this.plugin.getCommand("rsunsetfs").setExecutor(unsetfirstspawnCommand);
           
        }
    I would like to have one command like /rs or /randomspawn and as argument enable or setfirstspawn but still use a class for each command. So /randomspawn enable would be executed in a different CommandExecutor than /randomspawn setfirstspawn.

    I saw other devs working with annotations could someone explain how this works?
     
  2. Have you tryd to make Commands with arguments? like so: /rs setspawn ..
     
Thread Status:
Not open for further replies.

Share This Page