From dee8651e6170fe34a80bfcce01886802c3d328d0 Mon Sep 17 00:00:00 2001 From: P0nk Date: Tue, 21 May 2024 21:36:54 +0200 Subject: [PATCH] Add DevtestCommand to easily test without restarting server --- scripts/devtest.js | 3 ++ .../java/client/command/CommandsExecutor.java | 2 + .../command/commands/gm6/DevtestCommand.java | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 scripts/devtest.js create mode 100644 src/main/java/client/command/commands/gm6/DevtestCommand.java diff --git a/scripts/devtest.js b/scripts/devtest.js new file mode 100644 index 0000000000..c2b5abe462 --- /dev/null +++ b/scripts/devtest.js @@ -0,0 +1,3 @@ +function run(chr) { + chr.message("devtest.js") +} diff --git a/src/main/java/client/command/CommandsExecutor.java b/src/main/java/client/command/CommandsExecutor.java index a95e5943e2..16de527825 100644 --- a/src/main/java/client/command/CommandsExecutor.java +++ b/src/main/java/client/command/CommandsExecutor.java @@ -184,6 +184,7 @@ import client.command.commands.gm5.ShowSessionsCommand; import client.command.commands.gm6.ClearQuestCacheCommand; import client.command.commands.gm6.ClearQuestCommand; import client.command.commands.gm6.DCAllCommand; +import client.command.commands.gm6.DevtestCommand; import client.command.commands.gm6.EraseAllPNpcsCommand; import client.command.commands.gm6.GetAccCommand; import client.command.commands.gm6.MapPlayersCommand; @@ -556,6 +557,7 @@ public class CommandsExecutor { addCommand("addworld", 6, ServerAddWorldCommand.class); addCommand("removechannel", 6, ServerRemoveChannelCommand.class); addCommand("removeworld", 6, ServerRemoveWorldCommand.class); + addCommand("devtest", 6, DevtestCommand.class); commandsNameDesc.add(levelCommandsCursor); } diff --git a/src/main/java/client/command/commands/gm6/DevtestCommand.java b/src/main/java/client/command/commands/gm6/DevtestCommand.java new file mode 100644 index 0000000000..c0fd30dd57 --- /dev/null +++ b/src/main/java/client/command/commands/gm6/DevtestCommand.java @@ -0,0 +1,40 @@ +package client.command.commands.gm6; + +import client.Client; +import client.command.Command; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import scripting.AbstractScriptManager; + +import javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptException; + +public class DevtestCommand extends Command { + { + setDescription("Runs devtest.js. Developer utility - test stuff without restarting the server."); + } + + private static final Logger log = LoggerFactory.getLogger(DevtestCommand.class); + + private static class DevtestScriptManager extends AbstractScriptManager { + + @Override + public ScriptEngine getInvocableScriptEngine(String path) { + return super.getInvocableScriptEngine(path); + } + + } + + @Override + public void execute(Client client, String[] params) { + DevtestScriptManager scriptManager = new DevtestScriptManager(); + ScriptEngine scriptEngine = scriptManager.getInvocableScriptEngine("devtest.js"); + try { + Invocable invocable = (Invocable) scriptEngine; + invocable.invokeFunction("run", client.getPlayer()); + } catch (ScriptException | NoSuchMethodException e) { + log.info("devtest.js run() threw an exception", e); + } + } +}