Crossfire JXClient, Trunk
ScripttellCommand.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 java.util.Collection;
29 import org.jetbrains.annotations.NotNull;
30 
36 public class ScripttellCommand extends AbstractCommand {
37 
41  @NotNull
43 
50  super("scripttell", crossfireServerConnection);
51  this.scriptManager = scriptManager;
52  }
53 
54  @Override
55  public boolean allArguments() {
56  return false;
57  }
58 
59  @Override
60  public void execute(@NotNull final String args) {
61  if (args.isEmpty()) {
62  drawInfoError("Which script do you want to talk to?");
63  return;
64  }
65 
66  final String[] tmp = args.split(" +", 2);
67  final Collection<ScriptProcess> scriptProcesses = scriptManager.getScripts(tmp[0]);
68  if (scriptProcesses.isEmpty()) {
69  drawInfoError(scriptManager.hasScripts() ? "No matching scripts." : "No scripts running.");
70  return;
71  }
72 
73  if (tmp.length < 2) {
74  drawInfoError("What do you want to tell the script?");
75  return;
76  }
77 
78  final String cmd = "scripttell "+tmp[1];
79  for (ScriptProcess scriptProcess : scriptProcesses) {
80  scriptProcess.commandSent(cmd);
81  }
82  }
83 
84  @NotNull
85  @Override
86  public String getHelp() {
87  //noinspection StringBufferReplaceableByString
88  final StringBuilder sb = new StringBuilder();
89  sb.append("Communicates with a running client-sided script\n");
90  sb.append("\n");
91  sb.append("Usage: scripttell <script> <text>\n");
92  sb.append("\n");
93  sb.append("Sends <text> to the client-sided script <script>. ");
94  sb.append("<script> is the ID of a running client-sided script or the partial name of a running client-sided script. ");
95  sb.append("<text> is a text to send to the client-sided script.\n");
96  sb.append("Note: List running client-sided scripts: scripts\n");
97  return sb.toString();
98  }
99 
100 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.server
com.realtime.crossfire.jxclient.scripts.ScriptManager.getScripts
Set< ScriptProcess > getScripts(@NotNull final String partialScriptName)
Definition: ScriptManager.java:163
com.realtime.crossfire.jxclient.commands.AbstractCommand.crossfireServerConnection
final CrossfireServerConnection crossfireServerConnection
Definition: AbstractCommand.java:45
com.realtime.crossfire.jxclient.scripts.ScriptManager
Definition: ScriptManager.java:46
com.realtime.crossfire.jxclient.commands.AbstractCommand.drawInfoError
void drawInfoError(@NotNull final String message)
Definition: AbstractCommand.java:69
com.realtime.crossfire.jxclient.scripts
Definition: AbstractScriptProcess.java:23
com.realtime.crossfire.jxclient.commands.ScripttellCommand.ScripttellCommand
ScripttellCommand(@NotNull final ScriptManager scriptManager, @NotNull final CrossfireServerConnection crossfireServerConnection)
Definition: ScripttellCommand.java:49
com.realtime.crossfire.jxclient.server.crossfire.CrossfireServerConnection
Definition: CrossfireServerConnection.java:37
com.realtime.crossfire.jxclient.commands.ScripttellCommand.getHelp
String getHelp()
Definition: ScripttellCommand.java:86
com.realtime.crossfire.jxclient.scripts.ScriptManager.hasScripts
boolean hasScripts()
Definition: ScriptManager.java:203
com.realtime.crossfire.jxclient.server.crossfire
Definition: AbstractCrossfireServerConnection.java:23
com.realtime.crossfire.jxclient.commands.ScripttellCommand.execute
void execute(@NotNull final String args)
Definition: ScripttellCommand.java:60
com.realtime.crossfire
com.realtime.crossfire.jxclient.scripts.ScriptProcess
Definition: ScriptProcess.java:31
com.realtime
com.realtime.crossfire.jxclient.commands.ScripttellCommand.scriptManager
final ScriptManager scriptManager
Definition: ScripttellCommand.java:42
com
com.realtime.crossfire.jxclient.commands.AbstractCommand
Definition: AbstractCommand.java:33
com.realtime.crossfire.jxclient.commands.ScripttellCommand
Definition: ScripttellCommand.java:36
com.realtime.crossfire.jxclient.commands.ScripttellCommand.allArguments
boolean allArguments()
Definition: ScripttellCommand.java:55