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.server
com.realtime.crossfire.jxclient.commands.HelpCommand.commandQueue
final CommandQueue commandQueue
Definition: HelpCommand.java:40
com.realtime.crossfire.jxclient.commands.HelpCommand
Definition: HelpCommand.java:33
com.realtime.crossfire.jxclient.commands.Command
Definition: Command.java:31
com.realtime.crossfire.jxclient.commands.AbstractCommand.crossfireServerConnection
final CrossfireServerConnection crossfireServerConnection
Definition: AbstractCommand.java:45
com.realtime.crossfire.jxclient.commands.Command.getHelp
String getHelp()
com.realtime.crossfire.jxclient.commands.Commands.findCommand
Command findCommand(@NotNull final String commandName)
Definition: Commands.java:70
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.queue.CommandQueue
Definition: CommandQueue.java:38
com.realtime.crossfire.jxclient.commands.HelpCommand.commands
final Commands commands
Definition: HelpCommand.java:46
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.commands.Commands.getCommands
Collection< String > getCommands()
Definition: Commands.java:60
com.realtime.crossfire.jxclient.queue
Definition: CommandQueue.java:23
com.realtime.crossfire
com.realtime.crossfire.jxclient.commands.AbstractCommand.drawInfo
void drawInfo(@NotNull final String message)
Definition: AbstractCommand.java:61
com.realtime
com.realtime.crossfire.jxclient.queue.CommandQueue.sendNcom
void sendNcom(final boolean mustSend, @NotNull final String command)
Definition: CommandQueue.java:184
com
com.realtime.crossfire.jxclient.commands.HelpCommand.HelpCommand
HelpCommand(@NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final CommandQueue commandQueue, @NotNull final Commands commands)
Definition: HelpCommand.java:55
com.realtime.crossfire.jxclient.commands.Commands
Definition: Commands.java:37
com.realtime.crossfire.jxclient.commands.AbstractCommand
Definition: AbstractCommand.java:33
com.realtime.crossfire.jxclient.commands.HelpCommand.allArguments
boolean allArguments()
Definition: HelpCommand.java:62
com.realtime.crossfire.jxclient.commands.HelpCommand.getHelp
String getHelp()
Definition: HelpCommand.java:97
com.realtime.crossfire.jxclient.commands.HelpCommand.execute
void execute(@NotNull final String args)
Definition: HelpCommand.java:67