PlotSquared/Core/src/main/java/com/plotsquared/listener/WEManager.java

73 lines
2.6 KiB
Java
Raw Normal View History

package com.plotsquared.listener;
2015-04-18 15:47:13 +02:00
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings;
2015-08-13 19:22:32 +02:00
import com.intellectualcrafters.plot.flag.FlagManager;
2015-04-18 15:47:13 +02:00
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
2016-02-10 19:59:51 +01:00
import com.intellectualcrafters.plot.object.PlotArea;
2015-04-18 15:47:13 +02:00
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
2016-03-23 02:41:37 +01:00
import java.util.HashSet;
import java.util.UUID;
2015-09-13 06:04:31 +02:00
public class WEManager {
2016-03-23 02:41:37 +01:00
public static boolean maskContains(HashSet<RegionWrapper> mask, int x, int y, int z) {
for (RegionWrapper region : mask) {
2015-09-13 06:04:31 +02:00
if (region.isIn(x, y, z)) {
return true;
}
2015-09-01 00:51:51 +02:00
}
return false;
}
2016-03-23 02:41:37 +01:00
public static boolean maskContains(HashSet<RegionWrapper> mask, int x, int z) {
for (RegionWrapper region : mask) {
2015-09-13 06:04:31 +02:00
if (region.isIn(x, z)) {
return true;
}
2015-04-18 15:47:13 +02:00
}
return false;
}
2016-03-23 02:41:37 +01:00
public static HashSet<RegionWrapper> getMask(PlotPlayer player) {
HashSet<RegionWrapper> regions = new HashSet<>();
UUID uuid = player.getUUID();
Location location = player.getLocation();
String world = location.getWorld();
2016-02-10 19:59:51 +01:00
if (!PS.get().hasPlotArea(world)) {
regions.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE));
return regions;
}
2016-02-10 19:59:51 +01:00
PlotArea area = player.getApplicablePlotArea();
if (area == null) {
return regions;
}
2016-03-23 02:41:37 +01:00
for (Plot plot : area.getPlots()) {
2015-10-07 08:33:33 +02:00
if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && (FlagManager.getPlotFlagRaw(plot, "done") != null))) {
continue;
}
2016-03-23 02:41:37 +01:00
if (Settings.WE_ALLOW_HELPER && plot.isAdded(uuid) || !Settings.WE_ALLOW_HELPER && (plot.isOwner(uuid) || plot.getTrusted()
.contains(uuid))) {
2016-02-10 19:59:51 +01:00
regions.addAll(plot.getRegions());
2015-04-18 15:47:13 +02:00
}
}
return regions;
}
2016-03-23 02:41:37 +01:00
public static boolean intersects(RegionWrapper region1, RegionWrapper region2) {
2015-07-27 19:50:04 +02:00
return (region1.minX <= region2.maxX) && (region1.maxX >= region2.minX) && (region1.minZ <= region2.maxZ) && (region1.maxZ >= region2.minZ);
2015-04-18 15:47:13 +02:00
}
2016-03-23 02:41:37 +01:00
public static boolean regionContains(RegionWrapper selection, HashSet<RegionWrapper> mask) {
for (RegionWrapper region : mask) {
2015-09-13 06:04:31 +02:00
if (intersects(region, selection)) {
return true;
}
2015-04-18 15:47:13 +02:00
}
return false;
}
}