PlotSquared/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEManager.java

56 lines
2.1 KiB
Java
Raw Normal View History

2015-04-18 15:47:13 +02:00
package com.intellectualcrafters.plot.listeners.worldedit;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
public class WEManager {
public static HashSet<String> bypass = new HashSet<>();
public static boolean maskContains(HashSet<RegionWrapper> mask, int x, int z) {
for (RegionWrapper region : mask) {
if ((x >= region.minX) && (x <= region.maxX) && (z >= region.minZ) && (z <= region.maxZ)) {
return true;
}
}
return false;
}
public static HashSet<RegionWrapper> getMask(PlotPlayer player) {
HashSet<RegionWrapper> regions = new HashSet<>();
UUID uuid = player.getUUID();
for (Plot plot : PlotSquared.getPlots(player.getLocation().getWorld()).values()) {
if (!plot.settings.getMerged(0) && !plot.settings.getMerged(3)) {
if (plot.isOwner(uuid) || plot.trusted.contains(uuid)) {
2015-04-18 15:47:13 +02:00
Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
regions.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()));
}
}
}
return regions;
}
public static boolean intersects(RegionWrapper region1, RegionWrapper region2) {
if ((region1.minX <= region2.maxX) && (region1.maxX >= region2.minX) && (region1.minZ <= region2.maxZ) && (region1.maxZ >= region2.minZ)) {
return true;
}
return false;
}
public static boolean regionContains(RegionWrapper selection, HashSet<RegionWrapper> mask) {
for (RegionWrapper region : mask) {
if (intersects(region, selection)) {
return true;
}
}
return false;
}
}