From 2a6ef53c25ee112019d75133e7a0cf57939b0aff Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 17 Nov 2024 11:46:17 +0700 Subject: [PATCH] fix: make servereval run in executorService --- .../commands/ServerEvalCommand.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/ServerEvalCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/ServerEvalCommand.java index cd981a9b..64191d28 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/ServerEvalCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/ServerEvalCommand.java @@ -26,24 +26,26 @@ public class ServerEvalCommand extends Command { @Override public Component execute(CommandContext context) throws CommandException { - try { - final Bot bot = context.bot; + final Bot bot = context.bot; - final Globals globals = JsePlatform.standardGlobals(); + bot.executorService.submit(() -> { + try { + final Globals globals = JsePlatform.standardGlobals(); - globals.set("bot", CoerceJavaToLua.coerce(bot)); - globals.set("class", CoerceJavaToLua.coerce(Class.class)); - globals.set("context", CoerceJavaToLua.coerce(context)); + globals.set("bot", CoerceJavaToLua.coerce(bot)); + globals.set("class", CoerceJavaToLua.coerce(Class.class)); + globals.set("context", CoerceJavaToLua.coerce(context)); - LuaValue chunk = globals.load(context.getString(true, true)); + LuaValue chunk = globals.load(context.getString(true, true)); - final LuaValue output = chunk.call(); + final LuaValue output = chunk.call(); - return Component.text(output.toString()).color(NamedTextColor.GREEN); - } catch (CommandException e) { - throw e; - } catch (Exception e) { - throw new CommandException(Component.text(e.toString())); - } + context.sendOutput(Component.text(output.toString()).color(NamedTextColor.GREEN)); + } catch (Exception e) { + context.sendOutput(Component.text(e.toString()).color(NamedTextColor.RED)); + } + }); + + return null; } }