mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-30 20:54:44 +02:00
Initial annotation usage cleanup + EditorConfig
This commit is contained in:
@ -39,8 +39,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -76,15 +76,18 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
private final AtomicInteger expectedSize;
|
||||
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 @Nonnull final Collection<ProgressSubscriber> progressSubscribers) {
|
||||
@Inject
|
||||
private BukkitChunkCoordinator(
|
||||
@Assisted final long maxIterationTime,
|
||||
@Assisted final int initialBatchSize,
|
||||
@Assisted final @NonNull Consumer<BlockVector2> chunkConsumer,
|
||||
@Assisted final @NonNull World world,
|
||||
@Assisted final @NonNull Collection<BlockVector2> requestedChunks,
|
||||
@Assisted final @NonNull Runnable whenDone,
|
||||
@Assisted final @NonNull Consumer<Throwable> throwableConsumer,
|
||||
@Assisted final boolean unloadAfter,
|
||||
@Assisted final @NonNull Collection<ProgressSubscriber> progressSubscribers
|
||||
) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
this.totalSize = requestedChunks.size();
|
||||
@ -100,14 +103,16 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
this.progressSubscribers.addAll(progressSubscribers);
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
@Override
|
||||
public void start() {
|
||||
// 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));
|
||||
}
|
||||
|
||||
@Override public void runTask() {
|
||||
@Override
|
||||
public void runTask() {
|
||||
Chunk chunk = this.availableChunks.poll();
|
||||
if (chunk == null) {
|
||||
return;
|
||||
@ -166,22 +171,24 @@ 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
|
||||
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) {
|
||||
private void processChunk(final @NonNull Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
@ -192,18 +199,20 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
/**
|
||||
* Once a chunk has been used, free it up for unload by removing the plugin ticket
|
||||
*/
|
||||
private void freeChunk(@Nonnull final Chunk chunk) {
|
||||
private void freeChunk(final @NonNull Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.removePluginChunkTicket(this.plugin);
|
||||
}
|
||||
|
||||
@Override public int getRemainingChunks() {
|
||||
@Override
|
||||
public int getRemainingChunks() {
|
||||
return this.expectedSize.get();
|
||||
}
|
||||
|
||||
@Override public int getTotalChunks() {
|
||||
@Override
|
||||
public int getTotalChunks() {
|
||||
return this.totalSize;
|
||||
}
|
||||
|
||||
@ -212,7 +221,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
*
|
||||
* @param subscriber Subscriber
|
||||
*/
|
||||
public void subscribeToProgress(@Nonnull final ProgressSubscriber subscriber) {
|
||||
public void subscribeToProgress(final @NonNull ProgressSubscriber subscriber) {
|
||||
this.progressSubscribers.add(subscriber);
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
@ -65,31 +65,41 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
private final SideEffectSet noSideEffectSet;
|
||||
private final SideEffectSet lightingSideEffectSet;
|
||||
private org.bukkit.World bukkitWorld;
|
||||
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||
@Inject
|
||||
private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
|
||||
@Inject
|
||||
private ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||
private ChunkCoordinator chunkCoordinator;
|
||||
|
||||
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
|
||||
@Inject
|
||||
public BukkitQueueCoordinator(@NonNull World world) {
|
||||
super(world);
|
||||
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(
|
||||
SideEffect.NEIGHBORS,
|
||||
SideEffect.State.OFF
|
||||
);
|
||||
lightingSideEffectSet = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
|
||||
}
|
||||
|
||||
@Override public BlockState getBlock(int x, int y, int z) {
|
||||
@Override
|
||||
public BlockState getBlock(int x, int y, int z) {
|
||||
Block block = getBukkitWorld().getBlockAt(x, y, z);
|
||||
return BukkitBlockUtil.get(block);
|
||||
}
|
||||
|
||||
@Override public void start() {
|
||||
@Override
|
||||
public void start() {
|
||||
chunkCoordinator.start();
|
||||
}
|
||||
|
||||
//TODO: implement cancellation
|
||||
@Override public void cancel() {
|
||||
@Override
|
||||
public void cancel() {
|
||||
chunkCoordinator.cancel();
|
||||
}
|
||||
|
||||
@Override public boolean enqueue() {
|
||||
@Override
|
||||
public boolean enqueue() {
|
||||
final Clipboard regenClipboard;
|
||||
if (isRegen()) {
|
||||
BlockVector3 start = BlockVector3.at(getRegenStart()[0] << 4, 0, getRegenStart()[1] << 4);
|
||||
@ -110,8 +120,8 @@ 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++) {
|
||||
@ -190,16 +200,26 @@ 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(getCompleteTask())
|
||||
.withConsumer(consumer).unloadAfter(isUnloadAfter()).withProgressSubscribers(getProgressSubscribers()).build();
|
||||
chunkCoordinatorBuilderFactory
|
||||
.create(chunkCoordinatorFactory)
|
||||
.inWorld(getWorld())
|
||||
.withChunks(getBlockChunks().keySet())
|
||||
.withChunks(read)
|
||||
.withInitialBatchSize(3)
|
||||
.withMaxIterationTime(40)
|
||||
.withThrowableConsumer(Throwable::printStackTrace)
|
||||
.withFinalAction(getCompleteTask())
|
||||
.withConsumer(consumer)
|
||||
.unloadAfter(isUnloadAfter())
|
||||
.withProgressSubscribers(getProgressSubscribers())
|
||||
.build();
|
||||
return super.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
private void setWorldBlock(int x, int y, int z, @NonNull BaseBlock block, @NonNull BlockVector2 blockVector2) {
|
||||
try {
|
||||
BlockVector3 loc = BlockVector3.at(x, y, z);
|
||||
boolean lighting = false;
|
||||
@ -211,7 +231,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
|
||||
break;
|
||||
case REPLACEMENT:
|
||||
lighting = block.getBlockType().getMaterial().getLightValue() > 0
|
||||
|| getWorld().getBlock(loc).getBlockType().getMaterial().getLightValue() > 0;
|
||||
|| getWorld().getBlock(loc).getBlockType().getMaterial().getLightValue() > 0;
|
||||
break;
|
||||
default:
|
||||
// Can only be "all"
|
||||
|
@ -45,8 +45,9 @@ 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.Nullable;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GenChunk extends ScopedQueueCoordinator {
|
||||
@ -65,7 +66,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
this.biomes = Biome.values();
|
||||
}
|
||||
|
||||
@Nullable public ChunkData getChunkData() {
|
||||
public @Nullable ChunkData getChunkData() {
|
||||
return this.chunkData;
|
||||
}
|
||||
|
||||
@ -74,11 +75,11 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
*
|
||||
* @param chunkData Bukkit ChunkData
|
||||
*/
|
||||
public void setChunkData(@Nonnull ChunkData chunkData) {
|
||||
public void setChunkData(@NonNull ChunkData chunkData) {
|
||||
this.chunkData = chunkData;
|
||||
}
|
||||
|
||||
@Nonnull public Chunk getChunk() {
|
||||
public @NonNull Chunk getChunk() {
|
||||
if (chunk == null) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
if (worldObj != null) {
|
||||
@ -93,7 +94,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
*
|
||||
* @param chunk Bukkit Chunk
|
||||
*/
|
||||
public void setChunk(@Nonnull Chunk chunk) {
|
||||
public void setChunk(@NonNull Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@ -103,14 +104,15 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
*
|
||||
* @param wrap P2 ChunkWrapper
|
||||
*/
|
||||
public void setChunk(@Nonnull ChunkWrapper wrap) {
|
||||
public void setChunk(@NonNull ChunkWrapper wrap) {
|
||||
chunk = null;
|
||||
world = wrap.world;
|
||||
chunkX = wrap.x;
|
||||
chunkZ = wrap.z;
|
||||
}
|
||||
|
||||
@Override public void fillBiome(@Nonnull BiomeType biomeType) {
|
||||
@Override
|
||||
public void fillBiome(@NonNull BiomeType biomeType) {
|
||||
if (biomeGrid == null) {
|
||||
return;
|
||||
}
|
||||
@ -124,7 +126,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void setCuboid(@Nonnull Location pos1, @Nonnull Location pos2, @Nonnull BlockState block) {
|
||||
@Override
|
||||
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;
|
||||
@ -146,20 +149,20 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
chunkData.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, BukkitAdapter.adapt(block));
|
||||
}
|
||||
|
||||
@Override public boolean setBiome(int x, int z, @Nonnull BiomeType biomeType) {
|
||||
@Override
|
||||
public boolean setBiome(int x, int z, @NonNull BiomeType biomeType) {
|
||||
return setBiome(x, z, BukkitAdapter.adapt(biomeType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the in the whole column of XZ
|
||||
*
|
||||
* @param x Relative x location within the chunk (0 - 15)
|
||||
* @param z Relative z location within the chunk (0 - 15)
|
||||
* @param x Relative x location within the chunk (0 - 15)
|
||||
* @param z Relative z location within the chunk (0 - 15)
|
||||
* @param biome Bukkit biome to set
|
||||
*
|
||||
* @return if successful
|
||||
*/
|
||||
public boolean setBiome(int x, int z, @Nonnull Biome biome) {
|
||||
public boolean setBiome(int x, int z, @NonNull Biome biome) {
|
||||
if (this.biomeGrid != null) {
|
||||
for (int y = 0; y < 256; y++) {
|
||||
this.setBiome(x, y, z, biome);
|
||||
@ -169,7 +172,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean setBiome(int x, int y, int z, @Nonnull Biome biome) {
|
||||
public boolean setBiome(int x, int y, int z, @NonNull Biome biome) {
|
||||
if (this.biomeGrid != null) {
|
||||
this.biomeGrid.setBiome(x, y, z, biome);
|
||||
return true;
|
||||
@ -177,11 +180,13 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull Pattern pattern) {
|
||||
@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 BlockState id) {
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, @NonNull BlockState id) {
|
||||
if (this.result == null) {
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
return true;
|
||||
@ -191,7 +196,7 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void storeCache(final int x, final int y, final int z, @Nonnull final BlockState id) {
|
||||
private void storeCache(final int x, final int y, final int z, final @NonNull BlockState id) {
|
||||
int i = y >> 4;
|
||||
BlockState[] v = this.result[i];
|
||||
if (v == null) {
|
||||
@ -201,7 +206,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
v[j] = id;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, @Nonnull BaseBlock id) {
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, @NonNull BaseBlock id) {
|
||||
if (this.result == null) {
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
return true;
|
||||
@ -211,7 +217,8 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override @Nullable public BlockState getBlock(int x, int y, int z) {
|
||||
@Override
|
||||
public @Nullable BlockState getBlock(int x, int y, int z) {
|
||||
int i = y >> 4;
|
||||
if (result == null) {
|
||||
return BukkitBlockUtil.get(chunkData.getType(x, y, z));
|
||||
@ -232,19 +239,22 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
return chunk == null ? chunkZ : chunk.getZ();
|
||||
}
|
||||
|
||||
@Override @Nonnull public com.sk89q.worldedit.world.World getWorld() {
|
||||
@Override
|
||||
public com.sk89q.worldedit.world.@NonNull World getWorld() {
|
||||
return chunk == null ? BukkitAdapter.adapt(Bukkit.getWorld(world)) : BukkitAdapter.adapt(chunk.getWorld());
|
||||
}
|
||||
|
||||
@Override @Nonnull public Location getMax() {
|
||||
@Override
|
||||
public @NonNull Location getMax() {
|
||||
return Location.at(getWorld().getName(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||
}
|
||||
|
||||
@Override @Nonnull public Location getMin() {
|
||||
@Override
|
||||
public @NonNull Location getMin() {
|
||||
return Location.at(getWorld().getName(), getX() << 4, 0, getZ() << 4);
|
||||
}
|
||||
|
||||
@Nonnull public GenChunk clone() {
|
||||
public @NonNull GenChunk clone() {
|
||||
GenChunk toReturn = new GenChunk();
|
||||
if (this.result != null) {
|
||||
for (int i = 0; i < this.result.length; i++) {
|
||||
@ -258,4 +268,5 @@ public class GenChunk extends ScopedQueueCoordinator {
|
||||
toReturn.chunkData = this.chunkData;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user