From aaf6bd00b1682ce22bab036ccd1d1c280d312a4a Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Sat, 24 Dec 2016 05:09:24 +0100 Subject: initial commit --- .../com/encrox/instanceddungeons/DungeonWorld.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/com/encrox/instanceddungeons/DungeonWorld.java (limited to 'src/main/java/com/encrox/instanceddungeons/DungeonWorld.java') 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..643c787 --- /dev/null +++ b/src/main/java/com/encrox/instanceddungeons/DungeonWorld.java @@ -0,0 +1,50 @@ +package com.encrox.instanceddungeons; + +import java.util.ArrayList; + +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 regions; + private int lastX; + + public DungeonWorld(Plugin plugin, World world) { + this.world = world; + this.plugin = plugin; + regions = new ArrayList(); + 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) { + regions.remove(region); + } + + public World getWorld() { + return world; + } + +} -- cgit v1.2.1