3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-09-29 16:00:04 +02:00

Improve plot bounds handling to support arbitrarily sized non-cuboid plots

Dieser Commit ist enthalten in:
Moulberry 2024-05-28 22:28:26 +08:00
Ursprung f9cad68e17
Commit 53bfc16dc5
4 geänderte Dateien mit 64 neuen und 58 gelöschten Zeilen

Datei anzeigen

@ -221,32 +221,31 @@ public class AxiomPaper extends JavaPlugin implements Listener {
send = true; send = true;
} }
BlockPos boundsMin = null; Set<PlotSquaredIntegration.PlotBox> bounds = Set.of();
BlockPos boundsMax = null;
if (!player.hasPermission("axiom.allow_copying_other_plots")) { if (!player.hasPermission("axiom.allow_copying_other_plots")) {
if (PlotSquaredIntegration.isPlotWorld(player.getWorld())) { if (PlotSquaredIntegration.isPlotWorld(player.getWorld())) {
PlotSquaredIntegration.PlotBounds editable = PlotSquaredIntegration.getCurrentEditablePlot(player); PlotSquaredIntegration.PlotBounds editable = PlotSquaredIntegration.getCurrentEditablePlot(player);
if (editable != null) { if (editable != null) {
restrictions.lastPlotBounds = editable; restrictions.lastPlotBounds = editable;
boundsMin = editable.min(); bounds = editable.boxes();
boundsMax = editable.max();
} else if (restrictions.lastPlotBounds != null && restrictions.lastPlotBounds.worldName().equals(player.getWorld().getName())) { } else if (restrictions.lastPlotBounds != null && restrictions.lastPlotBounds.worldName().equals(player.getWorld().getName())) {
boundsMin = restrictions.lastPlotBounds.min(); bounds = restrictions.lastPlotBounds.boxes();
boundsMax = restrictions.lastPlotBounds.max();
} else { } else {
boundsMin = BlockPos.ZERO; bounds = Set.of(new PlotSquaredIntegration.PlotBox(BlockPos.ZERO, BlockPos.ZERO));
boundsMax = BlockPos.ZERO;
} }
} }
if (bounds.size() == 1) {
PlotSquaredIntegration.PlotBox plotBounds = bounds.iterator().next();
int min = Integer.MIN_VALUE; int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE; int max = Integer.MAX_VALUE;
if (boundsMin != null && boundsMax != null &&
boundsMin.getX() == min && boundsMin.getY() == min && boundsMin.getZ() == min && if (plotBounds.min().getX() == min && plotBounds.min().getY() == min && plotBounds.min().getZ() == min &&
boundsMax.getX() == max && boundsMax.getY() == max && boundsMax.getZ() == max) { plotBounds.max().getX() == max && plotBounds.max().getY() == max && plotBounds.max().getZ() == max) {
boundsMin = null; bounds = Set.of();
boundsMax = null; }
} }
} }
@ -254,12 +253,10 @@ public class AxiomPaper extends JavaPlugin implements Listener {
if (restrictions.maxSectionsPerSecond != rateLimit || if (restrictions.maxSectionsPerSecond != rateLimit ||
restrictions.canImportBlocks != allowImportingBlocks || restrictions.canImportBlocks != allowImportingBlocks ||
!Objects.equals(restrictions.boundsMin, boundsMin) || !Objects.equals(restrictions.bounds, bounds)) {
!Objects.equals(restrictions.boundsMax, boundsMax)) {
restrictions.maxSectionsPerSecond = rateLimit; restrictions.maxSectionsPerSecond = rateLimit;
restrictions.canImportBlocks = allowImportingBlocks; restrictions.canImportBlocks = allowImportingBlocks;
restrictions.boundsMin = boundsMin; restrictions.bounds = bounds;
restrictions.boundsMax = boundsMax;
send = true; send = true;
} }

Datei anzeigen

@ -6,14 +6,15 @@ import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Set;
public class Restrictions { public class Restrictions {
public boolean canImportBlocks = true; public boolean canImportBlocks = true;
public boolean canUseEditor = true; public boolean canUseEditor = true;
public boolean canEditDisplayEntities = true; public boolean canEditDisplayEntities = true;
public int maxSectionsPerSecond = 0; public int maxSectionsPerSecond = 0;
public BlockPos boundsMin = null; public Set<PlotSquaredIntegration.PlotBox> bounds = Set.of();
public BlockPos boundsMax = null;
public PlotSquaredIntegration.PlotBounds lastPlotBounds = null; public PlotSquaredIntegration.PlotBounds lastPlotBounds = null;
@ -26,16 +27,21 @@ public class Restrictions {
buf.writeVarInt(this.maxSectionsPerSecond); buf.writeVarInt(this.maxSectionsPerSecond);
if (this.boundsMin == null || this.boundsMax == null) { int count = Math.min(64, bounds.size());
buf.writeBoolean(false); buf.writeVarInt(count);
for (PlotSquaredIntegration.PlotBox bound : this.bounds) {
if (count > 0) {
count -= 1;
} else { } else {
buf.writeBoolean(true); break;
int minX = this.boundsMin.getX(); }
int minY = this.boundsMin.getY();
int minZ = this.boundsMin.getZ(); int minX = bound.min().getX();
int maxX = this.boundsMax.getX(); int minY = bound.min().getY();
int maxY = this.boundsMax.getY(); int minZ = bound.min().getZ();
int maxZ = this.boundsMax.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;
if (minX > 33554431) minX = 33554431; if (minX > 33554431) minX = 33554431;
@ -68,8 +74,7 @@ public class Restrictions {
", canUseEditor=" + canUseEditor + ", canUseEditor=" + canUseEditor +
", canEditDisplayEntities=" + canEditDisplayEntities + ", canEditDisplayEntities=" + canEditDisplayEntities +
", maxSectionsPerSecond=" + maxSectionsPerSecond + ", maxSectionsPerSecond=" + maxSectionsPerSecond +
", boundsMin=" + boundsMin + ", bounds=" + bounds +
", boundsMax=" + boundsMax +
", lastPlotBounds=" + lastPlotBounds + ", lastPlotBounds=" + lastPlotBounds +
'}'; '}';
} }

Datei anzeigen

@ -10,26 +10,13 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Set;
public class PlotSquaredIntegration { public class PlotSquaredIntegration {
public record PlotBounds(BlockPos min, BlockPos max, String worldName) { public record PlotBox(BlockPos min, BlockPos max) {}
public PlotBounds(CuboidRegion cuboidRegion, String worldName) { public record PlotBounds(Set<PlotBox> boxes, 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 static boolean canBreakBlock(Player player, Block block) { public static boolean canBreakBlock(Player player, Block block) {
if (!Bukkit.getPluginManager().isPluginEnabled("PlotSquared")) { if (!Bukkit.getPluginManager().isPluginEnabled("PlotSquared")) {

Datei anzeigen

@ -18,6 +18,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import net.minecraft.core.BlockPos;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -147,16 +148,12 @@ public class PlotSquaredIntegrationImpl {
BukkitPlayer pp = BukkitUtil.adapt(player); BukkitPlayer pp = BukkitUtil.adapt(player);
Plot plot = area.getPlot(location); Plot plot = area.getPlot(location);
if (plot != null) { if (plot != null) {
Location bottom = plot.getExtendedBottomAbs();
Location top = plot.getExtendedTopAbs();
CuboidRegion cuboidRegion = new CuboidRegion(bottom.getBlockVector3(), top.getBlockVector3());
// check unowned plots // check unowned plots
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_UNOWNED, false)) { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_UNOWNED, false)) {
return null; return null;
} else { } else {
return new PlotSquaredIntegration.PlotBounds(cuboidRegion, player.getWorld().getName()); return createBounds(plot, player.getWorld().getName());
} }
} }
// player is breaking another player's plot // player is breaking another player's plot
@ -164,7 +161,7 @@ public class PlotSquaredIntegrationImpl {
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_OTHER, false)) { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_OTHER, false)) {
return null; return null;
} else { } else {
return new PlotSquaredIntegration.PlotBounds(cuboidRegion, player.getWorld().getName()); return createBounds(plot, player.getWorld().getName());
} }
} }
// plot is 'done' // plot is 'done'
@ -172,15 +169,35 @@ public class PlotSquaredIntegrationImpl {
if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_OTHER, false)) { if (!pp.hasPermission(Permission.PERMISSION_ADMIN_BUILD_OTHER, false)) {
return null; return null;
} else { } 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; return null;
} }
private static PlotSquaredIntegration.PlotBounds createBounds(Plot plot, String worldName) {
Set<PlotSquaredIntegration.PlotBox> 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) { static SectionPermissionChecker checkSection(Player player, World world, int sectionX, int sectionY, int sectionZ) {
int minX = sectionX * 16; int minX = sectionX * 16;
int minY = sectionY * 16; int minY = sectionY * 16;