mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-30 20:54:44 +02:00
Many Much
- Add readregions to queues for when we're setting our own consumer (usually meaning the queue writes its own blocks, so it doesn't know which chunks to actually load) - Finish removing chunk/regionTasks - Allow the queue to not remove tickets from chunks (useful for swapping chunks so they don't unload needlessly) - Remove a lot of unused methods - Implement entities to queues - Remove chunk unloading (the server should really handle it)
This commit is contained in:
@ -69,6 +69,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
private final org.bukkit.World bukkitWorld;
|
||||
private final Runnable whenDone;
|
||||
private final Consumer<Throwable> throwableConsumer;
|
||||
private final boolean unloadAfter;
|
||||
private final int totalSize;
|
||||
|
||||
private final AtomicInteger expectedSize;
|
||||
@ -80,7 +81,8 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
@Assisted @Nonnull final World world,
|
||||
@Assisted @Nonnull final Collection<BlockVector2> requestedChunks,
|
||||
@Assisted @Nonnull final Runnable whenDone,
|
||||
@Assisted @Nonnull final Consumer<Throwable> throwableConsumer) {
|
||||
@Assisted @Nonnull final Consumer<Throwable> throwableConsumer,
|
||||
@Assisted final boolean unloadAfter) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
this.totalSize = requestedChunks.size();
|
||||
@ -90,6 +92,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
this.maxIterationTime = maxIterationTime;
|
||||
this.whenDone = whenDone;
|
||||
this.throwableConsumer = throwableConsumer;
|
||||
this.unloadAfter = unloadAfter;
|
||||
this.plugin = JavaPlugin.getPlugin(BukkitPlatform.class);
|
||||
this.bukkitWorld = Bukkit.getWorld(world.getName());
|
||||
}
|
||||
@ -119,7 +122,9 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
} catch (final Throwable throwable) {
|
||||
this.throwableConsumer.accept(throwable);
|
||||
}
|
||||
this.freeChunk(chunk);
|
||||
if (unloadAfter) {
|
||||
this.freeChunk(chunk);
|
||||
}
|
||||
processedChunks++;
|
||||
final long end = System.currentTimeMillis();
|
||||
// Update iteration time
|
||||
|
@ -52,17 +52,16 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
|
||||
private final World world;
|
||||
private final SideEffectSet sideEffectSet;
|
||||
private org.bukkit.World bukkitWorld;
|
||||
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||
@ -72,13 +71,12 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
|
||||
@Inject public BukkitQueueCoordinator(World world) {
|
||||
super(world);
|
||||
this.world = world;
|
||||
sideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF)
|
||||
.with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
org.bukkit.World worldObj = BukkitAdapter.adapt(world);
|
||||
org.bukkit.World worldObj = BukkitAdapter.adapt(getWorld());
|
||||
if (worldObj != null) {
|
||||
Block block = worldObj.getBlockAt(x, y, z);
|
||||
return BukkitBlockUtil.get(block);
|
||||
@ -103,7 +101,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4),
|
||||
BlockVector3.at((getRegenEnd()[0] << 4) + 15, 255, (getRegenEnd()[1] << 4) + 15));
|
||||
regenClipboard = new BlockArrayClipboard(region);
|
||||
world.regenerate(region, regenClipboard);
|
||||
getWorld().regenerate(region, regenClipboard);
|
||||
} else {
|
||||
regenClipboard = null;
|
||||
}
|
||||
@ -164,40 +162,51 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
int x = sx + ChunkUtil.getX(j);
|
||||
int y = ChunkUtil.getY(layer, j);
|
||||
int z = sz + ChunkUtil.getZ(j);
|
||||
world.setBiome(BlockVector3.at(x, y, z), biome);
|
||||
getWorld().setBiome(BlockVector3.at(x, y, z), biome);
|
||||
}
|
||||
}
|
||||
if (localChunk.getTiles().size() > 0) {
|
||||
localChunk.getTiles().forEach(((blockVector3, tag) -> {
|
||||
try {
|
||||
BaseBlock block = world.getBlock(blockVector3).toBaseBlock(tag);
|
||||
world.setBlock(blockVector3, block, sideEffectSet);
|
||||
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
|
||||
getWorld().setBlock(blockVector3, block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
sw.restoreTag(world.getName(), blockVector3.getX(), blockVector3.getY(),
|
||||
blockVector3.getZ());
|
||||
sw.restoreTag(getWorld().getName(), blockVector3.getX(),
|
||||
blockVector3.getY(), blockVector3.getZ());
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (localChunk.getEntities().size() > 0) {
|
||||
localChunk.getEntities().forEach((location, entity) -> {
|
||||
getWorld().createEntity(location, entity);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
CuboidRegion region;
|
||||
Collection<BlockVector2> read = new ArrayList<>();
|
||||
if ((region = getReadRegion()) != null) {
|
||||
read = region.getChunks();
|
||||
}
|
||||
chunkCoordinator =
|
||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(world)
|
||||
.withChunks(getBlockChunks().keySet()).withInitialBatchSize(3)
|
||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld())
|
||||
.withChunks(getBlockChunks().keySet()).withChunks(read).withInitialBatchSize(3)
|
||||
.withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace)
|
||||
.withFinalAction(whenDone).withConsumer(consumer).build();
|
||||
.withFinalAction(whenDone).withConsumer(consumer).unloadAfter(isUnloadAfter())
|
||||
.build();
|
||||
return super.enqueue();
|
||||
}
|
||||
|
||||
private void setWorldBlock(int x, int y, int z, BaseBlock block, BlockVector2 blockVector2) {
|
||||
try {
|
||||
world.setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
|
||||
getWorld().setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
// Fallback to not so nice method
|
||||
BlockData blockData = BukkitAdapter.adapt(block);
|
||||
|
||||
if (bukkitWorld == null) {
|
||||
bukkitWorld = Bukkit.getWorld(world.getName());
|
||||
bukkitWorld = Bukkit.getWorld(getWorld().getName());
|
||||
}
|
||||
Chunk chunk = bukkitWorld.getChunkAt(blockVector2.getX(), blockVector2.getZ());
|
||||
|
||||
@ -218,7 +227,8 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
CompoundTag tag = block.getNbtData();
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
|
||||
sw.restoreTag(world.getName(), existing.getX(), existing.getY(), existing.getZ());
|
||||
sw.restoreTag(getWorld().getName(), existing.getX(), existing.getY(),
|
||||
existing.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -227,13 +237,4 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
this.whenDone = whenDone;
|
||||
}
|
||||
|
||||
private void setMaterial(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
|
||||
Material material = BukkitAdapter.adapt(plotBlock.getBlockType());
|
||||
block.setType(material, false);
|
||||
}
|
||||
|
||||
private boolean equals(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
|
||||
return plotBlock.equals(BukkitBlockUtil.get(block));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user