diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java index cd0db428..15ce60bb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java @@ -112,7 +112,12 @@ public class ScriptRunner { }); for (LuaFunction luaFunction : luaFunctions) { - luaFunction.call(eventValue); + try { + luaFunction.call(eventValue); + } catch (Exception e) { + String[] sp = e.getMessage().split(":"); + BauSystem.MESSAGE.send("SCRIPT_ERROR_GLOBAL", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length))); + } } return cancelled.get(); @@ -124,12 +129,22 @@ public class ScriptRunner { return false; } - commandRegister.getFunction().call(args); + try { + commandRegister.getFunction().call(args); + } catch (Exception e) { + String[] sp = e.getMessage().split(":"); + BauSystem.MESSAGE.send("SCRIPT_ERROR_GLOBAL", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length))); + } return true; } public static void callHotkey(int mods, int key, Player player, boolean pressed) { Hotkey hotkey = Hotkey.fromChar(key, mods); - HOTKEY_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))); + try { + HOTKEY_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))); + } catch (Exception e) { + String[] sp = e.getMessage().split(":"); + BauSystem.MESSAGE.send("SCRIPT_ERROR_GLOBAL", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length))); + } } }