Fix some more stuff

This commit is contained in:
2025-08-02 13:25:22 +02:00
parent 3bb84d0dcc
commit 7dc9da549c
8 changed files with 39 additions and 29 deletions
@@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.script.lua.libs;
import de.steamwar.bausystem.features.loader.Loader;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionSystem;
import de.steamwar.bausystem.region.flags.*;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@@ -28,6 +29,7 @@ import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.OneArgFunction;
import java.util.UUID;
import java.util.function.Supplier;
@Linked
@@ -41,13 +43,14 @@ public class RegionLib implements LuaLib {
private LuaTable create(Supplier<Region> region, Player player) {
LuaTable table = LuaValue.tableOf();
table.set("name", getter(() -> region.get().getName()));
table.set("name", getter(() -> region.get().getID().toString()));
table.set("id", getter(() -> region.get().getID().toString()));
table.set("type", getter(() -> {
Region region1 = region.get();
if (region1.getType().isGlobal()) {
return "global";
}
return region1.getPrototype().getName();
return region1.getType().name().toLowerCase();
}));
LuaValue tntLib = LuaValue.tableOf();
@@ -72,16 +75,16 @@ public class RegionLib implements LuaLib {
Loader loader = Loader.getLoader(player);
table.set("loader", getter(() -> loader == null ? "OFF" : loader.getStage().name()));
table.set("copyPoint", getter(() -> toPos(region.get().getCopyPoint())));
table.set("minPointBuild", getter(() -> toPos(region.get().getMinPointBuild())));
table.set("maxPointBuild", getter(() -> toPos(region.get().getMaxPointBuild())));
table.set("minPointBuildExtension", getter(() -> toPos(region.get().getMinPointBuildExtension())));
table.set("maxPointBuildExtension", getter(() -> toPos(region.get().getMaxPointBuildExtension())));
table.set("testblockPoint", getter(() -> toPos(region.get().getTestBlockPoint())));
table.set("minPointTestblock", getter(() -> toPos(region.get().getMinPointTestblock())));
table.set("maxPointTestblock", getter(() -> toPos(region.get().getMaxPointTestblock())));
table.set("minPointTestblockExtension", getter(() -> toPos(region.get().getMinPointTestblockExtension())));
table.set("maxPointTestblockExtension", getter(() -> toPos(region.get().getMaxPointTestblockExtension())));
table.set("copyPoint", getter(() -> toPos(region.get().getBuildArea().getCopyPoint())));
table.set("minPointBuild", getter(() -> toPos(region.get().getBuildArea().getMinPoint(false))));
table.set("maxPointBuild", getter(() -> toPos(region.get().getBuildArea().getMinPoint(false))));
table.set("minPointBuildExtension", getter(() -> toPos(region.get().getBuildArea().getMinPoint(true))));
table.set("maxPointBuildExtension", getter(() -> toPos(region.get().getBuildArea().getMinPoint(true))));
table.set("testblockPoint", getter(() -> toPos(region.get().getTestblockArea().getCopyPoint())));
table.set("minPointTestblock", getter(() -> toPos(region.get().getTestblockArea().getMinPoint(false))));
table.set("maxPointTestblock", getter(() -> toPos(region.get().getTestblockArea().getMinPoint(false))));
table.set("minPointTestblockExtension", getter(() -> toPos(region.get().getTestblockArea().getMinPoint(true))));
table.set("maxPointTestblockExtension", getter(() -> toPos(region.get().getTestblockArea().getMinPoint(true))));
return table;
}
@@ -92,11 +95,11 @@ public class RegionLib implements LuaLib {
table.set("get", new OneArgFunction() {
@Override
public LuaValue call(LuaValue arg) {
return create(() -> Region.getREGION_MAP().get(arg.checkjstring()), player);
return create(() -> RegionSystem.INSTANCE.getRegion(UUID.fromString(arg.checkjstring())).orElse(RegionSystem.INSTANCE.getGlobalRegion()), player);
}
});
table.set("list", getter(() -> LuaValue.listOf(Region.getREGION_MAP().values().stream().map(region -> create(() -> region, player)).toArray(LuaTable[]::new))));
table.set("list", getter(() -> LuaValue.listOf(RegionSystem.INSTANCE.getRegions().map(region -> create(() -> region, player)).toArray(LuaTable[]::new))));
return table;
}
@@ -75,7 +75,7 @@ public class StorageLib implements LuaLib, Enable, Disable {
jsonObject.keySet().forEach(key -> {
map.put(key, fromJson(jsonObject.get(key)));
});
Region region = RegionSystem.INSTANCE.getRegion(regionStorage.getName().substring(0, regionStorage.getName().length() - ".json".length())).orElse(null);
Region region = RegionSystem.INSTANCE.getRegion(UUID.fromString(regionStorage.getName().substring(0, regionStorage.getName().length() - ".json".length()))).orElse(null);
REGION_STORAGE.put(region, map);
} catch (Exception e) {}
}
@@ -144,7 +144,7 @@ public class StorageLib implements LuaLib, Enable, Disable {
regionStorageDirectory.mkdirs();
for (Map.Entry<Region, HashMap<String, LuaValue>> entry : REGION_STORAGE.entrySet()) {
try {
FileWriter fileWriter = new FileWriter(new File(regionStorageDirectory, entry.getKey().getName() + ".json"));
FileWriter fileWriter = new FileWriter(new File(regionStorageDirectory, entry.getKey().getID().toString() + ".json"));
gson.toJson(toJson(entry.getValue()), fileWriter);
fileWriter.close();
} catch (IOException e) {}