Reworked entire chunk checking + code cleanup

This commit is contained in:
Spathi 2011-08-31 02:13:16 +01:00
parent 445d10afb7
commit c5f88fe716

View File

@ -16,7 +16,9 @@ import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
import org.bukkit.*; import org.bukkit.World;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -71,21 +73,21 @@ public class Worldguard {
// False: No regions found within chunk // False: No regions found within chunk
public static boolean checkForRegionsInChunk(Location loc) { public static boolean checkForRegionsInChunk(Location loc) {
if(isEnabled()) { if(isEnabled()) {
int plocX = loc.getBlockX();
int plocZ = loc.getBlockZ();
World world = loc.getWorld(); World world = loc.getWorld();
Chunk chunk = world.getChunkAt(loc);
int minChunkX = chunk.getX() * 16;
int minChunkZ = chunk.getZ() * 16;
int maxChunkX = minChunkX + 15;
int maxChunkZ = minChunkZ + 15;
Chunk chunk = world.getChunkAt(plocX, plocZ); int worldHeight = world.getMaxHeight(); // Allow for heights other than default
int chunkX = chunk.getX();
int chunkZ = chunk.getZ();
BlockVector minChunk = new BlockVector(chunkX, 0, chunkZ); BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ);
BlockVector maxChunk = new BlockVector(chunkX+15, 128, chunkZ+15); BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ);
RegionManager regionManager = wg.getRegionManager(world); RegionManager regionManager = wg.getRegionManager(world);
ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk); ProtectedCuboidRegion region = new ProtectedCuboidRegion("wgfactionoverlapcheck", minChunk, maxChunk);
Map<String, ProtectedRegion> allregions = regionManager.getRegions(); Map<String, ProtectedRegion> allregions = regionManager.getRegions();
List<ProtectedRegion> allregionslist = new ArrayList<ProtectedRegion>(allregions.values()); List<ProtectedRegion> allregionslist = new ArrayList<ProtectedRegion>(allregions.values());
List<ProtectedRegion> overlaps; List<ProtectedRegion> overlaps;
boolean foundregions = false; boolean foundregions = false;