diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index 6f7cf45..f702635 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -223,32 +223,31 @@ public class AxiomPaper extends JavaPlugin implements Listener { send = true; } - BlockPos boundsMin = null; - BlockPos boundsMax = null; + Set bounds = Set.of(); if (!player.hasPermission("axiom.allow_copying_other_plots")) { if (PlotSquaredIntegration.isPlotWorld(player.getWorld())) { PlotSquaredIntegration.PlotBounds editable = PlotSquaredIntegration.getCurrentEditablePlot(player); if (editable != null) { restrictions.lastPlotBounds = editable; - boundsMin = editable.min(); - boundsMax = editable.max(); + bounds = editable.boxes(); } else if (restrictions.lastPlotBounds != null && restrictions.lastPlotBounds.worldName().equals(player.getWorld().getName())) { - boundsMin = restrictions.lastPlotBounds.min(); - boundsMax = restrictions.lastPlotBounds.max(); + bounds = restrictions.lastPlotBounds.boxes(); } else { - boundsMin = BlockPos.ZERO; - boundsMax = BlockPos.ZERO; + bounds = Set.of(new PlotSquaredIntegration.PlotBox(BlockPos.ZERO, BlockPos.ZERO)); } } - int min = Integer.MIN_VALUE; - int max = Integer.MAX_VALUE; - if (boundsMin != null && boundsMax != null && - boundsMin.getX() == min && boundsMin.getY() == min && boundsMin.getZ() == min && - boundsMax.getX() == max && boundsMax.getY() == max && boundsMax.getZ() == max) { - boundsMin = null; - boundsMax = null; + if (bounds.size() == 1) { + PlotSquaredIntegration.PlotBox plotBounds = bounds.iterator().next(); + + int min = Integer.MIN_VALUE; + int max = Integer.MAX_VALUE; + + if (plotBounds.min().getX() == min && plotBounds.min().getY() == min && plotBounds.min().getZ() == min && + plotBounds.max().getX() == max && plotBounds.max().getY() == max && plotBounds.max().getZ() == max) { + bounds = Set.of(); + } } } @@ -256,12 +255,10 @@ public class AxiomPaper extends JavaPlugin implements Listener { if (restrictions.maxSectionsPerSecond != rateLimit || restrictions.canImportBlocks != allowImportingBlocks || - !Objects.equals(restrictions.boundsMin, boundsMin) || - !Objects.equals(restrictions.boundsMax, boundsMax)) { + !Objects.equals(restrictions.bounds, bounds)) { restrictions.maxSectionsPerSecond = rateLimit; restrictions.canImportBlocks = allowImportingBlocks; - restrictions.boundsMin = boundsMin; - restrictions.boundsMax = boundsMax; + restrictions.bounds = bounds; send = true; } diff --git a/src/main/java/com/moulberry/axiom/Restrictions.java b/src/main/java/com/moulberry/axiom/Restrictions.java index 4b6c25c..c36329c 100644 --- a/src/main/java/com/moulberry/axiom/Restrictions.java +++ b/src/main/java/com/moulberry/axiom/Restrictions.java @@ -6,14 +6,15 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import org.bukkit.entity.Player; +import java.util.Set; + public class Restrictions { public boolean canImportBlocks = true; public boolean canUseEditor = true; public boolean canEditDisplayEntities = true; public int maxSectionsPerSecond = 0; - public BlockPos boundsMin = null; - public BlockPos boundsMax = null; + public Set bounds = Set.of(); public PlotSquaredIntegration.PlotBounds lastPlotBounds = null; @@ -26,16 +27,21 @@ public class Restrictions { buf.writeVarInt(this.maxSectionsPerSecond); - if (this.boundsMin == null || this.boundsMax == null) { - buf.writeBoolean(false); - } else { - buf.writeBoolean(true); - int minX = this.boundsMin.getX(); - int minY = this.boundsMin.getY(); - int minZ = this.boundsMin.getZ(); - int maxX = this.boundsMax.getX(); - int maxY = this.boundsMax.getY(); - int maxZ = this.boundsMax.getZ(); + int count = Math.min(64, bounds.size()); + buf.writeVarInt(count); + for (PlotSquaredIntegration.PlotBox bound : this.bounds) { + if (count > 0) { + count -= 1; + } else { + break; + } + + int minX = bound.min().getX(); + int minY = bound.min().getY(); + int minZ = bound.min().getZ(); + int maxX = bound.max().getX(); + int maxY = bound.max().getY(); + int maxZ = bound.max().getZ(); if (minX < -33554431) minX = -33554431; if (minX > 33554431) minX = 33554431; @@ -68,8 +74,7 @@ public class Restrictions { ", canUseEditor=" + canUseEditor + ", canEditDisplayEntities=" + canEditDisplayEntities + ", maxSectionsPerSecond=" + maxSectionsPerSecond + - ", boundsMin=" + boundsMin + - ", boundsMax=" + boundsMax + + ", bounds=" + bounds + ", lastPlotBounds=" + lastPlotBounds + '}'; } diff --git a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java index deab2cf..586930c 100644 --- a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java +++ b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegration.java @@ -10,26 +10,13 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import java.util.Set; + public class PlotSquaredIntegration { - public record PlotBounds(BlockPos min, BlockPos max, String worldName) { - public PlotBounds(CuboidRegion cuboidRegion, String worldName) { - this( - new BlockPos( - cuboidRegion.getMinimumPoint().getBlockX(), - cuboidRegion.getMinimumPoint().getBlockY(), - cuboidRegion.getMinimumPoint().getBlockZ() - ), - new BlockPos( - cuboidRegion.getMaximumPoint().getBlockX(), - cuboidRegion.getMaximumPoint().getBlockY(), - cuboidRegion.getMaximumPoint().getBlockZ() - ), - worldName - ); - } - } + public record PlotBox(BlockPos min, BlockPos max) {} + public record PlotBounds(Set boxes, String worldName) {} public static boolean canBreakBlock(Player player, Block block) { if (!Bukkit.getPluginManager().isPluginEnabled("PlotSquared")) { diff --git a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java index 87fa49e..9fa95b3 100644 --- a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java +++ b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java @@ -18,6 +18,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.block.BlockType; +import net.minecraft.core.BlockPos; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -147,16 +148,12 @@ public class PlotSquaredIntegrationImpl { BukkitPlayer pp = BukkitUtil.adapt(player); Plot plot = area.getPlot(location); if (plot != null) { - Location bottom = plot.getExtendedBottomAbs(); - Location top = plot.getExtendedTopAbs(); - CuboidRegion cuboidRegion = new CuboidRegion(bottom.getBlockVector3(), top.getBlockVector3()); - // check unowned plots if (!plot.hasOwner()) { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_UNOWNED, false)) { return null; } else { - return new PlotSquaredIntegration.PlotBounds(cuboidRegion, player.getWorld().getName()); + return createBounds(plot, player.getWorld().getName()); } } // player is breaking another player's plot @@ -164,7 +161,7 @@ public class PlotSquaredIntegrationImpl { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_OTHER, false)) { return null; } else { - return new PlotSquaredIntegration.PlotBounds(cuboidRegion, player.getWorld().getName()); + return createBounds(plot, player.getWorld().getName()); } } // plot is 'done' @@ -172,15 +169,35 @@ public class PlotSquaredIntegrationImpl { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_OTHER, false)) { return null; } else { - return new PlotSquaredIntegration.PlotBounds(cuboidRegion, player.getWorld().getName()); + return createBounds(plot, player.getWorld().getName()); } } - return new PlotSquaredIntegration.PlotBounds(cuboidRegion, player.getWorld().getName()); + return createBounds(plot, player.getWorld().getName()); } return null; } + private static PlotSquaredIntegration.PlotBounds createBounds(Plot plot, String worldName) { + Set boxes = new HashSet<>(); + + for (CuboidRegion region : plot.getRegions()) { + BlockPos min = new BlockPos( + region.getMinimumPoint().getBlockX(), + region.getMinimumPoint().getBlockY(), + region.getMinimumPoint().getBlockZ() + ); + BlockPos max = new BlockPos( + region.getMaximumPoint().getBlockX(), + region.getMaximumPoint().getBlockY(), + region.getMaximumPoint().getBlockZ() + ); + boxes.add(new PlotSquaredIntegration.PlotBox(min, max)); + } + + return new PlotSquaredIntegration.PlotBounds(boxes, worldName); + } + static SectionPermissionChecker checkSection(Player player, World world, int sectionX, int sectionY, int sectionZ) { int minX = sectionX * 16; int minY = sectionY * 16;