2015-09-07 14:17:48 +02:00
|
|
|
package com.plotsquared.listener;
|
2015-04-18 15:47:13 +02:00
|
|
|
|
2015-07-30 16:25:16 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-07-03 14:15:20 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2015-06-11 09:12:39 +02:00
|
|
|
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;
|
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class WEManager {
|
|
|
|
public static boolean maskContains(final HashSet<RegionWrapper> mask, final int x, final int y, final int z) {
|
|
|
|
for (final RegionWrapper region : mask) {
|
|
|
|
if (region.isIn(x, y, z)) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-01 00:51:51 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public static boolean maskContains(final HashSet<RegionWrapper> mask, final int x, final int z) {
|
|
|
|
for (final RegionWrapper region : mask) {
|
|
|
|
if (region.isIn(x, z)) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-18 15:47:13 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public static HashSet<RegionWrapper> getMask(final PlotPlayer player) {
|
2015-09-11 12:09:22 +02:00
|
|
|
final HashSet<RegionWrapper> regions = new HashSet<>();
|
|
|
|
final UUID uuid = player.getUUID();
|
|
|
|
final Location location = player.getLocation();
|
|
|
|
final String world = location.getWorld();
|
2016-02-10 19:59:51 +01:00
|
|
|
if (!PS.get().hasPlotArea(world)) {
|
2015-08-28 00:33:32 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
for (final Plot plot : area.getPlots()) {
|
2015-10-07 08:33:33 +02:00
|
|
|
if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && (FlagManager.getPlotFlagRaw(plot, "done") != null))) {
|
2015-08-20 06:56:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
if (Settings.WE_ALLOW_HELPER ? plot.isAdded(uuid) : (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;
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public static boolean intersects(final RegionWrapper region1, final 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
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
|
|
|
|
public static boolean regionContains(final RegionWrapper selection, final HashSet<RegionWrapper> mask) {
|
|
|
|
for (final RegionWrapper region : mask) {
|
|
|
|
if (intersects(region, selection)) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-18 15:47:13 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|