mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
* Begin to implement extended world heights: - Implemented in Bukkit module (and where required in Core module) * Implement extended world heights into core module * Add min gen height to setup, * Default gen/build heights based on minecraft version * Few fixes * Fix up queues * Address comments * Make road schematic stuff slightly more efficient by sharing queues * Minor fixes, don't overlay error many times for the same y * Fix incorrect schematic paste height, undo changes to HybridUtils * Overhall regenallroads method to make it work, make sure BukkitChunkCoordinator can/will finish * Process chunks in order when regenerating all roads * Address comments * Address comments * Ground level//bedrock is at min gen height - Add comment on == rather than <= being used - It's because it's only checking for the bedrock layer being broken if that's disabled * Fix offset for min build height in SchematicHandler * Better javadoc Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> * Address inclusivity issues for max world height * Javadocs/comments/deprecation * Use world min/max heights if present in QueueCoordinator * Address some deprecations for regions and biome setting * Add a count for chunks we're currently trying to load to not skip chunks at the end of a queue's edit * Use minGenHeight + 1 rather than build height in AugmentedUtils * Create utility method for layer index in GenChunk * Correct height in HybridUtils, also use minGenHeight + 1 * Don't magically split to 128 height in regeneration * Add utility methods for world height in QueueCoordinator * Clean up ClassicPlotManager road creation/removal * Start generation at min gen height if bedrock is disabled * min gen height is set in PlotArea * Add note on schem y normalisation * Improve plot getVolume method readability * Don't overly extend height when regenerating road region * y index utility method in ChunknQueueCoordinator * Layer index utility method in LocalChunk * Use version min/max heights if world not present in QueueCoordinator * Fix min -> max * Don't allow players to modify outside build height when using plot set / schematics. - Also fixes schematic height issues * Remove debug * Address comments * Switch loadingChunks to AtomicInteger to be safe (in case of multi-threaded) * Fix "security" issue that was already present * Ensure sign isn't physicsed Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
This commit is contained in:
@ -238,6 +238,16 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
return this.version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int versionMinHeight() {
|
||||
return serverVersion()[1] >= 18 ? -64 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int versionMaxHeight() {
|
||||
return serverVersion()[1] >= 18 ? 319 : 255;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String serverImplementation() {
|
||||
return Bukkit.getVersion();
|
||||
|
@ -65,7 +65,10 @@ final class BlockStatePopulator extends BlockPopulator {
|
||||
return;
|
||||
}
|
||||
final ChunkWrapper wrap = new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
|
||||
final ScopedQueueCoordinator chunk = this.queue.getForChunk(wrap.x, wrap.z);
|
||||
final ScopedQueueCoordinator chunk = this.queue.getForChunk(wrap.x, wrap.z,
|
||||
com.plotsquared.bukkit.util.BukkitWorld.getMinWorldHeight(world),
|
||||
com.plotsquared.bukkit.util.BukkitWorld.getMaxWorldHeight(world) - 1
|
||||
);
|
||||
if (this.plotGenerator.populateChunk(chunk, area)) {
|
||||
this.queue.enqueue();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.bukkit.generator;
|
||||
|
||||
import com.plotsquared.bukkit.queue.GenChunk;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitWorld;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.generator.GeneratorWrapper;
|
||||
import com.plotsquared.core.generator.IndependentPlotGenerator;
|
||||
@ -159,12 +160,14 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
@NonNull BiomeGrid biome
|
||||
) {
|
||||
|
||||
GenChunk result = new GenChunk();
|
||||
int minY = BukkitWorld.getMinWorldHeight(world);
|
||||
int maxY = BukkitWorld.getMaxWorldHeight(world);
|
||||
GenChunk result = new GenChunk(minY, maxY);
|
||||
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
|
||||
if (result.getChunkData() != null) {
|
||||
for (int chunkX = 0; chunkX < 16; chunkX++) {
|
||||
for (int chunkZ = 0; chunkZ < 16; chunkZ++) {
|
||||
for (int y = 0; y < world.getMaxHeight(); y++) {
|
||||
for (int y = minY; y < maxY; y++) {
|
||||
biome.setBiome(chunkX, y, chunkZ, Biome.PLAINS);
|
||||
|
||||
}
|
||||
|
@ -354,7 +354,8 @@ public class BlockEventListener implements Listener {
|
||||
Plot plot = area.getPlot(location);
|
||||
if (plot != null) {
|
||||
BukkitPlayer plotPlayer = BukkitUtil.adapt(player);
|
||||
if (event.getBlock().getY() == 0) {
|
||||
// == rather than <= as we only care about the "ground level" not being destroyed
|
||||
if (event.getBlock().getY() == area.getMinGenHeight()) {
|
||||
if (!Permissions
|
||||
.hasPermission(plotPlayer, Permission.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
|
||||
plotPlayer.sendMessage(
|
||||
@ -649,7 +650,8 @@ public class BlockEventListener implements Listener {
|
||||
event.getBlock().breakNaturally();
|
||||
}
|
||||
}
|
||||
if (location.getY() == 0) {
|
||||
// == rather than <= as we only care about the "ground level" not being destroyed
|
||||
if (location.getY() == area.getMinGenHeight()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -74,8 +74,9 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
private final Consumer<Throwable> throwableConsumer;
|
||||
private final boolean unloadAfter;
|
||||
private final int totalSize;
|
||||
|
||||
private final AtomicInteger expectedSize;
|
||||
private final AtomicInteger loadingChunks = new AtomicInteger();
|
||||
|
||||
private int batchSize;
|
||||
private PlotSquaredTask task;
|
||||
private boolean shouldCancel;
|
||||
@ -150,6 +151,13 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
|
||||
Chunk chunk = this.availableChunks.poll();
|
||||
if (chunk == null) {
|
||||
if (this.availableChunks.isEmpty()) {
|
||||
if (this.requestedChunks.isEmpty() && loadingChunks.get() == 0) {
|
||||
finish();
|
||||
} else {
|
||||
requestBatch();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
long[] iterationTime = new long[2];
|
||||
@ -197,9 +205,11 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
BlockVector2 chunk;
|
||||
for (int i = 0; i < this.batchSize && (chunk = this.requestedChunks.poll()) != null; i++) {
|
||||
// This required PaperLib to be bumped to version 1.0.4 to mark the request as urgent
|
||||
loadingChunks.incrementAndGet();
|
||||
PaperLib
|
||||
.getChunkAtAsync(this.bukkitWorld, chunk.getX(), chunk.getZ(), true, true)
|
||||
.whenComplete((chunkObject, throwable) -> {
|
||||
loadingChunks.decrementAndGet();
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
// We want one less because this couldn't be processed
|
||||
|
@ -111,8 +111,8 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
public boolean enqueue() {
|
||||
final Clipboard regenClipboard;
|
||||
if (isRegen()) {
|
||||
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4);
|
||||
BlockVector3 end = BlockVector3.at((getRegenEnd()[0] << 4) + 15, 255, (getRegenEnd()[1] << 4) + 15);
|
||||
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, getMinY(), getRegenStart()[1] << 4);
|
||||
BlockVector3 end = BlockVector3.at((getRegenEnd()[0] << 4) + 15, getMaxY(), (getRegenEnd()[1] << 4) + 15);
|
||||
Region region = new CuboidRegion(start, end);
|
||||
regenClipboard = new BlockArrayClipboard(region);
|
||||
regenClipboard.setOrigin(start);
|
||||
@ -134,7 +134,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
int sx = blockVector2.getX() << 4;
|
||||
int sz = blockVector2.getZ() << 4;
|
||||
if (isRegenChunk) {
|
||||
for (int layer = 0; layer < 16; layer++) {
|
||||
for (int layer = getMinLayer(); layer <= getMaxLayer(); layer++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
@ -170,7 +170,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
int lx = ChunkUtil.getX(j);
|
||||
int lz = ChunkUtil.getZ(j);
|
||||
int x = sx + lx;
|
||||
int y = ChunkUtil.getY(layer, j);
|
||||
int y = ChunkUtil.getY(layer + localChunk.getMinSection(), j);
|
||||
int z = sz + lz;
|
||||
boolean edge = Settings.QUEUE.UPDATE_EDGES && isEdge(y >> 4, lx, y & 15, lz, blockVector2,
|
||||
localChunk
|
||||
@ -179,7 +179,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
|
||||
for (int layer = 0; layer < localChunk.getBiomes().length; layer++) {
|
||||
BiomeType[] biomesLayer = localChunk.getBiomes()[layer];
|
||||
if (biomesLayer == null) {
|
||||
continue;
|
||||
@ -295,47 +295,48 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
}
|
||||
|
||||
private boolean isEdge(int layer, int x, int y, int z, BlockVector2 blockVector2, LocalChunk localChunk) {
|
||||
if (layer == 0 || layer == localChunk.getBaseblocks().length - 1) {
|
||||
int layerIndex = (layer - localChunk.getMinSection());
|
||||
if (layer == localChunk.getMinSection() || layerIndex == localChunk.getBaseblocks().length - 1) {
|
||||
return false;
|
||||
}
|
||||
if (x == 0) {
|
||||
LocalChunk localChunkX = getBlockChunks().get(blockVector2.withX(blockVector2.getX() - 1));
|
||||
if (localChunkX == null || localChunkX.getBaseblocks()[layer] == null ||
|
||||
localChunkX.getBaseblocks()[layer][ChunkUtil.getJ(15, y, z)] != null) {
|
||||
if (localChunkX == null || localChunkX.getBaseblocks()[layerIndex] == null ||
|
||||
localChunkX.getBaseblocks()[layerIndex][ChunkUtil.getJ(15, y, z)] != null) {
|
||||
return true;
|
||||
}
|
||||
} else if (x == 15) {
|
||||
LocalChunk localChunkX = getBlockChunks().get(blockVector2.withX(blockVector2.getX() + 1));
|
||||
if (localChunkX == null || localChunkX.getBaseblocks()[layer] == null ||
|
||||
localChunkX.getBaseblocks()[layer][ChunkUtil.getJ(0, y, z)] != null) {
|
||||
if (localChunkX == null || localChunkX.getBaseblocks()[layerIndex] == null ||
|
||||
localChunkX.getBaseblocks()[layerIndex][ChunkUtil.getJ(0, y, z)] != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (z == 0) {
|
||||
LocalChunk localChunkZ = getBlockChunks().get(blockVector2.withZ(blockVector2.getZ() - 1));
|
||||
if (localChunkZ == null || localChunkZ.getBaseblocks()[layer] == null ||
|
||||
localChunkZ.getBaseblocks()[layer][ChunkUtil.getJ(x, y, 15)] != null) {
|
||||
if (localChunkZ == null || localChunkZ.getBaseblocks()[layerIndex] == null ||
|
||||
localChunkZ.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, y, 15)] != null) {
|
||||
return true;
|
||||
}
|
||||
} else if (z == 15) {
|
||||
LocalChunk localChunkZ = getBlockChunks().get(blockVector2.withZ(blockVector2.getZ() + 1));
|
||||
if (localChunkZ == null || localChunkZ.getBaseblocks()[layer] == null ||
|
||||
localChunkZ.getBaseblocks()[layer][ChunkUtil.getJ(x, y, 0)] != null) {
|
||||
if (localChunkZ == null || localChunkZ.getBaseblocks()[layerIndex] == null ||
|
||||
localChunkZ.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, y, 0)] != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (y == 0) {
|
||||
if (localChunk.getBaseblocks()[layer - 1] == null ||
|
||||
localChunk.getBaseblocks()[layer][ChunkUtil.getJ(x, 15, z)] != null) {
|
||||
if (localChunk.getBaseblocks()[layerIndex - 1] == null ||
|
||||
localChunk.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, 15, z)] != null) {
|
||||
return true;
|
||||
}
|
||||
} else if (y == 15) {
|
||||
if (localChunk.getBaseblocks()[layer + 1] == null ||
|
||||
localChunk.getBaseblocks()[layer][ChunkUtil.getJ(x, 0, z)] != null) {
|
||||
if (localChunk.getBaseblocks()[layerIndex + 1] == null ||
|
||||
localChunk.getBaseblocks()[layerIndex][ChunkUtil.getJ(x, 0, z)] != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
BaseBlock[] baseBlocks = localChunk.getBaseblocks()[layer];
|
||||
BaseBlock[] baseBlocks = localChunk.getBaseblocks()[layerIndex];
|
||||
if (x > 0 && baseBlocks[ChunkUtil.getJ(x - 1, y, z)] == null) {
|
||||
return true;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.AnnotationHelper;
|
||||
import com.plotsquared.core.util.ChunkUtil;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -50,6 +51,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@AnnotationHelper.ApiDescription(info = "Internal use only. Subject to changes at any time.")
|
||||
public class GenChunk extends ScopedQueueCoordinator {
|
||||
|
||||
public final Biome[] biomes;
|
||||
@ -61,8 +63,14 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
public int chunkZ;
|
||||
private ChunkData chunkData = null;
|
||||
|
||||
public GenChunk() {
|
||||
super(null, Location.at("", 0, 0, 0), Location.at("", 15, 255, 15));
|
||||
/**
|
||||
* @param minY minimum world Y, inclusive
|
||||
* @param maxY maximum world Y, inclusive
|
||||
*
|
||||
* @since TODO
|
||||
*/
|
||||
public GenChunk(int minY, int maxY) {
|
||||
super(null, Location.at("", 0, minY, 0), Location.at("", 15, maxY, 15));
|
||||
this.biomes = Biome.values();
|
||||
}
|
||||
|
||||
@ -117,7 +125,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return;
|
||||
}
|
||||
Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
for (int y = 0; y < 256; y++) {
|
||||
for (int y = getMin().getY(); y <= getMax().getY(); y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
this.biomeGrid.setBiome(x, y, z, biome);
|
||||
@ -130,7 +138,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
public void setCuboid(@NonNull Location pos1, @NonNull Location pos2, @NonNull BlockState block) {
|
||||
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) {
|
||||
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
||||
int layer = y >> 4;
|
||||
int layer = getLayerIndex(y);
|
||||
BlockState[] data = result[layer];
|
||||
if (data == null) {
|
||||
result[layer] = data = new BlockState[4096];
|
||||
@ -164,7 +172,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
*/
|
||||
public boolean setBiome(int x, int z, @NonNull Biome biome) {
|
||||
if (this.biomeGrid != null) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
for (int y = getMin().getY(); y <= getMax().getY(); y++) {
|
||||
this.setBiome(x, y, z, biome);
|
||||
}
|
||||
return true;
|
||||
@ -197,7 +205,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
}
|
||||
|
||||
private void storeCache(final int x, final int y, final int z, final @NonNull BlockState id) {
|
||||
int i = y >> 4;
|
||||
int i = getLayerIndex(y);
|
||||
BlockState[] v = this.result[i];
|
||||
if (v == null) {
|
||||
this.result[i] = v = new BlockState[4096];
|
||||
@ -219,7 +227,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
|
||||
@Override
|
||||
public @Nullable BlockState getBlock(int x, int y, int z) {
|
||||
int i = y >> 4;
|
||||
int i = getLayerIndex(y);
|
||||
if (result == null) {
|
||||
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
|
||||
}
|
||||
@ -246,16 +254,16 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
|
||||
@Override
|
||||
public @NonNull Location getMax() {
|
||||
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
return Location.at(getWorld().getName(), 15 + (getX() << 4), super.getMax().getY(), 15 + (getZ() << 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Location getMin() {
|
||||
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
|
||||
return Location.at(getWorld().getName(), getX() << 4, super.getMin().getY(), getZ() << 4);
|
||||
}
|
||||
|
||||
public @NonNull GenChunk clone() {
|
||||
GenChunk toReturn = new GenChunk();
|
||||
GenChunk toReturn = new GenChunk(getMin().getY(), getMax().getY());
|
||||
if (this.result != null) {
|
||||
for (int i = 0; i < this.result.length; i++) {
|
||||
BlockState[] matrix = this.result[i];
|
||||
@ -269,4 +277,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
private int getLayerIndex(int y) {
|
||||
return (y - getMin().getY()) >> 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.entity.EntityCategories;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
@ -261,7 +260,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
if (checkX2 && checkZ2) {
|
||||
map.saveRegion(world, xxt2, xxt, zzt2, zzt); //
|
||||
}
|
||||
CuboidRegion currentPlotClear = RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
CuboidRegion currentPlotClear = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
|
||||
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
|
||||
AugmentedUtils.bypass(
|
||||
ignoreAugment,
|
||||
@ -276,7 +275,9 @@ public class BukkitRegionManager extends RegionManager {
|
||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
int minY = value.getMin().getY();
|
||||
for (int yIndex = 0; yIndex < ids.length; yIndex++) {
|
||||
int y = yIndex + minY;
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
@ -284,12 +285,6 @@ public class BukkitRegionManager extends RegionManager {
|
||||
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -297,7 +292,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
}, world.getName(), chunk)
|
||||
);
|
||||
//map.restoreBlocks(worldObj, 0, 0);
|
||||
map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0);
|
||||
map.restoreEntities(Bukkit.getWorld(world.getName()));
|
||||
});
|
||||
regenQueue.setCompleteTask(whenDone);
|
||||
queue.setCompleteTask(regenQueue::enqueue);
|
||||
|
@ -44,7 +44,6 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -61,7 +60,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
@ -246,7 +244,9 @@ public class BukkitUtil extends WorldUtil {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
int air = 1;
|
||||
for (int y = bukkitWorld.getMaxHeight() - 1; y >= 0; y--) {
|
||||
int maxY = com.plotsquared.bukkit.util.BukkitWorld.getMaxWorldHeight(bukkitWorld);
|
||||
int minY = com.plotsquared.bukkit.util.BukkitWorld.getMinWorldHeight(bukkitWorld);
|
||||
for (int y = maxY - 1; y >= minY; y--) {
|
||||
Block block = bukkitWorld.getBlockAt(x, y, z);
|
||||
Material type = block.getType();
|
||||
if (type.isSolid()) {
|
||||
@ -273,7 +273,9 @@ public class BukkitUtil extends WorldUtil {
|
||||
final World bukkitWorld = Objects.requireNonNull(getWorld(world));
|
||||
// Skip top and bottom block
|
||||
int air = 1;
|
||||
for (int y = bukkitWorld.getMaxHeight() - 1; y >= 0; y--) {
|
||||
int maxY = com.plotsquared.bukkit.util.BukkitWorld.getMaxWorldHeight(bukkitWorld);
|
||||
int minY = com.plotsquared.bukkit.util.BukkitWorld.getMinWorldHeight(bukkitWorld);
|
||||
for (int y = maxY - 1; y >= minY; y--) {
|
||||
Block block = bukkitWorld.getBlockAt(x, y, z);
|
||||
Material type = block.getType();
|
||||
if (type.isSolid()) {
|
||||
@ -371,7 +373,7 @@ public class BukkitUtil extends WorldUtil {
|
||||
sign.setLine(i, LEGACY_COMPONENT_SERIALIZER
|
||||
.serialize(MINI_MESSAGE.parse(lines[i].getComponent(LocaleHolder.console()), replacements)));
|
||||
}
|
||||
sign.update(true);
|
||||
sign.update(true, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -382,27 +384,6 @@ public class BukkitUtil extends WorldUtil {
|
||||
return new StringComparison<BlockState>().new ComparisonResult(1, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(
|
||||
final @NonNull String worldName,
|
||||
final @NonNull CuboidRegion region,
|
||||
final @NonNull BiomeType biomeType
|
||||
) {
|
||||
final World world = getWorld(worldName);
|
||||
if (world == null) {
|
||||
LOGGER.warn("An error occurred while setting the biome because the world was null", new RuntimeException());
|
||||
return;
|
||||
}
|
||||
final Biome biome = BukkitAdapter.adapt(biomeType);
|
||||
for (int x = region.getMinimumPoint().getX(); x <= region.getMaximumPoint().getX(); x++) {
|
||||
for (int z = region.getMinimumPoint().getZ(); z <= region.getMaximumPoint().getZ(); z++) {
|
||||
if (world.getBiome(x, z) != biome) {
|
||||
world.setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.sk89q.worldedit.world.@NonNull World getWeWorld(final @NonNull String world) {
|
||||
return new BukkitWorld(Bukkit.getWorld(world));
|
||||
|
@ -36,6 +36,18 @@ import java.util.Objects;
|
||||
public class BukkitWorld implements World<org.bukkit.World> {
|
||||
|
||||
private static final Map<String, BukkitWorld> worldMap = Maps.newHashMap();
|
||||
private static final boolean HAS_MIN_Y;
|
||||
|
||||
static {
|
||||
boolean temp;
|
||||
try {
|
||||
org.bukkit.World.class.getMethod("getMinHeight");
|
||||
temp = true;
|
||||
} catch (NoSuchMethodException e) {
|
||||
temp = false;
|
||||
}
|
||||
HAS_MIN_Y = temp;
|
||||
}
|
||||
|
||||
private final org.bukkit.World world;
|
||||
|
||||
@ -73,6 +85,24 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
||||
return bukkitWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the min world height from a Bukkit {@link org.bukkit.World}. Inclusive
|
||||
*
|
||||
* @since TODO
|
||||
*/
|
||||
public static int getMinWorldHeight(org.bukkit.World world) {
|
||||
return HAS_MIN_Y ? world.getMinHeight() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max world height from a Bukkit {@link org.bukkit.World}. Exclusive
|
||||
*
|
||||
* @since TODO
|
||||
*/
|
||||
public static int getMaxWorldHeight(org.bukkit.World world) {
|
||||
return HAS_MIN_Y ? world.getMaxHeight() : 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.World getPlatformWorld() {
|
||||
return this.world;
|
||||
@ -83,6 +113,16 @@ public class BukkitWorld implements World<org.bukkit.World> {
|
||||
return this.world.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return getMinWorldHeight(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return getMaxWorldHeight(world) - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
|
@ -70,7 +70,7 @@ public class ContentMap {
|
||||
}
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
saveBlocks(world, 256, x, z, 0, 0);
|
||||
saveBlocks(world, x, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,14 +92,7 @@ public class ContentMap {
|
||||
}
|
||||
}
|
||||
|
||||
void saveEntitiesIn(Chunk chunk, CuboidRegion region) {
|
||||
saveEntitiesIn(chunk, region, 0, 0, false);
|
||||
}
|
||||
|
||||
void saveEntitiesIn(
|
||||
Chunk chunk, CuboidRegion region, int offsetX, int offsetZ,
|
||||
boolean delete
|
||||
) {
|
||||
void saveEntitiesIn(Chunk chunk, CuboidRegion region, boolean delete) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
Location location = BukkitUtil.adapt(entity.getLocation());
|
||||
int x = location.getX();
|
||||
@ -111,8 +104,6 @@ public class ContentMap {
|
||||
continue;
|
||||
}
|
||||
EntityWrapper wrap = new ReplicatingEntityWrapper(entity, (short) 2);
|
||||
wrap.x += offsetX;
|
||||
wrap.z += offsetZ;
|
||||
wrap.saveEntity();
|
||||
this.entities.add(wrap);
|
||||
if (delete) {
|
||||
@ -123,10 +114,10 @@ public class ContentMap {
|
||||
}
|
||||
}
|
||||
|
||||
void restoreEntities(World world, int xOffset, int zOffset) {
|
||||
void restoreEntities(World world) {
|
||||
for (EntityWrapper entity : this.entities) {
|
||||
try {
|
||||
entity.spawn(world, xOffset, zOffset);
|
||||
entity.spawn(world, 0, 0);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Failed to restore entity", e);
|
||||
}
|
||||
@ -134,15 +125,13 @@ public class ContentMap {
|
||||
this.entities.clear();
|
||||
}
|
||||
|
||||
//todo optimize maxY
|
||||
void saveBlocks(BukkitWorld world, int maxY, int x, int z, int offsetX, int offsetZ) {
|
||||
maxY = Math.min(255, maxY);
|
||||
BaseBlock[] ids = new BaseBlock[maxY + 1];
|
||||
for (short y = 0; y <= maxY; y++) {
|
||||
BaseBlock block = world.getFullBlock(BlockVector3.at(x, y, z));
|
||||
ids[y] = block;
|
||||
private void saveBlocks(BukkitWorld world, int x, int z) {
|
||||
BaseBlock[] ids = new BaseBlock[world.getMaxY() - world.getMinY() + 1];
|
||||
for (short yIndex = 0; yIndex <= world.getMaxY() - world.getMinY(); yIndex++) {
|
||||
BaseBlock block = world.getFullBlock(BlockVector3.at(x, yIndex + world.getMinY(), z));
|
||||
ids[yIndex] = block;
|
||||
}
|
||||
PlotLoc loc = new PlotLoc(x + offsetX, z + offsetZ);
|
||||
PlotLoc loc = new PlotLoc(x, z);
|
||||
this.allBlocks.put(loc, ids);
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,11 @@ public class FaweRegionManager extends BukkitRegionManager {
|
||||
delegate.setBiome(region, extendBiome, biome, world, whenDone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(CuboidRegion region, int extendBiome, BiomeType biome, PlotArea area, Runnable whenDone) {
|
||||
delegate.setBiome(region, extendBiome, biome, area.getWorldName(), whenDone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyRegion(
|
||||
final @NonNull Location pos1,
|
||||
|
Reference in New Issue
Block a user