SteamWar/BauSystem2.0
Archiviert
12
0

Fix RegionLib in Gloal scripts
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-08-19 23:30:20 +02:00
Ursprung dce679afa2
Commit 98b5b8605e

Datei anzeigen

@ -35,37 +35,38 @@ import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue; import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.OneArgFunction; import org.luaj.vm2.lib.OneArgFunction;
import java.util.function.Supplier;
@Linked @Linked
public class RegionLib implements LuaLib { public class RegionLib implements LuaLib {
@Override @Override
public String name() { public String name() {
return "region"; return "region";
} }
private LuaTable create(Region region, Player player) { private LuaTable create(Supplier<Region> region, Player player) {
LuaTable table = LuaValue.tableOf(); LuaTable table = LuaValue.tableOf();
table.set("name", getter(() -> region.getName())); table.set("name", getter(() -> region.get().getName()));
table.set("type", getter(() -> region.getPrototype().getName())); table.set("type", getter(() -> region.get().getPrototype().getName()));
LuaValue tntLib = LuaValue.tableOf(); LuaValue tntLib = LuaValue.tableOf();
tntLib.set("mode", getter(() -> region.getPlain(Flag.TNT, TNTMode.class).name())); tntLib.set("mode", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class).name()));
tntLib.set("enabled", getter(() -> region.getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY)); tntLib.set("enabled", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY));
tntLib.set("onlyTb", getter(() -> region.getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB)); tntLib.set("onlyTb", getter(() -> region.get().getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB));
table.set("tnt", tntLib); table.set("tnt", tntLib);
table.set("fire", getter(() -> region.getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW)); table.set("fire", getter(() -> region.get().getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW));
table.set("freeze", getter(() -> region.getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE)); table.set("freeze", getter(() -> region.get().getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE));
table.set("protect", getter(() -> region.getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE)); table.set("protect", getter(() -> region.get().getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE));
LuaValue traceLib = LuaValue.tableOf(); LuaValue traceLib = LuaValue.tableOf();
traceLib.set("active", getter(() -> !region.isGlobal() && Recorder.INSTANCE.get(region) instanceof ActiveTracer)); traceLib.set("active", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof ActiveTracer));
traceLib.set("auto", getter(() -> !region.isGlobal() && Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder)); traceLib.set("auto", getter(() -> !region.get().isGlobal() && Recorder.INSTANCE.get(region.get()) instanceof AutoTraceRecorder));
traceLib.set("status", getter(() -> Recorder.INSTANCE.get(region).scriptState())); traceLib.set("status", getter(() -> Recorder.INSTANCE.get(region.get()).scriptState()));
traceLib.set("time", getter(() -> Recorder.INSTANCE.get(region).scriptTime())); traceLib.set("time", getter(() -> Recorder.INSTANCE.get(region.get()).scriptTime()));
table.set("trace", traceLib); table.set("trace", traceLib);
@ -77,15 +78,15 @@ public class RegionLib implements LuaLib {
@Override @Override
public LuaTable get(Player player) { 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() { table.set("get", new OneArgFunction() {
@Override @Override
public LuaValue call(LuaValue arg) { 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; return table;
} }