Mirror von
https://github.com/Moulberry/AxiomPaperPlugin.git
synchronisiert 2024-11-17 05:40:06 +01:00
Improve plot bounds handling to support arbitrarily sized non-cuboid plots
Dieser Commit ist enthalten in:
Ursprung
6c494c4276
Commit
cc2c65849f
@ -223,32 +223,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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int min = Integer.MIN_VALUE;
|
if (bounds.size() == 1) {
|
||||||
int max = Integer.MAX_VALUE;
|
PlotSquaredIntegration.PlotBox plotBounds = bounds.iterator().next();
|
||||||
if (boundsMin != null && boundsMax != null &&
|
|
||||||
boundsMin.getX() == min && boundsMin.getY() == min && boundsMin.getZ() == min &&
|
int min = Integer.MIN_VALUE;
|
||||||
boundsMax.getX() == max && boundsMax.getY() == max && boundsMax.getZ() == max) {
|
int max = Integer.MAX_VALUE;
|
||||||
boundsMin = null;
|
|
||||||
boundsMax = null;
|
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 ||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
} else {
|
for (PlotSquaredIntegration.PlotBox bound : this.bounds) {
|
||||||
buf.writeBoolean(true);
|
if (count > 0) {
|
||||||
int minX = this.boundsMin.getX();
|
count -= 1;
|
||||||
int minY = this.boundsMin.getY();
|
} else {
|
||||||
int minZ = this.boundsMin.getZ();
|
break;
|
||||||
int maxX = this.boundsMax.getX();
|
}
|
||||||
int maxY = this.boundsMax.getY();
|
|
||||||
int maxZ = this.boundsMax.getZ();
|
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;
|
||||||
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 +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
@ -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")) {
|
||||||
|
@ -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;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren