aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/MultiArgsCommand.java
blob: 5fde6775526f21363aa204e3a8599d53e03085ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.juick.command;

import com.juick.User;
import com.juick.server.protocol.ProtocolListener;

import java.util.regex.Matcher;

/**
 * @author ma1uta
 */
public abstract class MultiArgsCommand implements Command {

    @Override
    public String execute(User sender, ProtocolListener protocolListener, String command) {
        Matcher matcher = pattern().matcher(command.trim());
        String[] arguments = new String[matcher.groupCount()];
        for (int i = 1; i <= matcher.groupCount(); i++) {
            arguments[i - 1] = (matcher.group(i));
        }
        return execute(sender, protocolListener, arguments);
    }

    protected abstract String execute(User sender, ProtocolListener protocolListener, String... arguments);
}