Crossfire JXClient, Trunk
AgainCommand.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 
28 import org.jetbrains.annotations.NotNull;
29 
34 public class AgainCommand extends AbstractCommand {
35 
39  @NotNull
41 
45  @NotNull
47 
56  super("again", crossfireServerConnection);
57  this.commandExecutor = commandExecutor;
58  this.commandHistory = commandHistory;
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  drawInfoError("The 'again' command does not take any arguments.");
70  return;
71  }
72 
73  int index = 0;
74  while (true) {
75  final String command = commandHistory.last(index);
76  if (command == null) {
77  drawInfoError("There is no command to repeat.");
78  return;
79  }
80 
81  if (!command.equalsIgnoreCase("again")) {
83  return;
84  }
85 
86  index++;
87  }
88  }
89 
90  @NotNull
91  @Override
92  public String getHelp() {
93  //noinspection StringBufferReplaceableByString
94  final StringBuilder sb = new StringBuilder();
95  sb.append("Repeats the last executed command\n");
96  sb.append("\n");
97  sb.append("Usage: again\n");
98  sb.append("\n");
99  sb.append("Re-runs the last command.\n");
100  return sb.toString();
101  }
102 
103 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.gui.textinput.CommandExecutor.executeCommand
void executeCommand(@NotNull final CharSequence commandLine)
com.realtime.crossfire.jxclient.settings.CommandHistory
Definition: CommandHistory.java:35
com.realtime.crossfire.jxclient.commands.AgainCommand.AgainCommand
AgainCommand(@NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final CommandExecutor commandExecutor, @NotNull final CommandHistory commandHistory)
Definition: AgainCommand.java:55
com.realtime.crossfire.jxclient.gui.textinput
Definition: ActivateCommandInputCommand.java:23
com.realtime.crossfire.jxclient.commands.AgainCommand.allArguments
boolean allArguments()
Definition: AgainCommand.java:62
com.realtime.crossfire.jxclient.commands.AgainCommand.getHelp
String getHelp()
Definition: AgainCommand.java:92
com.realtime.crossfire.jxclient.commands.AbstractCommand.crossfireServerConnection
final CrossfireServerConnection crossfireServerConnection
Definition: AbstractCommand.java:45
com.realtime.crossfire.jxclient.settings
Definition: CommandHistory.java:23
com.realtime.crossfire.jxclient.commands.AbstractCommand.drawInfoError
void drawInfoError(@NotNull final String message)
Definition: AbstractCommand.java:69
com.realtime.crossfire.jxclient.commands.AgainCommand.execute
void execute(@NotNull final String args)
Definition: AgainCommand.java:67
com.realtime.crossfire.jxclient.settings.CommandHistory.last
String last(final int index)
Definition: CommandHistory.java:132
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.commands.AgainCommand
Definition: AgainCommand.java:34
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.gui.textinput.CommandExecutor
Definition: CommandExecutor.java:31
com.realtime.crossfire.jxclient.commands.AgainCommand.commandExecutor
final CommandExecutor commandExecutor
Definition: AgainCommand.java:40
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.commands.AbstractCommand
Definition: AbstractCommand.java:33
com.realtime.crossfire.jxclient.commands.AgainCommand.commandHistory
final CommandHistory commandHistory
Definition: AgainCommand.java:46