diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java index a08097100..f56671ee8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -166,7 +166,7 @@ public class BlockEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && !area.getRoadFlag(RedstoneFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(RedstoneFlag.class, false)) { event.setNewCurrent(0); } return; @@ -1084,7 +1084,10 @@ public class BlockEventListener implements Listener { return; } if (plot == null) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_ROAD)) { + if (!area.isRoadFlagsAndFlagEquals(BlockIgnitionFlag.class, true) && !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)) @@ -1092,7 +1095,10 @@ public class BlockEventListener implements Listener { event.setCancelled(true); } } else if (!plot.hasOwner()) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BUILD_UNOWNED)) { + if (!area.isRoadFlagsAndFlagEquals(BlockIgnitionFlag.class, true) && !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)) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java index 2d23515ad..077675433 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener117.java @@ -91,7 +91,8 @@ public class BlockEventListener117 implements Listener { } Plot plot = location.getOwnedPlot(); - if (plot == null || !plot.getFlag(MiscInteractFlag.class)) { + if (plot == null && !area.isRoadFlagsAndFlagEquals(MiscInteractFlag.class, true) || plot != null && !plot.getFlag( + MiscInteractFlag.class)) { if (plotPlayer != null) { if (plot != null) { if (!plot.isAdded(plotPlayer.getUUID())) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java index bc28460e2..e342cf7d9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntityEventListener.java @@ -261,7 +261,7 @@ public class EntityEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && area.getRoadFlag(InvincibleFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(InvincibleFlag.class, true)) { event.setCancelled(true); } return; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java index 54cc21a41..4da6848d4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java @@ -326,14 +326,18 @@ public class PaperListener implements Listener { return; } Location location = BukkitUtil.adapt(entity.getLocation()); - if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { + PlotArea area = location.getPlotArea(); + if (area == null) { return; } PlotPlayer pp = BukkitUtil.adapt((Player) shooter); Plot plot = location.getOwnedPlot(); if (plot == null) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) { + if (!area.isRoadFlagsAndFlagEquals(ProjectilesFlag.class, true) && !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)) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index ca7130deb..0b3a5e0c8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -889,8 +889,7 @@ public class PlayerEventListener implements Listener { } } else { PlotArea area = pp.getPlotAreaAbs(); - if (area != null && area.isRoadFlags() && area - .getRoadFlag(PreventCreativeCopyFlag.class)) { + if (area != null && area.isRoadFlagsAndFlagEquals(PreventCreativeCopyFlag.class, true)) { final ItemStack newStack = new ItemStack(newItem.getType(), newItem.getAmount()); event.setCursor(newStack); @@ -998,8 +997,10 @@ public class PlayerEventListener implements Listener { Plot plot = location.getPlotAbs(); BukkitPlayer pp = BukkitUtil.adapt(e.getPlayer()); if (plot == null) { - if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions - .hasPermission(pp, Permission.PERMISSION_ADMIN_INTERACT_ROAD)) { + if (!area.isRoadFlagsAndFlagEquals(MiscInteractFlag.class, true) && !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)) @@ -1009,9 +1010,7 @@ 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,7 +1593,10 @@ public class PlayerEventListener implements Listener { BukkitPlayer pp = BukkitUtil.adapt(p); Plot plot = area.getPlot(location); if (plot == null) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_DESTROY_VEHICLE_ROAD)) { + if (!area.isRoadFlagsAndFlagEquals(VehicleBreakFlag.class, true) && !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)) @@ -1642,7 +1644,7 @@ public class PlayerEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && !area.getRoadFlag(ItemDropFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(ItemDropFlag.class, false)) { event.setCancelled(true); } return; @@ -1668,7 +1670,7 @@ public class PlayerEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && area.getRoadFlag(DropProtectionFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(DropProtectionFlag.class, true)) { event.setCancelled(true); } return; @@ -1690,17 +1692,15 @@ public class PlayerEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && area.getRoadFlag(KeepInventoryFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(KeepInventoryFlag.class, true)) { event.setCancelled(true); } return; } if (plot.getFlag(KeepInventoryFlag.class)) { - if (plot.getFlag(KeepInventoryFlag.class)) { - plot.debug(event.getEntity().getName() + " kept their inventory because of keep-inventory = true"); - event.getDrops().clear(); - event.setKeepInventory(true); - } + plot.debug(event.getEntity().getName() + " kept their inventory because of keep-inventory = true"); + event.getDrops().clear(); + event.setKeepInventory(true); } } @@ -1725,16 +1725,14 @@ public class PlayerEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && area.getRoadFlag(DenyPortalTravelFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(DenyPortalTravelFlag.class, true)) { event.setCancelled(true); } return; } if (plot.getFlag(DenyPortalTravelFlag.class)) { - 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); - } + plot.debug(event.getPlayer().getName() + " did not travel thru a portal because of deny-portal-travel = true"); + event.setCancelled(true); } } @@ -1772,7 +1770,7 @@ public class PlayerEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && area.getRoadFlag(DenyPortalsFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(DenyPortalsFlag.class, true)) { event.setCancelled(true); return; } @@ -1801,16 +1799,14 @@ public class PlayerEventListener implements Listener { } Plot plot = location.getOwnedPlot(); if (plot == null) { - if (area.isRoadFlags() && area.getRoadFlag(LecternReadBookFlag.class)) { + if (area.isRoadFlagsAndFlagEquals(LecternReadBookFlag.class, true)) { event.setCancelled(true); } return; } if (plot.getFlag(LecternReadBookFlag.class)) { - if (plot.getFlag(LecternReadBookFlag.class)) { - plot.debug(event.getPlayer().getName() + " could not take the book because of lectern-read-book = true"); - event.setCancelled(true); - } + plot.debug(event.getPlayer().getName() + " could not take the book because of lectern-read-book = true"); + event.setCancelled(true); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java index 743649a80..92eec80b7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ProjectileEventListener.java @@ -97,14 +97,18 @@ public class ProjectileEventListener implements Listener { return; } Location location = BukkitUtil.adapt(entity.getLocation()); - if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) { + PlotArea area = location.getPlotArea(); + if (area == null) { return; } PlotPlayer pp = BukkitUtil.adapt((Player) shooter); Plot plot = location.getOwnedPlot(); if (plot == null) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_ROAD)) { + if (!area.isRoadFlagsAndFlagEquals(ProjectilesFlag.class, true) && !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)) @@ -154,6 +158,8 @@ public class ProjectileEventListener implements Listener { if (plot.isAdded(((Player) shooter).getUniqueId()) || plot.getFlag(ProjectilesFlag.class)) { return; } + } else if (area.isRoadFlagsAndFlagEquals(ProjectilesFlag.class, true)) { + return; } entity.remove(); @@ -163,7 +169,10 @@ public class ProjectileEventListener implements Listener { PlotPlayer pp = BukkitUtil.adapt((Player) shooter); if (plot == null) { - if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED)) { + if (!area.isRoadFlagsAndFlagEquals(ProjectilesFlag.class, true) && !Permissions.hasPermission( + pp, + Permission.PERMISSION_ADMIN_PROJECTILE_UNOWNED + )) { entity.remove(); event.setCancelled(true); } @@ -194,7 +203,6 @@ public class ProjectileEventListener implements Listener { if (sPlot == null || !PlotHandler.sameOwners(plot, sPlot)) { entity.remove(); event.setCancelled(true); - return; } } } diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 63f5577ba..81e63ee10 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -46,6 +46,7 @@ import com.plotsquared.core.plot.flag.FlagParseException; import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.plot.flag.types.BooleanFlag; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.QueueCoordinator; import com.plotsquared.core.util.MathMan; @@ -1242,6 +1243,18 @@ public abstract class PlotArea { return this.roadFlagContainer.getFlag(flagClass).getValue(); } + /** + * Check if the value of a {@link BooleanFlag} matches the given boolean. If + * road flags are disabled, returns false. + * + * @param flagClass boolean flag to get value of + * @param value boolean value to check flag value against + * @return Flag value or false if road flags disabled + */ + public boolean isRoadFlagsAndFlagEquals(final Class> flagClass, boolean value) { + return this.roadFlags && (getRoadFlag(flagClass) == value); + } + /** * Get the value associated with the specified road flag. This will look at * the default values stored in {@link GlobalFlagContainer}.