mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-30 20:54:44 +02:00
Formatting, mark nonnull, nullable etc
This commit is contained in:
@ -76,13 +76,13 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
private int batchSize;
|
||||
|
||||
@Inject private BukkitChunkCoordinator(@Assisted final long maxIterationTime,
|
||||
@Assisted final int initialBatchSize,
|
||||
@Assisted @Nonnull final Consumer<BlockVector2> chunkConsumer,
|
||||
@Assisted @Nonnull final World world,
|
||||
@Assisted @Nonnull final Collection<BlockVector2> requestedChunks,
|
||||
@Assisted @Nonnull final Runnable whenDone,
|
||||
@Assisted @Nonnull final Consumer<Throwable> throwableConsumer,
|
||||
@Assisted final boolean unloadAfter) {
|
||||
@Assisted final int initialBatchSize,
|
||||
@Assisted @Nonnull final Consumer<BlockVector2> chunkConsumer,
|
||||
@Assisted @Nonnull final World world,
|
||||
@Assisted @Nonnull final Collection<BlockVector2> requestedChunks,
|
||||
@Assisted @Nonnull final Runnable whenDone,
|
||||
@Assisted @Nonnull final Consumer<Throwable> throwableConsumer,
|
||||
@Assisted final boolean unloadAfter) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
this.totalSize = requestedChunks.size();
|
||||
@ -104,8 +104,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
// Request initial batch
|
||||
this.requestBatch();
|
||||
// Wait until next tick to give the chunks a chance to be loaded
|
||||
TaskManager.runTaskLater(() -> TaskManager.runTaskRepeat(this, TaskTime.ticks(1)),
|
||||
TaskTime.ticks(1));
|
||||
TaskManager.runTaskLater(() -> TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
|
||||
}
|
||||
|
||||
@Override public void runTask() {
|
||||
@ -129,8 +128,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
final long end = System.currentTimeMillis();
|
||||
// Update iteration time
|
||||
iterationTime = end - start;
|
||||
} while (2 * iterationTime /* last chunk + next chunk */ < this.maxIterationTime
|
||||
&& (chunk = availableChunks.poll()) != null);
|
||||
} while (2 * iterationTime /* last chunk + next chunk */ < this.maxIterationTime && (chunk = availableChunks.poll()) != null);
|
||||
if (processedChunks < this.batchSize) {
|
||||
// Adjust batch size based on the amount of processed chunks per tick
|
||||
this.batchSize = processedChunks;
|
||||
@ -157,36 +155,42 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a batch of chunks to be loaded
|
||||
*/
|
||||
private void requestBatch() {
|
||||
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
|
||||
PaperLib.getChunkAtAsync(this.bukkitWorld, chunk.getX(), chunk.getZ(), true, true)
|
||||
.whenComplete((chunkObject, throwable) -> {
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
// We want one less because this couldn't be processed
|
||||
this.expectedSize.decrementAndGet();
|
||||
} else {
|
||||
this.processChunk(chunkObject);
|
||||
}
|
||||
});
|
||||
PaperLib.getChunkAtAsync(this.bukkitWorld, chunk.getX(), chunk.getZ(), true, true).whenComplete((chunkObject, throwable) -> {
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
// We want one less because this couldn't be processed
|
||||
this.expectedSize.decrementAndGet();
|
||||
} else {
|
||||
this.processChunk(chunkObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Once a chunk has been loaded, process it (add a plugin ticket and add to available chunks list)
|
||||
*/
|
||||
private void processChunk(@Nonnull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.addPluginChunkTicket(this.plugin);
|
||||
this.availableChunks.add(chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Once a chunk has been used, free it up for unload by removing the plugin ticket
|
||||
*/
|
||||
private void freeChunk(@Nonnull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.removePluginChunkTicket(this.plugin);
|
||||
}
|
||||
@ -214,8 +218,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
*
|
||||
* @param subscriber Subscriber
|
||||
*/
|
||||
public void subscribeToProgress(
|
||||
@Nonnull final BukkitChunkCoordinator.ProgressSubscriber subscriber) {
|
||||
public void subscribeToProgress(@Nonnull final BukkitChunkCoordinator.ProgressSubscriber subscriber) {
|
||||
this.progressSubscribers.add(subscriber);
|
||||
}
|
||||
|
||||
@ -228,8 +231,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
* @param coordinator Coordinator instance that triggered the notification
|
||||
* @param progress Progress in the range [0, 1]
|
||||
*/
|
||||
void notifyProgress(@Nonnull final BukkitChunkCoordinator coordinator,
|
||||
final float progress);
|
||||
void notifyProgress(@Nonnull final BukkitChunkCoordinator coordinator, final float progress);
|
||||
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,7 @@ 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;
|
||||
@ -69,10 +70,9 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
private Runnable whenDone;
|
||||
private ChunkCoordinator chunkCoordinator;
|
||||
|
||||
@Inject public BukkitQueueCoordinator(World world) {
|
||||
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
||||
super(world);
|
||||
sideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF)
|
||||
.with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||
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) {
|
||||
@ -97,10 +97,8 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
@Override 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, 0, getRegenStart()[1] << 4);
|
||||
BlockVector3 end = BlockVector3.at((getRegenEnd()[0] << 4) + 15, 255, (getRegenEnd()[1] << 4) + 15);
|
||||
Region region = new CuboidRegion(start, end);
|
||||
regenClipboard = new BlockArrayClipboard(region);
|
||||
regenClipboard.setOrigin(start);
|
||||
@ -117,17 +115,14 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
consumer = blockVector2 -> {
|
||||
LocalChunk localChunk = getBlockChunks().get(blockVector2);
|
||||
boolean isRegenChunk =
|
||||
regenClipboard != null && blockVector2.getBlockX() > getRegenStart()[0]
|
||||
&& blockVector2.getBlockZ() > getRegenStart()[1]
|
||||
&& blockVector2.getBlockX() < getRegenEnd()[0]
|
||||
&& blockVector2.getBlockZ() < getRegenEnd()[1];
|
||||
regenClipboard != null && blockVector2.getBlockX() > getRegenStart()[0] && blockVector2.getBlockZ() > getRegenStart()[1]
|
||||
&& blockVector2.getBlockX() < getRegenEnd()[0] && blockVector2.getBlockZ() < getRegenEnd()[1];
|
||||
if (isRegenChunk) {
|
||||
for (int layer = 0; layer < 16; layer++) {
|
||||
for (int y = layer << 4; y < 16; y++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
BaseBlock block =
|
||||
regenClipboard.getFullBlock(BlockVector3.at(x, y, z));
|
||||
BaseBlock block = regenClipboard.getFullBlock(BlockVector3.at(x, y, z));
|
||||
if (block != null) {
|
||||
setWorldBlock(x, y, z, block, blockVector2);
|
||||
}
|
||||
@ -186,8 +181,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
getWorld().setBlock(blockVector3, block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
sw.restoreTag(getWorld().getName(), blockVector3.getX(),
|
||||
blockVector3.getY(), blockVector3.getZ());
|
||||
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -203,15 +197,16 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
read.addAll(getReadChunks());
|
||||
}
|
||||
chunkCoordinator =
|
||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld())
|
||||
.withChunks(getBlockChunks().keySet()).withChunks(read).withInitialBatchSize(3)
|
||||
.withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace)
|
||||
.withFinalAction(whenDone).withConsumer(consumer).unloadAfter(isUnloadAfter())
|
||||
.build();
|
||||
chunkCoordinatorBuilderFactory.create(chunkCoordinatorFactory).inWorld(getWorld()).withChunks(getBlockChunks().keySet()).withChunks(read)
|
||||
.withInitialBatchSize(3).withMaxIterationTime(40).withThrowableConsumer(Throwable::printStackTrace).withFinalAction(whenDone)
|
||||
.withConsumer(consumer).unloadAfter(isUnloadAfter()).build();
|
||||
return super.enqueue();
|
||||
}
|
||||
|
||||
private void setWorldBlock(int x, int y, int z, BaseBlock block, BlockVector2 blockVector2) {
|
||||
/**
|
||||
* Set a block to the world. First tries WNA but defaults to normal block setting methods if that fails
|
||||
*/
|
||||
private void setWorldBlock(int x, int y, int z, @Nonnull BaseBlock block, @Nonnull BlockVector2 blockVector2) {
|
||||
try {
|
||||
getWorld().setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
|
||||
} catch (WorldEditException ignored) {
|
||||
@ -225,8 +220,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
final BlockState existingBaseBlock = BukkitAdapter.adapt(existing.getBlockData());
|
||||
if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing.getBlockData()
|
||||
.matches(blockData)) {
|
||||
if (BukkitBlockUtil.get(existing).equals(existingBaseBlock) && existing.getBlockData().matches(blockData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -240,8 +234,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
CompoundTag tag = block.getNbtData();
|
||||
StateWrapper sw = new StateWrapper(tag);
|
||||
|
||||
sw.restoreTag(getWorld().getName(), existing.getX(), existing.getY(),
|
||||
existing.getZ());
|
||||
sw.restoreTag(getWorld().getName(), existing.getX(), existing.getY(), existing.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,10 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GenChunk extends ScopedQueueCoordinator {
|
||||
@ -65,15 +67,15 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
this.biomes = Biome.values();
|
||||
}
|
||||
|
||||
public ChunkData getChunkData() {
|
||||
@Nullable public ChunkData getChunkData() {
|
||||
return this.chunkData;
|
||||
}
|
||||
|
||||
public void setChunkData(ChunkData chunkData) {
|
||||
public void setChunkData(@Nonnull ChunkData chunkData) {
|
||||
this.chunkData = chunkData;
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
@Nonnull public Chunk getChunk() {
|
||||
if (chunk == null) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
if (worldObj != null) {
|
||||
@ -83,18 +85,18 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public void setChunk(Chunk chunk) {
|
||||
public void setChunk(@Nonnull Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
public void setChunk(ChunkWrapper wrap) {
|
||||
public void setChunk(@Nonnull ChunkWrapper wrap) {
|
||||
chunk = null;
|
||||
world = wrap.world;
|
||||
chunkX = wrap.x;
|
||||
chunkZ = wrap.z;
|
||||
}
|
||||
|
||||
@Override public void fillBiome(BiomeType biomeType) {
|
||||
@Override public void fillBiome(@Nonnull BiomeType biomeType) {
|
||||
if (biomeGrid == null) {
|
||||
return;
|
||||
}
|
||||
@ -106,9 +108,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setCuboid(Location pos1, Location pos2, BlockState block) {
|
||||
if (result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15
|
||||
&& pos2.getZ() == 15) {
|
||||
@Override public void setCuboid(@NotNull Location pos1, @NotNull Location pos2, @NotNull 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;
|
||||
BlockState[] data = result[layer];
|
||||
@ -126,15 +127,14 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
int maxX = Math.max(pos1.getX(), pos2.getX());
|
||||
int maxY = Math.max(pos1.getY(), pos2.getY());
|
||||
int maxZ = Math.max(pos1.getZ(), pos2.getZ());
|
||||
chunkData
|
||||
.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, BukkitAdapter.adapt(block));
|
||||
chunkData.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, BukkitAdapter.adapt(block));
|
||||
}
|
||||
|
||||
@Override public boolean setBiome(int x, int z, BiomeType biomeType) {
|
||||
@Override public boolean setBiome(int x, int z, @NotNull BiomeType biomeType) {
|
||||
return setBiome(x, z, BukkitAdapter.adapt(biomeType));
|
||||
}
|
||||
|
||||
public boolean setBiome(int x, int z, Biome biome) {
|
||||
public boolean setBiome(int x, int z, @Nonnull Biome biome) {
|
||||
if (this.biomeGrid != null) {
|
||||
this.biomeGrid.setBiome(x, z, biome);
|
||||
return true;
|
||||
@ -142,12 +142,11 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull Pattern pattern) {
|
||||
return setBlock(x, y, z, PatternUtil
|
||||
.apply(Preconditions.checkNotNull(pattern, "Pattern may not be null"), x, y, z));
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull @NotNull Pattern pattern) {
|
||||
return setBlock(x, y, z, PatternUtil.apply(Preconditions.checkNotNull(pattern, "Pattern may not be null"), x, y, z));
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
||||
@Override public boolean setBlock(int x, int y, int z, @NotNull BlockState id) {
|
||||
if (this.result == null) {
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
return true;
|
||||
@ -157,7 +156,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void storeCache(final int x, final int y, final int z, final BlockState id) {
|
||||
private void storeCache(final int x, final int y, final int z, @Nonnull final BlockState id) {
|
||||
int i = y >> 4;
|
||||
BlockState[] v = this.result[i];
|
||||
if (v == null) {
|
||||
@ -167,7 +166,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
v[j] = id;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BaseBlock id) {
|
||||
@Override public boolean setBlock(int x, int y, int z, @NotNull BaseBlock id) {
|
||||
if (this.result == null) {
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
return true;
|
||||
@ -177,7 +176,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
@Override @Nullable public BlockState getBlock(int x, int y, int z) {
|
||||
int i = y >> 4;
|
||||
if (result == null) {
|
||||
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
|
||||
@ -198,21 +197,19 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return chunk == null ? chunkZ : chunk.getZ();
|
||||
}
|
||||
|
||||
@Override public com.sk89q.worldedit.world.World getWorld() {
|
||||
return chunk == null ?
|
||||
BukkitAdapter.adapt(Bukkit.getWorld(world)) :
|
||||
BukkitAdapter.adapt(chunk.getWorld());
|
||||
@Override @Nonnull public com.sk89q.worldedit.world.World getWorld() {
|
||||
return chunk == null ? BukkitAdapter.adapt(Bukkit.getWorld(world)) : BukkitAdapter.adapt(chunk.getWorld());
|
||||
}
|
||||
|
||||
@Override public Location getMax() {
|
||||
@Override @Nonnull public Location getMax() {
|
||||
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
}
|
||||
|
||||
@Override public Location getMin() {
|
||||
@Override @Nonnull public Location getMin() {
|
||||
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
|
||||
}
|
||||
|
||||
public GenChunk clone() {
|
||||
@Nonnull public GenChunk clone() {
|
||||
GenChunk toReturn = new GenChunk();
|
||||
if (this.result != null) {
|
||||
for (int i = 0; i < this.result.length; i++) {
|
||||
|
Reference in New Issue
Block a user