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
00034 public class ScriptkillCommand extends AbstractCommand {
00035
00039 @NotNull
00040 private final ScriptManager scriptManager;
00041
00047 public ScriptkillCommand(@NotNull final ScriptManager scriptManager, @NotNull final CrossfireServerConnection crossfireServerConnection) {
00048 super("scriptkill", crossfireServerConnection);
00049 this.scriptManager = scriptManager;
00050 }
00051
00055 @Override
00056 public boolean allArguments() {
00057 return false;
00058 }
00059
00063 @Override
00064 public void execute(@NotNull final String args) {
00065 final Collection<ScriptProcess> scriptProcesses = scriptManager.getScripts(args);
00066 if (scriptProcesses.isEmpty()) {
00067 drawInfoError(scriptManager.hasScripts() ? "No matching scripts." : "No scripts running.");
00068 return;
00069 }
00070 if (scriptProcesses.size() > 1) {
00071 drawInfoError("More than one script matches: "+scriptProcesses+".");
00072 return;
00073 }
00074 final ScriptProcess scriptProcess = scriptProcesses.iterator().next();
00075 scriptProcess.killScript();
00076 }
00077
00078 }