2015-09-07 14:17:48 +02:00
|
|
|
package com.plotsquared.listener;
|
2015-04-18 15:47:13 +02:00
|
|
|
|
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;
|
2016-04-19 22:59:10 +02:00
|
|
|
import com.intellectualcrafters.plot.flag.Flags;
|
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-06-05 11:46:52 +02:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2016-06-10 19:00:34 +02:00
|
|
|
|
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
|
|
|
|
2016-06-05 11:46:52 +02:00
|
|
|
public static BaseBlock AIR = new BaseBlock(0, 0);
|
|
|
|
|
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)) {
|
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;
|
|
|
|
}
|
2016-08-12 21:04:11 +02:00
|
|
|
boolean allowMember = player.hasPermission("plots.worldedit.member");
|
2016-08-25 17:36:35 +02:00
|
|
|
Plot plot = player.getCurrentPlot();
|
|
|
|
HashSet<RegionWrapper> allowed = new HashSet<>();
|
|
|
|
if (plot == null) {
|
|
|
|
plot = player.getMeta("WorldEditRegionPlot");
|
|
|
|
}
|
2018-04-13 12:37:28 +02:00
|
|
|
if (plot != null && (!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot)) && ((allowMember && plot.isAdded(uuid)) || (!allowMember && (plot.isOwner(uuid)) || plot.getTrusted().contains(uuid))) && !(Flags.NO_WORLDEDIT.isTrue(plot))) {
|
2016-11-11 14:14:12 +01:00
|
|
|
for (RegionWrapper region : plot.getRegions()) {
|
|
|
|
RegionWrapper copy = new RegionWrapper(region.minX, region.maxX, area.MIN_BUILD_HEIGHT, area.MAX_BUILD_HEIGHT, region.minZ, region.maxZ);
|
|
|
|
regions.add(copy);
|
|
|
|
}
|
2016-08-25 17:36:35 +02:00
|
|
|
player.setMeta("WorldEditRegionPlot", plot);
|
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) {
|
2016-11-11 14:14:12 +01:00
|
|
|
return region1.intersects(region2);
|
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;
|
|
|
|
}
|
|
|
|
}
|