Crossfire JXClient, Trunk
HelpCommand.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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.commands;
24 
27 import org.jetbrains.annotations.NotNull;
28 
33 public class HelpCommand extends AbstractCommand {
34 
39  @NotNull
40  private final CommandQueue commandQueue;
41 
45  @NotNull
46  private final Commands commands;
47 
56  super("help", crossfireServerConnection);
57  this.commandQueue = commandQueue;
58  this.commands = commands;
59  }
60 
61  @Override
62  public boolean allArguments() {
63  return false;
64  }
65 
66  @Override
67  public void execute(@NotNull final String args) {
68  if (args.isEmpty()) {
69  commandQueue.sendNcom(true, "help "+args);
70  return;
71  }
72 
73  if (args.equalsIgnoreCase("commands")) {
74  final StringBuilder sb = new StringBuilder();
75  String separator = " Client-sided commands:\n";
76  for (final String command : commands.getCommands()) {
77  sb.append(separator).append(command);
78  separator = " ";
79  }
80  sb.append("\n");
81  drawInfo(sb.toString());
82  commandQueue.sendNcom(true, "help "+args);
83  return;
84  }
85 
86  final Command command = commands.findCommand(args);
87  if (command == null || command instanceof HelpCommand) {
88  commandQueue.sendNcom(true, "help "+args);
89  return;
90  }
91 
92  drawInfo("Help about '"+args+"'\n"+command.getHelp().trim());
93  }
94 
95  @NotNull
96  @Override
97  public String getHelp() {
98  return "";
99  }
100 
101 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.commands.HelpCommand.getHelp
String getHelp()
Returns the help text for this command.
Definition: HelpCommand.java:97
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.commands.HelpCommand.allArguments
boolean allArguments()
Returns whether all remaining commands should be included as arguments.
Definition: HelpCommand.java:62
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.commands.Command.getHelp
String getHelp()
Returns the help text for this command.
com.realtime.crossfire.jxclient.commands.Commands.getCommands
Collection< String > getCommands()
Returns all defined commands.
Definition: Commands.java:60
com.realtime.crossfire.jxclient.commands.AbstractCommand
Abstract base class for Command implementations.
Definition: AbstractCommand.java:33
com.realtime.crossfire.jxclient.commands.HelpCommand.commandQueue
final CommandQueue commandQueue
The CommandQueue instance for sending "help" commands to the server.
Definition: HelpCommand.java:40
com.realtime.crossfire.jxclient.commands.Commands
Parses and executes client-side commands.
Definition: Commands.java:37
com.realtime.crossfire.jxclient.queue.CommandQueue.sendNcom
void sendNcom(final boolean mustSend, @NotNull final String command)
Sends a "ncom" command to the server.
Definition: CommandQueue.java:184
com.realtime.crossfire.jxclient.commands.HelpCommand.execute
void execute(@NotNull final String args)
Executes the command with the given arguments.
Definition: HelpCommand.java:67
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.commands.AbstractCommand.crossfireServerConnection
final CrossfireServerConnection crossfireServerConnection
The connection instance.
Definition: AbstractCommand.java:45
com.realtime.crossfire.jxclient.queue
Definition: CommandQueue.java:23
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.commands.HelpCommand
Implements the command "help".
Definition: HelpCommand.java:33
com.realtime.crossfire.jxclient.commands.HelpCommand.commands
final Commands commands
All defined client-sided commands.
Definition: HelpCommand.java:46
com.realtime.crossfire.jxclient.commands.AbstractCommand.drawInfo
void drawInfo(@NotNull final String message)
Displays a regular output message.
Definition: AbstractCommand.java:61
com.realtime.crossfire.jxclient.queue.CommandQueue
Maintains the pending (ncom) commands sent to the server.
Definition: CommandQueue.java:38
com.realtime.crossfire.jxclient.commands.Commands.findCommand
Command findCommand(@NotNull final String commandName)
Returns a Command by name.
Definition: Commands.java:70
com.realtime.crossfire.jxclient.commands.HelpCommand.HelpCommand
HelpCommand(@NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final CommandQueue commandQueue, @NotNull final Commands commands)
Creates a new instance.
Definition: HelpCommand.java:55
com.realtime.crossfire.jxclient.commands.Command
Implements a client-side command.
Definition: Command.java:31