From 5f0ac969d5ff029f34145222fd5f05cd7f4fa2d7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 17 Jul 2023 17:22:10 +0200 Subject: [PATCH] Throw on global methods in local Signed-off-by: Chaoscaot --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../features/script/lua/SteamWarPlatform.java | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index cd9c3fcc..20842c72 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -233,6 +233,7 @@ GUI_EDITOR_TITLE_MORE=Select item SCRIPT_ERROR_GUI=§cError in parsing script: Line {0} SCRIPT_ERROR_GLOBAL=§cError in global script: Line {0} SCRIPT_ERROR_CLICK=§cError in script: Line {0} +SCRIPT_ERROR_ONLY_IN_GLOBAL=§cThis function is only available in global scripts ## CustomScript SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 38c34e4d..32c5e03d 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -230,6 +230,7 @@ GUI_EDITOR_TITLE_MORE=Item auswählen SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} SCRIPT_COMMAND_ITEM_NAME = §7Befehl§8: §e/{0} +SCRIPT_ERROR_ONLY_IN_GLOBAL=§cDieses Skript kann nur als globales Skript ausgeführt werden ## Script Menu GUI SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Klicke zum rausnehmen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java index 1d65f680..a35ede6e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java @@ -19,9 +19,11 @@ package de.steamwar.bausystem.features.script.lua; +import de.steamwar.bausystem.BauSystem; import org.bukkit.entity.Player; import org.luaj.vm2.Globals; import org.luaj.vm2.LoadState; +import org.luaj.vm2.LuaError; import org.luaj.vm2.LuaFunction; import org.luaj.vm2.compiler.LuaC; import org.luaj.vm2.lib.Bit32Lib; @@ -46,6 +48,14 @@ public class SteamWarPlatform { globals.load(new StringLib()); globals.load(new SteamWarLuaPlugin(player)); + globals.load(new SteamWarGlobalLuaPlugin((eventType, luaFunction) -> { + throw new LuaError(BauSystem.MESSAGE.parse("SCRIPT_ERROR_ONLY_IN_GLOBAL", player)); + }, (s, luaFunction) -> { + throw new LuaError(BauSystem.MESSAGE.parse("SCRIPT_ERROR_ONLY_IN_GLOBAL", player)); + }, commandRegister -> { + throw new LuaError(BauSystem.MESSAGE.parse("SCRIPT_ERROR_ONLY_IN_GLOBAL", player)); + })); + LoadState.install(globals); LuaC.install(globals); return globals;