summaryrefslogtreecommitdiff
path: root/src/main/java/com/encrox/zombie/ZombieWorld.java
diff options
context:
space:
mode:
authorLeonard Kugis <leonard@kug.is>2022-04-25 18:50:36 +0200
committerLeonard Kugis <leonard@kug.is>2022-04-25 18:50:36 +0200
commit9e2ddeb55321b09086a5a27254197d783847e6e3 (patch)
tree620e4a7b326df2a77fff51aff390e0a6bef43631 /src/main/java/com/encrox/zombie/ZombieWorld.java
Initial commitHEADmaster
Diffstat (limited to 'src/main/java/com/encrox/zombie/ZombieWorld.java')
-rwxr-xr-xsrc/main/java/com/encrox/zombie/ZombieWorld.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/com/encrox/zombie/ZombieWorld.java b/src/main/java/com/encrox/zombie/ZombieWorld.java
new file mode 100755
index 0000000..52ddea8
--- /dev/null
+++ b/src/main/java/com/encrox/zombie/ZombieWorld.java
@@ -0,0 +1,79 @@
+package com.encrox.zombie;
+
+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.worldguard.protection.regions.ProtectedCuboidRegion;
+import com.sk89q.worldguard.protection.regions.ProtectedRegion;
+
+public class ZombieWorld {
+
+ private Plugin plugin;
+ private World world;
+ private ArrayList<ProtectedRegion> regions;
+ private int lastX;
+
+ public ZombieWorld(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;
+ }
+ }
+ }
+
+ public InstancedProtectedCuboidRegion allocate(Schematic schematic) {
+ 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+schematic.width, 255, schematic.length))).getIntersectingRegions(regions).isEmpty()) {
+ region = new InstancedProtectedCuboidRegion(plugin, world, ""+min.getBlockX(), min, max);
+ schematic.reset();
+ for(int y = 0; y<schematic.height; y++) {
+ for(int z = 0; z<schematic.length; z++) {
+ for(int x = 0; x<schematic.width; x++) {
+ //System.out.println("block set at: (" + (min.getBlockX()+x) + ", " + (64+y) + ", " + (min.getBlockZ()+z) + ")");
+ world.getBlockAt(min.getBlockX()+x, 64+y, min.getBlockZ()+z).setType(Material.getMaterial(schematic.getBlockIdAt(x, y, z)));
+ world.getBlockAt(min.getBlockX()+x, 64+y, min.getBlockZ()+z).setData(schematic.getDataAt(x, y, z));;
+ }
+ }
+ }
+ 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;
+ }
+
+}