Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
dce679afa2
Commit
98b5b8605e
@ -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> 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;
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren