22 package com.realtime.crossfire.jxclient.commands;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.regex.Pattern;
27 import org.jetbrains.annotations.NotNull;
61 public static Collection<CommandExec>
expand(@NotNull
final CharSequence commandList, @NotNull
final Commands commands) {
62 final Collection<CommandExec> list =
new ArrayList<>();
63 CharSequence remainingCommandList = commandList;
65 final String[] tmp = PATTERN_SEPARATOR.split(remainingCommandList, 2);
66 final String commandSpec = tmp[0];
67 if (!commandSpec.isEmpty()) {
68 final String[] tmp2 = PATTERN_SPACES.split(commandSpec, 2);
69 final String commandName = tmp2[0];
70 final String commandArgs = tmp2.length == 2 ? tmp2[1] :
"";
71 final Command command = commands.findCommand(commandName);
72 if (command == null) {
75 final String[] tmp3 = PATTERN_SPACES.split(remainingCommandList, 2);
76 list.add(
new CommandExec(command, tmp3.length == 2 ? tmp3[1] :
""));
85 remainingCommandList = tmp[1];
Implements a client-side command.
Expands a command (or list of commands) into a sequence of Commands to execute.
A Command instance and its arguments.
static Collection< CommandExec > expand(@NotNull final CharSequence commandList, @NotNull final Commands commands)
Expands a command list into a sequence of Commands to execute.
CommandExpander()
Private constructor to prevent instantiation.
boolean allArguments()
Returns whether all remaining commands should be included as arguments.
static final Pattern PATTERN_SPACES
The Pattern for splitting commands from command arguments.
static final Pattern PATTERN_SEPARATOR
The Pattern for splitting command sequences.
Parses and executes client-side commands.