3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-14 12:10:05 +01: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 6c494c4276
Commit cc2c65849f
4 geänderte Dateien mit 64 neuen und 58 gelöschten Zeilen

Datei anzeigen

@ -223,32 +223,31 @@ public class AxiomPaper extends JavaPlugin implements Listener {
send = true;
}
BlockPos boundsMin = null;
BlockPos boundsMax = null;
Set<PlotSquaredIntegration.PlotBox> 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;
}

Datei anzeigen

@ -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<PlotSquaredIntegration.PlotBox> 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 +
'}';
}

Datei anzeigen

@ -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<PlotBox> boxes, String worldName) {}
public static boolean canBreakBlock(Player player, Block block) {
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.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<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) {
int minX = sectionX * 16;
int minY = sectionY * 16;