SteamWar/BauSystem2.0
Archiviert
12
0

Fix Error Messages
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Chaoscaot <chaoscaot@zohomail.eu>
Dieser Commit ist enthalten in:
Chaoscaot 2023-08-02 12:42:55 +02:00
Ursprung 82b385e5ff
Commit 02c095a946
Signiert von: Chaoscaot
GPG-Schlüssel-ID: BDF8FADD7D5EDB7A
2 geänderte Dateien mit 22 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -250,7 +250,7 @@ SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eInsert
SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Click with a book to insert
SCRIPT_MENU_GUI_ENTER_NAME = §eEnter a name
SCRIPT_DEPRECATED=§cThe function §8'§e{0}§8'§c is deprecated and will be removed in the future. Please use §8'§e{1}§8'§c instead.
SCRIPT_DEPRECATED=§cThe function §8\'§e{0}§8\'§c is deprecated and will be removed in the future. Please use §8\'§e{1}§8\'§c instead.
# Shield Printing
SHIELD_PRINTING_HELP_START = §8/§eshieldprinting start §8- §7Starts the shield printing

Datei anzeigen

@ -50,13 +50,7 @@ public class ScriptRunner {
public static void runScript(String script, Player player) {
Globals globals = SteamWarPlatform.createClickGlobals(player);
try {
globals.load(script).call();
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_CLICK", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
}
catchScript("SCRIPT_ERROR_CLICK", player, () -> globals.load(script).call());
}
public static void updateGlobalScript(Player player) {
@ -72,12 +66,7 @@ public class ScriptRunner {
commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister));
for (String script : scripts) {
try {
globals.load(script).call();
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_GLOBAL", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
}
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> globals.load(script).call());
}
}
@ -119,13 +108,10 @@ public class ScriptRunner {
});
}
final LuaValue finalEventValue = eventValue;
for (LuaFunction luaFunction : luaFunctions) {
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)));
}
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> luaFunction.call(finalEventValue));
}
if (wrappedEvent instanceof Cancellable) {
@ -192,22 +178,30 @@ public class ScriptRunner {
}
});
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)));
}
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> commandRegister.getFunction().call(args));
return true;
}
public static void callHotkey(int mods, int key, Player player, boolean pressed) {
Hotkey hotkey = Hotkey.fromChar(key, mods);
catchScript("SCRIPT_ERROR_GLOBAL", player, () -> HOTKEY_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))));
}
public static void catchScript(String errorMsg, Player player, Runnable run) {
try {
HOTKEY_MAP.getOrDefault(player, Collections.emptyMap()).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed)));
run.run();
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_GLOBAL", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
int index = 0;
for (int i = sp.length - 1; i >= 0; i--) {
String[] ss = sp[i].split(" ");
boolean num = ss[0].chars().mapToObj(Character::isDigit).allMatch(b -> b);
if (num && !ss[0].isEmpty()) {
index = i;
break;
}
}
BauSystem.MESSAGE.send(errorMsg, player, String.join(":", Arrays.copyOfRange(sp, index, sp.length)));
}
}
}