SteamWar/BauSystem2.0
Archiviert
12
0

Hotfix Exceptions in InventoryLib
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-07-28 10:46:09 +02:00
Ursprung 9003884dad
Commit 3c30f57e08

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
@ -35,6 +36,7 @@ import org.luaj.vm2.lib.VarArgFunction;
import org.luaj.vm2.lib.ZeroArgFunction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Linked
@ -80,7 +82,14 @@ public class InventoryLib implements LuaLib {
}
LuaFunction handler = args.checkfunction(args.narg());
item.setCallback(clickType -> handler.call(LuaValue.valueOf(clickType.name())));
item.setCallback(clickType -> {
try {
handler.call(LuaValue.valueOf(clickType.name()));
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_CLICK", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
}
});
inventory.setItem(slot, item);
return LuaValue.NIL;
@ -94,7 +103,14 @@ public class InventoryLib implements LuaLib {
Material material = SWItem.getMaterial(args.checkjstring(2));
String name = ChatColor.translateAlternateColorCodes('&', args.checkjstring(3));
LuaFunction handler = args.checkfunction(4);
SWItem item = new SWItem(material, name, clickType -> handler.call(LuaValue.valueOf(clickType.name())));
SWItem item = new SWItem(material, name, clickType -> {
try {
handler.call(LuaValue.valueOf(clickType.name()));
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_CLICK", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
}
});
if (args.narg() >= 5) {
LuaTable lore = args.checktable(5);
@ -122,7 +138,14 @@ public class InventoryLib implements LuaLib {
@Override
public LuaValue call(LuaValue arg) {
LuaFunction function = arg.checkfunction();
inventory.addCloseRunnable(function::call);
inventory.addCloseRunnable(() -> {
try {
function.call();
} catch (Exception e) {
String[] sp = e.getMessage().split(":");
BauSystem.MESSAGE.send("SCRIPT_ERROR_CLICK", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)));
}
});
return LuaValue.NIL;
}
});