Compare commits

..

1 Commits

Author SHA1 Message Date
9ee3e9a3a4 feature: improve handling of null issues in plot analysis
- Addresses #3865 (does not fix the underlying issue though)
2022-11-11 11:29:56 +00:00
13 changed files with 84 additions and 177 deletions

View File

@ -56,7 +56,6 @@ import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PlotFlagUtil;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.task.TaskTime;
import com.sk89q.worldedit.WorldEdit;
@ -167,7 +166,7 @@ public class BlockEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, RedstoneFlag.class, false)) {
if (area.isRoadFlags() && !area.getRoadFlag(RedstoneFlag.class)) {
event.setNewCurrent(0);
}
return;
@ -1085,10 +1084,7 @@ public class BlockEventListener implements Listener {
return;
}
if (plot == null) {
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, BlockIgnitionFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_BUILD_ROAD
)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_ROAD))
@ -1096,10 +1092,7 @@ public class BlockEventListener implements Listener {
event.setCancelled(true);
}
} else if (!plot.hasOwner()) {
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, BlockIgnitionFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_BUILD_UNOWNED
)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_BUILD_UNOWNED))

View File

@ -26,7 +26,6 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.flag.implementations.CopperOxideFlag;
import com.plotsquared.core.plot.flag.implementations.MiscInteractFlag;
import com.plotsquared.core.util.PlotFlagUtil;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
@ -92,8 +91,7 @@ public class BlockEventListener117 implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null && !PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, MiscInteractFlag.class, true) || plot != null && !plot.getFlag(
MiscInteractFlag.class)) {
if (plot == null || !plot.getFlag(MiscInteractFlag.class)) {
if (plotPlayer != null) {
if (plot != null) {
if (!plot.isAdded(plotPlayer.getUUID())) {
@ -106,12 +104,6 @@ public class BlockEventListener117 implements Listener {
if (entity instanceof Item item) {
UUID itemThrower = item.getThrower();
if (plot != null) {
if (itemThrower == null && (itemThrower = item.getOwner()) == null) {
plot.debug(
"A thrown item couldn't trigger sculk sensors because misc-interact = false and the item's owner could not be resolved.");
event.setCancelled(true);
return;
}
if (!plot.isAdded(itemThrower)) {
if (!plot.isAdded(itemThrower)) {
plot.debug("A thrown item couldn't trigger sculk sensors because misc-interact = false");

View File

@ -38,7 +38,6 @@ import com.plotsquared.core.plot.flag.implementations.InvincibleFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PlotFlagUtil;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
import org.bukkit.Material;
@ -262,7 +261,7 @@ public class EntityEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, InvincibleFlag.class, true)) {
if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) {
event.setCancelled(true);
}
return;

View File

@ -44,7 +44,6 @@ import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PlotFlagUtil;
import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.Chunk;
import org.bukkit.block.Block;
@ -327,18 +326,14 @@ public class PaperListener implements Listener {
return;
}
Location location = BukkitUtil.adapt(entity.getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_PROJECTILE_ROAD
)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))

View File

@ -48,10 +48,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* @deprecated P2 effectively no longer supports 1.13
*/
@Deprecated(forRemoval = true, since = "6.10.4")
public class PaperListener113 extends PaperListener {
@Inject

View File

@ -68,7 +68,6 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PlotFlagUtil;
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.TaskManager;
@ -890,7 +889,8 @@ public class PlayerEventListener implements Listener {
}
} else {
PlotArea area = pp.getPlotAreaAbs();
if (area != null && PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, PreventCreativeCopyFlag.class, true)) {
if (area != null && area.isRoadFlags() && area
.getRoadFlag(PreventCreativeCopyFlag.class)) {
final ItemStack newStack =
new ItemStack(newItem.getType(), newItem.getAmount());
event.setCursor(newStack);
@ -998,10 +998,8 @@ public class PlayerEventListener implements Listener {
Plot plot = location.getPlotAbs();
BukkitPlayer pp = BukkitUtil.adapt(e.getPlayer());
if (plot == null) {
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, MiscInteractFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_INTERACT_ROAD
)) {
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions
.hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_INTERACT_ROAD))
@ -1011,7 +1009,9 @@ public class PlayerEventListener implements Listener {
} else {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_OTHER)) {
pp.sendMessage(TranslatableCaption.of("done.building_restricted"));
pp.sendMessage(
TranslatableCaption.of("done.building_restricted")
);
e.setCancelled(true);
return;
}
@ -1594,10 +1594,7 @@ public class PlayerEventListener implements Listener {
BukkitPlayer pp = BukkitUtil.adapt(p);
Plot plot = area.getPlot(location);
if (plot == null) {
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, VehicleBreakFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD
)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD))
@ -1645,7 +1642,7 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ItemDropFlag.class, false)) {
if (area.isRoadFlags() && !area.getRoadFlag(ItemDropFlag.class)) {
event.setCancelled(true);
}
return;
@ -1671,7 +1668,7 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, DropProtectionFlag.class, true)) {
if (area.isRoadFlags() && area.getRoadFlag(DropProtectionFlag.class)) {
event.setCancelled(true);
}
return;
@ -1693,15 +1690,17 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, KeepInventoryFlag.class, true)) {
if (area.isRoadFlags() && area.getRoadFlag(KeepInventoryFlag.class)) {
event.setCancelled(true);
}
return;
}
if (plot.getFlag(KeepInventoryFlag.class)) {
plot.debug(event.getEntity().getName() + " kept their inventory because of keep-inventory = true");
event.getDrops().clear();
event.setKeepInventory(true);
if (plot.getFlag(KeepInventoryFlag.class)) {
plot.debug(event.getEntity().getName() + " kept their inventory because of keep-inventory = true");
event.getDrops().clear();
event.setKeepInventory(true);
}
}
}
@ -1726,14 +1725,16 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, DenyPortalTravelFlag.class, true)) {
if (area.isRoadFlags() && area.getRoadFlag(DenyPortalTravelFlag.class)) {
event.setCancelled(true);
}
return;
}
if (plot.getFlag(DenyPortalTravelFlag.class)) {
plot.debug(event.getPlayer().getName() + " did not travel thru a portal because of deny-portal-travel = true");
event.setCancelled(true);
if (plot.getFlag(DenyPortalTravelFlag.class)) {
plot.debug(event.getPlayer().getName() + " did not travel thru a portal because of deny-portal-travel = true");
event.setCancelled(true);
}
}
}
@ -1771,7 +1772,7 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, DenyPortalsFlag.class, true)) {
if (area.isRoadFlags() && area.getRoadFlag(DenyPortalsFlag.class)) {
event.setCancelled(true);
return;
}
@ -1800,14 +1801,16 @@ public class PlayerEventListener implements Listener {
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, LecternReadBookFlag.class, true)) {
if (area.isRoadFlags() && area.getRoadFlag(LecternReadBookFlag.class)) {
event.setCancelled(true);
}
return;
}
if (plot.getFlag(LecternReadBookFlag.class)) {
plot.debug(event.getPlayer().getName() + " could not take the book because of lectern-read-book = true");
event.setCancelled(true);
if (plot.getFlag(LecternReadBookFlag.class)) {
plot.debug(event.getPlayer().getName() + " could not take the book because of lectern-read-book = true");
event.setCancelled(true);
}
}
}

View File

@ -31,7 +31,6 @@ import com.plotsquared.core.plot.PlotHandler;
import com.plotsquared.core.plot.flag.implementations.ProjectilesFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PlotFlagUtil;
import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@ -98,18 +97,14 @@ public class ProjectileEventListener implements Listener {
return;
}
Location location = BukkitUtil.adapt(entity.getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
PlotPlayer<Player> pp = BukkitUtil.adapt((Player) shooter);
Plot plot = location.getOwnedPlot();
if (plot == null) {
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_PROJECTILE_ROAD
)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) {
pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_PROJECTILE_ROAD))
@ -159,8 +154,6 @@ public class ProjectileEventListener implements Listener {
if (plot.isAdded(((Player) shooter).getUniqueId()) || plot.getFlag(ProjectilesFlag.class)) {
return;
}
} else if (PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true)) {
return;
}
entity.remove();
@ -170,10 +163,7 @@ public class ProjectileEventListener implements Listener {
PlotPlayer<?> pp = BukkitUtil.adapt((Player) shooter);
if (plot == null) {
if (!PlotFlagUtil.isAreaRoadFlagsAndFlagEquals(area, ProjectilesFlag.class, true) && !Permissions.hasPermission(
pp,
Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED
)) {
if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) {
entity.remove();
event.setCancelled(true);
}
@ -204,6 +194,7 @@ public class ProjectileEventListener implements Listener {
if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) {
entity.remove();
event.setCancelled(true);
return;
}
}
}

View File

@ -44,7 +44,6 @@ public class LimitedRegionWrapperQueue extends DelegateQueueCoordinator {
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + LimitedRegionWrapperQueue.class.getSimpleName());
private final LimitedRegion limitedRegion;
private boolean useOtherRestoreTagMethod = false;
/**
* @since 6.9.0
@ -66,18 +65,10 @@ public class LimitedRegionWrapperQueue extends DelegateQueueCoordinator {
CompoundTag tag = id.getNbtData();
StateWrapper sw = new StateWrapper(tag);
try {
if (useOtherRestoreTagMethod && getWorld() != null) {
sw.restoreTag(getWorld().getName(), x, y, z);
} else {
sw.restoreTag(limitedRegion.getBlockState(x, y, z).getBlock());
}
sw.restoreTag(limitedRegion.getBlockState(x, y, z).getBlock());
} catch (IllegalArgumentException e) {
LOGGER.error("Error attempting to populate tile entity into the world at location {},{},{}", x, y, z, e);
return false;
} catch (IllegalStateException e) {
useOtherRestoreTagMethod = true;
LOGGER.warn("IllegalStateException attempting to populate tile entity into the world at location {},{},{}. " +
"Possibly on <=1.17.1, switching to secondary method.", x, y, z, e);
}
}
return result;

View File

@ -142,14 +142,6 @@ public class Auto extends SubCommand {
}
}
}
int maxMerge = Permissions.hasPermissionRange(player, Permission.PERMISSION_MERGE, Settings.Limit.MAX_PLOTS);
if (sizeX * sizeZ > maxMerge) {
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
Template.of("node", Permission.PERMISSION_MERGE + "." + (sizeX * sizeZ))
);
return false;
}
return true;
}

View File

@ -124,7 +124,7 @@ public class Merge extends SubCommand {
return false;
}
final int size = plot.getConnectedPlots().size();
int max = Permissions.hasPermissionRange(player, Permission.PERMISSION_MERGE, Settings.Limit.MAX_PLOTS);
int max = Permissions.hasPermissionRange(player, "plots.merge", Settings.Limit.MAX_PLOTS);
PlotMergeEvent event =
this.eventDispatcher.callMerge(plot, direction, max, player);
if (event.getEventResult() == Result.DENY) {

View File

@ -234,44 +234,52 @@ public class HybridUtils {
Set<BlockType> types = new HashSet<>();
for (int yIndex = 0; yIndex < height; yIndex++) {
BlockState old = oldBlocks[yIndex][x][z]; // Nullable
try {
BlockState now = newBlocks[yIndex][x][z]; // Not null
if (!now.equals(old) && !(old == null && now.getBlockType().equals(BlockTypes.AIR))) {
changes[i]++;
}
if (now.getBlockType().getMaterial().isAir()) {
air[i]++;
} else {
// check vertices
// modifications_adjacent
if (x > 0 && z > 0 && yIndex > 0 && x < width - 1 && z < length - 1 && yIndex < (height - 1)) {
if (newBlocks[yIndex - 1][x][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x - 1][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x][z - 1].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex + 1][x][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x + 1][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x][z + 1].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
BlockState now = newBlocks[yIndex][x][z]; // Not null
if (now == null) {
throw new NullPointerException(String.format(
"\"now\" block null attempting to perform plot analysis. Indexes: x=%d of %d, yIndex=%d" +
" of %d, z=%d of %d",
x,
width,
yIndex,
height,
z,
length
));
}
if (!now.equals(old) && !(old == null && now.getBlockType().equals(BlockTypes.AIR))) {
changes[i]++;
}
if (now.getBlockType().getMaterial().isAir()) {
air[i]++;
} else {
// check vertices
// modifications_adjacent
if (x > 0 && z > 0 && yIndex > 0 && x < width - 1 && z < length - 1 && yIndex < (height - 1)) {
if (newBlocks[yIndex - 1][x][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x - 1][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x][z - 1].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex + 1][x][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x + 1][z].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
if (newBlocks[yIndex][x][z + 1].getBlockType().getMaterial().isAir()) {
faces[i]++;
}
}
if (!now.equals(now.getBlockType().getDefaultState())) {
data[i]++;
}
types.add(now.getBlockType());
if (!now.equals(now.getBlockType().getDefaultState())) {
data[i]++;
}
} catch (NullPointerException e) {
e.printStackTrace();
types.add(now.getBlockType());
}
}
variety[i] = types.size();

View File

@ -1,53 +0,0 @@
/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.util;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.flag.PlotFlag;
import java.util.Objects;
/**
* Util class for generic methods relating to plot flags.
*
* @since 6.10.4
*/
public final class PlotFlagUtil {
private PlotFlagUtil() {
//No-op
}
/**
* Check if the value of a {@link PlotFlag} matches the given value. If
* road flags are disabled for the given plot area, returns false.
*
* @param flagClass boolean flag to get value of
* @param value boolean value to check flag value against
* @param <T> The flag value type
* @return true if road flag value matches with road flags enabled
* @since 6.10.4
*/
public static <T> boolean isAreaRoadFlagsAndFlagEquals(
PlotArea area, final Class<? extends PlotFlag<T, ?>> flagClass, T value
) {
return area.isRoadFlags() && Objects.equals(area.getRoadFlag(flagClass), value);
}
}

View File

@ -19,7 +19,7 @@ plugins {
}
group = "com.plotsquared"
version = "6.10.4"
version = "6.10.4-SNAPSHOT"
subprojects {
group = rootProject.group