package fr.aumgn.bukkitutils.command.executor;

import org.apache.commons.lang.Validate;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;

import fr.aumgn.bukkitutils.command.CommandsMessages;
import fr.aumgn.bukkitutils.command.args.CommandArgsParser;

public class NestedCommandExecutor implements CommandExecutor {

    private final JavaPlugin plugin;
    private final CommandsMessages messages;
    private final String defaultTo;

    public NestedCommandExecutor(JavaPlugin plugin, CommandsMessages messages,
            String defaultTo) {
        this.plugin = plugin;
        this.messages = messages;
        this.defaultTo = defaultTo;
    }

    @Override
    public boolean onCommand(CommandSender sender,
            Command cmd, String label, String[] rawArgs) {

        CommandArgsParser parser =  new CommandArgsParser(messages, rawArgs);
        String[] args = parser.linearize();

        PluginCommand subCmd;
        String[] subCmdArgs;
        if (args.length == 0) {
            if (defaultTo.isEmpty()) {
                return false;
            }

            subCmd = plugin.getCommand(cmd.getName() + " " + defaultTo);
            Validate.notNull(subCmd);
            subCmdArgs = args;
        } else {
            subCmd = plugin.getCommand(cmd.getName() + " " + args[0]);
            if (subCmd == null) {
                if (defaultTo.isEmpty()) {
                    return false;
                }

                subCmd = plugin.getCommand(cmd.getName() + " " + defaultTo);
                Validate.notNull(subCmd);
                subCmdArgs = args;
            } else {
                subCmdArgs = new String[args.length - 1];
                System.arraycopy(args, 1, subCmdArgs, 0, args.length - 1);
            }
        }

        subCmd.execute(sender, label + " " + args[0], subCmdArgs);
        return true;
    }
}

@@ -1080,16 +1080,41 @@
 subCmd;%0A
+        String subLabel;%0A
         
@@ -1130,24 +1130,24 @@
 subCmdArgs;%0A
-
         if (
@@ -1353,32 +1353,62 @@
 otNull(subCmd);%0A
+            subLabel = label;%0A
             subC
@@ -1709,32 +1709,66 @@
 %22 + defaultTo);%0A
+                subLabel = label;%0A
                 
@@ -1841,32 +1841,82 @@
        %7D else %7B%0A
+                subLabel = label + %22 %22 + args%5B0%5D;%0A
                 
@@ -2088,37 +2088,24 @@
 sender, 
-label + %22 %22 + args%5B0%5D
+subLabel
 , subCmd

Fix nested commands default command label