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.scripts.ScriptManager;
00025 import com.realtime.crossfire.jxclient.scripts.ScriptProcess;
00026 import com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection;
00027 import java.util.Collection;
00028 import org.jetbrains.annotations.NotNull;
00029
00035 public class ScripttellCommand extends AbstractCommand {
00036
00040 @NotNull
00041 private final ScriptManager scriptManager;
00042
00048 public ScripttellCommand(@NotNull final ScriptManager scriptManager, @NotNull final CrossfireServerConnection crossfireServerConnection) {
00049 super("scripttell", crossfireServerConnection);
00050 this.scriptManager = scriptManager;
00051 }
00052
00056 @Override
00057 public boolean allArguments() {
00058 return false;
00059 }
00060
00064 @Override
00065 public void execute(@NotNull final String args) {
00066 if (args.isEmpty()) {
00067 drawInfoError("Which script do you want to talk to?");
00068 return;
00069 }
00070
00071 final String[] tmp = args.split(" +", 2);
00072 final Collection<ScriptProcess> scriptProcesses = scriptManager.getScripts(tmp[0]);
00073 if (scriptProcesses.isEmpty()) {
00074 drawInfoError(scriptManager.hasScripts() ? "No matching scripts." : "No scripts running.");
00075 return;
00076 }
00077
00078 if (tmp.length < 2) {
00079 drawInfoError("What do you want to tell the script?");
00080 return;
00081 }
00082
00083 final String cmd = "scripttell "+tmp[1];
00084 for (final ScriptProcess scriptProcess : scriptProcesses) {
00085 scriptProcess.commandSent(cmd);
00086 }
00087 }
00088
00089 }