SteamWar/BauSystem2.0
Archiviert
12
0

Merge branch 'master' into TestBlockPaste-Without-Water
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
YoyoNow 2023-08-19 23:29:10 +02:00
Commit eec5e97842
3 geänderte Dateien mit 25 neuen und 30 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)));
}
}
}

Datei anzeigen

@ -25,6 +25,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptRunner;
import de.steamwar.bausystem.features.script.lua.libs.LuaLib;
import de.steamwar.bausystem.features.world.WorldEditListener;
import de.steamwar.bausystem.utils.WorldEditUtils;
@ -79,7 +80,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
LuaFunction callback = arg2.checkfunction();
SWAnvilInv inv = new SWAnvilInv(player, message);
inv.setCallback(s -> callback.call(valueOf(s)));
inv.setCallback(s -> ScriptRunner.catchScript("SCRIPT_ERROR_CLICK", player, () -> callback.call(valueOf(s))));
inv.open();
return LuaValue.NIL;
@ -91,7 +92,7 @@ public class SteamWarLuaPlugin extends TwoArgFunction {
long time = arg1.checklong();
LuaFunction callback = arg2.checkfunction();
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> callback.call(), time);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> ScriptRunner.catchScript("SCRIPT_ERROR_CLICK", player, callback::call), time);
return LuaValue.NIL;
}
});