2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.util;
|
2015-04-18 15:47:13 +02:00
|
|
|
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
2020-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
2020-07-23 20:52:32 +02:00
|
|
|
import com.plotsquared.core.player.MetaDataAccess;
|
|
|
|
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.plot.Plot;
|
|
|
|
import com.plotsquared.core.plot.PlotArea;
|
2020-04-30 12:01:52 +02:00
|
|
|
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
|
|
|
|
import com.plotsquared.core.plot.flag.implementations.NoWorldeditFlag;
|
2019-11-04 22:08:33 +01:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2016-06-10 19:00:34 +02:00
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
import java.util.HashSet;
|
2019-11-04 22:08:33 +01:00
|
|
|
import java.util.Set;
|
2016-03-23 02:41:37 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
public class WEManager {
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2022-03-08 19:14:19 +01:00
|
|
|
private static final BlockVector3 MIN = BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
|
|
|
private static final BlockVector3 MAX = BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
|
|
|
|
2019-11-04 22:08:33 +01:00
|
|
|
public static boolean maskContains(Set<CuboidRegion> mask, int x, int y, int z) {
|
|
|
|
for (CuboidRegion region : mask) {
|
|
|
|
if (RegionUtil.contains(region, x, y, z)) {
|
2015-09-13 06:04:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-01 00:51:51 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2019-11-04 22:08:33 +01:00
|
|
|
public static boolean maskContains(Set<CuboidRegion> mask, int x, int z) {
|
|
|
|
for (CuboidRegion region : mask) {
|
|
|
|
if (RegionUtil.contains(region, x, z)) {
|
2015-09-13 06:04:31 +02:00
|
|
|
return true;
|
2018-12-20 00:18:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-24 18:42:02 +01:00
|
|
|
public static boolean maskContains(Set<CuboidRegion> mask, double dx, double dy, double dz) {
|
2018-12-20 00:18:57 +01:00
|
|
|
int x = Math.toIntExact(Math.round(dx >= 0 ? dx - 0.5 : dx + 0.5));
|
|
|
|
int y = Math.toIntExact(Math.round(dy - 0.5));
|
|
|
|
int z = Math.toIntExact(Math.round(dz >= 0 ? dz - 0.5 : dz + 0.5));
|
2019-11-04 22:08:33 +01:00
|
|
|
for (CuboidRegion region : mask) {
|
|
|
|
if (RegionUtil.contains(region, x, y, z)) {
|
2018-12-20 00:18:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-04 22:08:33 +01:00
|
|
|
public static boolean maskContains(Set<CuboidRegion> mask, double dx, double dz) {
|
2018-12-20 00:18:57 +01:00
|
|
|
int x = Math.toIntExact(Math.round(dx >= 0 ? dx - 0.5 : dx + 0.5));
|
|
|
|
int z = Math.toIntExact(Math.round(dz >= 0 ? dz - 0.5 : dz + 0.5));
|
2019-11-04 22:08:33 +01:00
|
|
|
for (CuboidRegion region : mask) {
|
|
|
|
if (RegionUtil.contains(region, x, z)) {
|
2018-12-20 00:18:57 +01:00
|
|
|
return true;
|
2015-09-13 06:04:31 +02:00
|
|
|
}
|
2015-04-18 15:47:13 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2020-05-27 14:08:48 +02:00
|
|
|
public static HashSet<CuboidRegion> getMask(PlotPlayer<?> player) {
|
2019-11-04 22:08:33 +01:00
|
|
|
HashSet<CuboidRegion> regions = new HashSet<>();
|
2016-03-23 02:41:37 +01:00
|
|
|
UUID uuid = player.getUUID();
|
|
|
|
Location location = player.getLocation();
|
2020-07-10 12:21:29 +02:00
|
|
|
String world = location.getWorldName();
|
2020-07-07 13:37:03 +02:00
|
|
|
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
|
2022-03-08 19:14:19 +01:00
|
|
|
regions.add(new CuboidRegion(MIN, MAX));
|
2015-08-28 00:33:32 +02:00
|
|
|
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();
|
2020-07-23 20:52:32 +02:00
|
|
|
try (final MetaDataAccess<Plot> metaDataAccess =
|
2021-01-09 22:28:41 +01:00
|
|
|
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_WORLD_EDIT_REGION_PLOT)) {
|
2020-07-23 20:52:32 +02:00
|
|
|
if (plot == null) {
|
|
|
|
plot = metaDataAccess.get().orElse(null);
|
|
|
|
}
|
|
|
|
if (plot != null && (!Settings.Done.RESTRICT_BUILDING || !DoneFlag.isDone(plot)) && (
|
2022-01-20 21:01:38 +01:00
|
|
|
(allowMember && plot.isAdded(uuid)) || (!allowMember && plot.isOwner(uuid) || plot
|
2021-01-09 22:28:41 +01:00
|
|
|
.getTrusted().contains(uuid))) && !plot.getFlag(NoWorldeditFlag.class)) {
|
2020-07-23 20:52:32 +02:00
|
|
|
for (CuboidRegion region : plot.getRegions()) {
|
|
|
|
BlockVector3 pos1 = region.getMinimumPoint().withY(area.getMinBuildHeight());
|
|
|
|
BlockVector3 pos2 = region.getMaximumPoint().withY(area.getMaxBuildHeight());
|
|
|
|
CuboidRegion copy = new CuboidRegion(pos1, pos2);
|
|
|
|
regions.add(copy);
|
|
|
|
}
|
|
|
|
metaDataAccess.set(plot);
|
2016-11-11 14:14:12 +01:00
|
|
|
}
|
2015-04-18 15:47:13 +02:00
|
|
|
}
|
|
|
|
return regions;
|
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2019-11-04 22:08:33 +01:00
|
|
|
public static boolean intersects(CuboidRegion region1, CuboidRegion region2) {
|
|
|
|
return RegionUtil.intersects(region1, region2);
|
2015-04-18 15:47:13 +02:00
|
|
|
}
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2019-11-04 22:08:33 +01:00
|
|
|
public static boolean regionContains(CuboidRegion selection, HashSet<CuboidRegion> mask) {
|
|
|
|
for (CuboidRegion 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;
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2015-04-18 15:47:13 +02:00
|
|
|
}
|