From 98b5b8605ef29083312d1d9b883fdf21d06a4642 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 23:30:20 +0200 Subject: [PATCH] Fix RegionLib in Gloal scripts Signed-off-by: yoyosource --- .../features/script/lua/libs/RegionLib.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java index f0fc72ad..0f3104cf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -35,37 +35,38 @@ import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaValue; import org.luaj.vm2.lib.OneArgFunction; +import java.util.function.Supplier; + @Linked public class RegionLib implements LuaLib { - @Override public String name() { return "region"; } - private LuaTable create(Region region, Player player) { + private LuaTable create(Supplier region, Player player) { LuaTable table = LuaValue.tableOf(); - table.set("name", getter(() -> region.getName())); - table.set("type", getter(() -> region.getPrototype().getName())); + table.set("name", getter(() -> region.get().getName())); + table.set("type", getter(() -> region.get().getPrototype().getName())); LuaValue tntLib = LuaValue.tableOf(); - tntLib.set("mode", getter(() -> region.getPlain(Flag.TNT, TNTMode.class).name())); - tntLib.set("enabled", getter(() -> region.getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY)); - tntLib.set("onlyTb", getter(() -> region.getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB)); + tntLib.set("mode", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class).name())); + tntLib.set("enabled", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY)); + tntLib.set("onlyTb", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB)); table.set("tnt", tntLib); - table.set("fire", getter(() -> region.getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW)); - table.set("freeze", getter(() -> region.getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE)); - table.set("protect", getter(() -> region.getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE)); + table.set("fire", getter(() -> region.get().getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW)); + table.set("freeze", getter(() -> region.get().getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE)); + table.set("protect", getter(() -> region.get().getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE)); LuaValue traceLib = LuaValue.tableOf(); - traceLib.set("active", getter(() -> !region.isGlobal() && Recorder.INSTANCE.get(region) instanceof ActiveTracer)); - traceLib.set("auto", getter(() -> !region.isGlobal() && Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder)); - traceLib.set("status", getter(() -> Recorder.INSTANCE.get(region).scriptState())); - traceLib.set("time", getter(() -> Recorder.INSTANCE.get(region).scriptTime())); + traceLib.set("active", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof ActiveTracer)); + traceLib.set("auto", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof AutoTraceRecorder)); + traceLib.set("status", getter(() -> Recorder.INSTANCE.get(region.get()).scriptState())); + traceLib.set("time", getter(() -> Recorder.INSTANCE.get(region.get()).scriptTime())); table.set("trace", traceLib); @@ -77,15 +78,15 @@ public class RegionLib implements LuaLib { @Override public LuaTable get(Player player) { - LuaTable table = create(Region.getRegion(player.getLocation()), player); + LuaTable table = create(() -> Region.getRegion(player.getLocation()), player); table.set("get", new OneArgFunction() { @Override public LuaValue call(LuaValue arg) { - return create(Region.getREGION_MAP().get(arg.checkjstring()), player); + return create(() -> Region.getREGION_MAP().get(arg.checkjstring()), player); } }); - table.set("list", getter(() -> LuaValue.listOf(Region.getREGION_MAP().values().stream().map(region -> create(region, player)).toArray(LuaValue[]::new)))); + table.set("list", getter(() -> LuaValue.listOf(Region.getREGION_MAP().values().stream().map(region -> create(() -> region, player)).toArray(LuaValue[]::new)))); return table; }