mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-30 20:54:44 +02:00
Switch to using QueueCoordinators everywhere
This commit is contained in:
@ -53,6 +53,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
|
||||
private final World world;
|
||||
private final SideEffectSet sideEffectSet;
|
||||
private Runnable whenDone;
|
||||
|
||||
public BukkitQueueCoordinator(World world) {
|
||||
super(world);
|
||||
@ -74,91 +75,96 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
@Override public boolean enqueue() {
|
||||
BukkitChunkCoordinator.builder().inWorld(BukkitAdapter.adapt(world))
|
||||
.withChunks(getBlockChunks().keySet()).withInitialBatchSize(3).withMaxIterationTime(40)
|
||||
.withThrowableConsumer(Throwable::printStackTrace).withConsumer(chunk -> {
|
||||
LocalChunk localChunk =
|
||||
getBlockChunks().get(BlockVector2.at(chunk.getX(), chunk.getZ()));
|
||||
if (localChunk == null) {
|
||||
throw new NullPointerException(
|
||||
"LocalChunk cannot be null when accessed from ChunkCoordinator");
|
||||
}
|
||||
World worldObj = getWorld();
|
||||
int sx = chunk.getX() << 4;
|
||||
int sz = chunk.getX() << 4;
|
||||
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
|
||||
BaseBlock[] blocksLayer = localChunk.getBaseblocks()[layer];
|
||||
if (blocksLayer == null) {
|
||||
continue;
|
||||
.withThrowableConsumer(Throwable::printStackTrace).withFinalAction(whenDone)
|
||||
.withConsumer(chunk -> {
|
||||
LocalChunk localChunk =
|
||||
getBlockChunks().get(BlockVector2.at(chunk.getX(), chunk.getZ()));
|
||||
if (localChunk == null) {
|
||||
throw new NullPointerException(
|
||||
"LocalChunk cannot be null when accessed from ChunkCoordinator");
|
||||
}
|
||||
for (int j = 0; j < blocksLayer.length; j++) {
|
||||
if (blocksLayer[j] == null) {
|
||||
World worldObj = getWorld();
|
||||
int sx = chunk.getX() << 4;
|
||||
int sz = chunk.getX() << 4;
|
||||
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
|
||||
BaseBlock[] blocksLayer = localChunk.getBaseblocks()[layer];
|
||||
if (blocksLayer == null) {
|
||||
continue;
|
||||
}
|
||||
BaseBlock block = blocksLayer[j];
|
||||
int x = sx + MainUtil.x_loc[layer][j];
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = sz + MainUtil.z_loc[layer][j];
|
||||
try {
|
||||
worldObj.setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
// Fallback to not so nice method
|
||||
BlockData blockData = BukkitAdapter.adapt(block);
|
||||
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
final BlockState existingBaseBlock =
|
||||
BukkitAdapter.adapt(existing.getBlockData());
|
||||
if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing
|
||||
.getBlockData().matches(blockData)) {
|
||||
for (int j = 0; j < blocksLayer.length; j++) {
|
||||
if (blocksLayer[j] == null) {
|
||||
continue;
|
||||
}
|
||||
BaseBlock block = blocksLayer[j];
|
||||
int x = sx + MainUtil.x_loc[layer][j];
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = sz + MainUtil.z_loc[layer][j];
|
||||
try {
|
||||
worldObj.setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
// Fallback to not so nice method
|
||||
BlockData blockData = BukkitAdapter.adapt(block);
|
||||
|
||||
if (existing.getState() instanceof Container) {
|
||||
((Container) existing.getState()).getInventory().clear();
|
||||
}
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
final BlockState existingBaseBlock =
|
||||
BukkitAdapter.adapt(existing.getBlockData());
|
||||
if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing
|
||||
.getBlockData().matches(blockData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
existing.setType(BukkitAdapter.adapt(block.getBlockType()), false);
|
||||
existing.setBlockData(blockData, false);
|
||||
if (block.hasNbtData()) {
|
||||
CompoundTag tag = block.getNbtData();
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
if (existing.getState() instanceof Container) {
|
||||
((Container) existing.getState()).getInventory().clear();
|
||||
}
|
||||
|
||||
sw.restoreTag(worldObj.getName(), existing.getX(), existing.getY(),
|
||||
existing.getZ());
|
||||
existing.setType(BukkitAdapter.adapt(block.getBlockType()), false);
|
||||
existing.setBlockData(blockData, false);
|
||||
if (block.hasNbtData()) {
|
||||
CompoundTag tag = block.getNbtData();
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
|
||||
sw.restoreTag(worldObj.getName(), existing.getX(), existing.getY(),
|
||||
existing.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
|
||||
BiomeType[] biomesLayer = localChunk.getBiomes()[layer];
|
||||
if (biomesLayer == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < biomesLayer.length; j++) {
|
||||
if (biomesLayer[j] == null) {
|
||||
for (int layer = 0; layer < localChunk.getBaseblocks().length; layer++) {
|
||||
BiomeType[] biomesLayer = localChunk.getBiomes()[layer];
|
||||
if (biomesLayer == null) {
|
||||
continue;
|
||||
}
|
||||
BiomeType biome = biomesLayer[j];
|
||||
int x = sx + MainUtil.x_loc[layer][j];
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = sz + MainUtil.z_loc[layer][j];
|
||||
worldObj.setBiome(BlockVector3.at(x, y, z), biome);
|
||||
}
|
||||
}
|
||||
if (localChunk.getTiles().size() > 0) {
|
||||
localChunk.getTiles().forEach(((blockVector3, tag) -> {
|
||||
try {
|
||||
BaseBlock block = worldObj.getBlock(blockVector3).toBaseBlock(tag);
|
||||
worldObj.setBlock(blockVector3, block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
sw.restoreTag(worldObj.getName(), blockVector3.getX(), blockVector3.getY(),
|
||||
blockVector3.getZ());
|
||||
for (int j = 0; j < biomesLayer.length; j++) {
|
||||
if (biomesLayer[j] == null) {
|
||||
continue;
|
||||
}
|
||||
BiomeType biome = biomesLayer[j];
|
||||
int x = sx + MainUtil.x_loc[layer][j];
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = sz + MainUtil.z_loc[layer][j];
|
||||
worldObj.setBiome(BlockVector3.at(x, y, z), biome);
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (localChunk.getTiles().size() > 0) {
|
||||
localChunk.getTiles().forEach(((blockVector3, tag) -> {
|
||||
try {
|
||||
BaseBlock block = worldObj.getBlock(blockVector3).toBaseBlock(tag);
|
||||
worldObj.setBlock(blockVector3, block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
sw.restoreTag(worldObj.getName(), blockVector3.getX(),
|
||||
blockVector3.getY(), blockVector3.getZ());
|
||||
}
|
||||
}));
|
||||
}
|
||||
});
|
||||
return super.enqueue();
|
||||
}
|
||||
|
||||
@Override public void setCompleteTask(Runnable whenDone) {
|
||||
this.whenDone = whenDone;
|
||||
}
|
||||
|
||||
private void setMaterial(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
|
||||
Material material = BukkitAdapter.adapt(plotBlock.getBlockType());
|
||||
block.setType(material, false);
|
||||
|
@ -30,7 +30,7 @@ import com.plotsquared.bukkit.util.BukkitBlockUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.plotsquared.core.location.ChunkWrapper;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -41,16 +41,17 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GenChunk extends ScopedLocalBlockQueue {
|
||||
public class GenChunk extends ScopedQueueCoordinator {
|
||||
|
||||
public final Biome[] biomes;
|
||||
public BlockState[][] result;
|
||||
@ -191,16 +192,18 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
return chunk == null ? chunkZ : chunk.getZ();
|
||||
}
|
||||
|
||||
@Override public String getWorld() {
|
||||
return chunk == null ? world : chunk.getWorld().getName();
|
||||
@Override public com.sk89q.worldedit.world.World getWorld() {
|
||||
return chunk == null ?
|
||||
BukkitAdapter.adapt(Bukkit.getWorld(world)) :
|
||||
BukkitAdapter.adapt(chunk.getWorld());
|
||||
}
|
||||
|
||||
@Override public Location getMax() {
|
||||
return Location.at(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
}
|
||||
|
||||
@Override public Location getMin() {
|
||||
return Location.at(getWorld(), getX() << 4, 0, getZ() << 4);
|
||||
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
|
||||
}
|
||||
|
||||
public GenChunk clone() {
|
||||
|
Reference in New Issue
Block a user