00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.commands;
00023
00024 import com.realtime.crossfire.jxclient.gui.commandlist.CommandList;
00025 import com.realtime.crossfire.jxclient.gui.commandlist.CommandListType;
00026 import com.realtime.crossfire.jxclient.gui.textinput.CommandCallback;
00027 import com.realtime.crossfire.jxclient.gui.textinput.GUICommandFactory;
00028 import com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection;
00029 import com.realtime.crossfire.jxclient.util.StringUtils;
00030 import org.jetbrains.annotations.NotNull;
00031
00036 public class BindCommand extends AbstractCommand {
00037
00041 @NotNull
00042 private final CommandCallback commandCallback;
00043
00047 @NotNull
00048 private final GUICommandFactory guiCommandFactory;
00049
00056 public BindCommand(@NotNull final CrossfireServerConnection crossfireServerConnection, @NotNull final CommandCallback commandCallback, @NotNull final GUICommandFactory guiCommandFactory) {
00057 super("bind", crossfireServerConnection);
00058 this.commandCallback = commandCallback;
00059 this.guiCommandFactory = guiCommandFactory;
00060 }
00061
00065 @Override
00066 public boolean allArguments() {
00067 return true;
00068 }
00069
00073 @Override
00074 public void execute(@NotNull final String args) {
00075 final String commandList;
00076 final boolean perCharacterBinding;
00077 if (args.equals("-c")) {
00078 perCharacterBinding = true;
00079 commandList = "";
00080 } else if (args.startsWith("-c ")) {
00081 perCharacterBinding = true;
00082 commandList = StringUtils.trimLeading(args.substring(3));
00083 } else {
00084 perCharacterBinding = false;
00085 commandList = args;
00086 }
00087
00088 if (commandList.length() == 0) {
00089 drawInfoError("Which command do you want to bind?");
00090 return;
00091 }
00092
00093 final CommandList commandList2 = new CommandList(CommandListType.AND);
00094 commandList2.add(guiCommandFactory.createCommand(commandList));
00095 if (!commandCallback.createKeyBinding(perCharacterBinding, commandList2)) {
00096 drawInfoError("Cannot use bind -c since no character is logged in.");
00097
00098 return;
00099 }
00100 }
00101
00102 }