summaryrefslogtreecommitdiff
path: root/src/main/java/com/encrox/instanceddungeons/DungeonWorld.java
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2022-04-25 18:40:22 +0200
committerLeonard Kugis <leonard@kug.is>2022-04-25 18:40:22 +0200
commit9420b8c5ef71dee01d7e19160992c34d5feef154 (patch)
tree5c31e9c3ff1e0bebeff4b164d739c46abbee7c7b /src/main/java/com/encrox/instanceddungeons/DungeonWorld.java
parenteaed2149f9f018a4486828fea612c7322af32171 (diff)
Diffstat (limited to 'src/main/java/com/encrox/instanceddungeons/DungeonWorld.java')
-rw-r--r--src/main/java/com/encrox/instanceddungeons/DungeonWorld.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/main/java/com/encrox/instanceddungeons/DungeonWorld.java b/src/main/java/com/encrox/instanceddungeons/DungeonWorld.java
new file mode 100644
index 0000000..7d4b99c
--- /dev/null
+++ b/src/main/java/com/encrox/instanceddungeons/DungeonWorld.java
@@ -0,0 +1,59 @@
+package com.encrox.instanceddungeons;
+
+import java.util.ArrayList;
+
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.plugin.Plugin;
+
+import com.encrox.instancedregions.InstancedProtectedCuboidRegion;
+import com.sk89q.worldedit.BlockVector;
+import com.sk89q.worldedit.BlockVector2D;
+import com.sk89q.worldedit.regions.CuboidRegion;
+import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
+
+public class DungeonWorld {
+
+ private Plugin plugin;
+ private World world;
+ private ArrayList<ProtectedRegion> regions;
+ private int lastX;
+
+ public DungeonWorld(Plugin plugin, World world) {
+ this.world = world;
+ this.plugin = plugin;
+ regions = new ArrayList<ProtectedRegion>();
+ lastX = 0;
+ }
+
+ public InstancedProtectedCuboidRegion allocate(int width, int length) {
+ BlockVector min, max;
+ InstancedProtectedCuboidRegion region;
+ for(int i = 0; true; i+=16) {
+ if(new ProtectedCuboidRegion("current", (min = new BlockVector(lastX+i, 0, 0)), (max = new BlockVector(lastX+i+width, 255, length))).getIntersectingRegions(regions).isEmpty()) {
+ region = new InstancedProtectedCuboidRegion(plugin, world, ""+min.getBlockX(), min, max);
+ regions.add(region);
+ return region;
+ }
+ }
+ }
+
+ //YOU STILL HAVE TO DISPOSE THE INSTANCED REGION MANUALLY!
+ public void deallocate(InstancedProtectedCuboidRegion region) {
+ BlockVector min = region.getMinimumPoint(), max = region.getMaximumPoint();
+ for(int y = min.getBlockY(), ymax = max.getBlockY(); y<ymax; y++) {
+ for(int z = min.getBlockZ(), zmax = max.getBlockZ(); z<zmax; z++) {
+ for(int x = min.getBlockX(), xmax = max.getBlockX(); x<xmax; x++) {
+ world.getBlockAt(x, y, z).setType(Material.AIR);
+ }
+ }
+ }
+ regions.remove(region);
+ }
+
+ public World getWorld() {
+ return world;
+ }
+
+}