aboutsummaryrefslogtreecommitdiff
path: root/juick-commands/src/main/java/com/juick/command/MultiArgsCommand.java
blob: 4d50bff0b532eda56c492d954d3883dac6eef6ac (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
package com.juick.command;

import com.juick.User;

import java.util.regex.Matcher;

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

    @Override
    public String execute(User sender, MessageListener 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, MessageListener protocolListener, String... arguments);
}