Crossfire JXClient, Trunk  R20561
CommandExecutorImpl.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.commands;
23 
26 import org.jetbrains.annotations.NotNull;
27 
32 public class CommandExecutorImpl implements CommandExecutor {
33 
37  @NotNull
38  private final CommandQueue commandQueue;
39 
43  @NotNull
44  private final Commands commands;
45 
51  public CommandExecutorImpl(@NotNull final CommandQueue commandQueue, @NotNull final Commands commands) {
52  this.commandQueue = commandQueue;
53  this.commands = commands;
54  }
55 
59  @Override
60  public void executeCommand(@NotNull final CharSequence commandLine) {
61  final Iterable<CommandExec> commandList = CommandExpander.expand(commandLine, commands);
62  for (final CommandExec commandExec : commandList) {
63  final Command command = commandExec.getCommand();
64  if (command == null) {
65  commandQueue.sendNcom(false, commandExec.getArgs());
66  } else {
67  command.execute(commandExec.getArgs());
68  }
69  }
70  }
71 
72 }
Implements a client-side command.
Definition: Command.java:30
void sendNcom(final boolean mustSend, @NotNull final String command)
Sends an "ncom" command to the server.
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.
final CommandQueue commandQueue
The command queue for sending commands.
void execute(@NotNull String args)
Executes the command with the given arguments.
CommandExecutorImpl(@NotNull final CommandQueue commandQueue, @NotNull final Commands commands)
Creates a new instance.
Maintains the pending (ncom) commands sent to the server.
void executeCommand(@NotNull final CharSequence commandLine)
Executes a command or a list of commands.The commands may be a client- or a server-sided command...
Parses and executes client-side commands.
Definition: Commands.java:33