Crossfire JXClient, Trunk
UnbindCommand.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 UnbindCommand extends AbstractCommand {
34 
38  @NotNull
40 
47  super("unbind", crossfireServerConnection);
48  this.commandCallback = commandCallback;
49  }
50 
51  @Override
52  public boolean allArguments() {
53  return false;
54  }
55 
56  @Override
57  public void execute(@NotNull final String args) {
58  final CharSequence commands;
59  final boolean perCharacterBinding;
60  if (args.equals("-c")) {
61  perCharacterBinding = true;
62  commands = "";
63  } else if (args.startsWith("-c ")) {
64  perCharacterBinding = true;
65  commands = args.substring(3).trim();
66  } else {
67  perCharacterBinding = false;
68  commands = args;
69  }
70 
71  if (commands.length() != 0) {
72  drawInfoError("No arguments allowed.");
73  return;
74  }
75 
76  if (!commandCallback.removeKeyBinding(perCharacterBinding)) {
77  drawInfoError("Cannot use unbind -c since no character is logged in.");
78  //noinspection UnnecessaryReturnStatement
79  return;
80  }
81  }
82 
83  @NotNull
84  @Override
85  public String getHelp() {
86  //noinspection StringBufferReplaceableByString
87  final StringBuilder sb = new StringBuilder();
88  sb.append("Unbinds a command from a key\n");
89  sb.append("\n");
90  sb.append("Usage: unbind\n");
91  sb.append("Usage: unbind -c\n");
92  sb.append("\n");
93  sb.append("Asks the user for a key, then de-associates the key from its bound command.\n");
94  sb.append("If the option -c is used, the key is unbound only from the current character. Otherwise the key is unbound from all characters on all Crossfire servers.\n");
95  sb.append("To abort an unbind command, press ESC.\n");
96  sb.append("Note: Bind a key: bind\n");
97  return sb.toString();
98  }
99 
100 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.commands.UnbindCommand.allArguments
boolean allArguments()
Definition: UnbindCommand.java:52
com.realtime.crossfire.jxclient.commands.UnbindCommand.commandCallback
final CommandCallback commandCallback
Definition: UnbindCommand.java:39
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.commands.UnbindCommand.getHelp
String getHelp()
Definition: UnbindCommand.java:85
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback.removeKeyBinding
boolean removeKeyBinding(boolean perCharacter)
com.realtime.crossfire.jxclient.gui.textinput
Definition: ActivateCommandInputCommand.java:23
com.realtime.crossfire.jxclient.gui.textinput.CommandCallback
Definition: CommandCallback.java:33
com.realtime.crossfire.jxclient.commands.AbstractCommand.crossfireServerConnection
final CrossfireServerConnection crossfireServerConnection
Definition: AbstractCommand.java:45
com.realtime.crossfire.jxclient.commands.AbstractCommand.drawInfoError
void drawInfoError(@NotNull final String message)
Definition: AbstractCommand.java:69
com.realtime.crossfire.jxclient.commands.UnbindCommand
Definition: UnbindCommand.java:33
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.gui
com.realtime.crossfire.jxclient.commands.UnbindCommand.UnbindCommand
UnbindCommand(@NotNull final CommandCallback commandCallback, @NotNull final CrossfireServerConnection crossfireServerConnection)
Definition: UnbindCommand.java:46
com.realtime.crossfire.jxclient.commands.UnbindCommand.execute
void execute(@NotNull final String args)
Definition: UnbindCommand.java:57
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire
com.realtime
com
com.realtime.crossfire.jxclient.commands.AbstractCommand
Definition: AbstractCommand.java:33