mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Annotations
This commit is contained in:
parent
37b5575484
commit
7cf5821341
@ -167,8 +167,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
*
|
||||
* @param chunkX the chunk X
|
||||
* @param chunkZ the chunk Z
|
||||
* @return a {@link CompletableFuture} completed once the chunk has been loaded
|
||||
*/
|
||||
public abstract CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ);
|
||||
public abstract @NotNull CompletableFuture<@NotNull Chunk> loadChunk(int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* Loads the chunk if the chunk is already loaded or if
|
||||
@ -176,9 +177,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
*
|
||||
* @param chunkX the chunk X
|
||||
* @param chunkZ the chunk Z
|
||||
* @return a {@link CompletableFuture} completed once the chunk has been processed
|
||||
* @return a {@link CompletableFuture} completed once the chunk has been processed, can be null if not loaded
|
||||
*/
|
||||
public abstract @NotNull CompletableFuture<Chunk> loadOptionalChunk(int chunkX, int chunkZ);
|
||||
public abstract @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* Schedules the removal of a {@link Chunk}, this method does not promise when it will be done.
|
||||
@ -200,30 +201,29 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
* @param chunkZ the chunk Z
|
||||
* @return the chunk at the specified position, null if not loaded
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Chunk getChunk(int chunkX, int chunkZ);
|
||||
public abstract @Nullable Chunk getChunk(int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* Saves a {@link Chunk} to permanent storage.
|
||||
*
|
||||
* @param chunk the {@link Chunk} to save
|
||||
* @return future called when the chunk is done saving
|
||||
*/
|
||||
public abstract CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk);
|
||||
public abstract @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk);
|
||||
|
||||
/**
|
||||
* Saves multiple chunks to permanent storage.
|
||||
*
|
||||
* @param callback optional callback called when the chunks are done saving
|
||||
* @return future called when the chunks are done saving
|
||||
*/
|
||||
public abstract CompletableFuture<Void> saveChunksToStorage();
|
||||
public abstract @NotNull CompletableFuture<Void> saveChunksToStorage();
|
||||
|
||||
/**
|
||||
* Gets the instance {@link ChunkGenerator}.
|
||||
*
|
||||
* @return the {@link ChunkGenerator} of the instance
|
||||
*/
|
||||
@Nullable
|
||||
public abstract ChunkGenerator getChunkGenerator();
|
||||
public abstract @Nullable ChunkGenerator getChunkGenerator();
|
||||
|
||||
/**
|
||||
* Changes the instance {@link ChunkGenerator}.
|
||||
@ -237,8 +237,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
*
|
||||
* @return an unmodifiable containing all the instance chunks
|
||||
*/
|
||||
@NotNull
|
||||
public abstract Collection<Chunk> getChunks();
|
||||
public abstract @NotNull Collection<@NotNull Chunk> getChunks();
|
||||
|
||||
/**
|
||||
* Gets the instance {@link StorageLocation}.
|
||||
@ -489,9 +488,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
/**
|
||||
* Loads the chunk at the given {@link Point} with a callback.
|
||||
*
|
||||
* @param point the chunk position
|
||||
* @param point the chunk position
|
||||
*/
|
||||
public CompletableFuture<Chunk> loadChunk(@NotNull Point point) {
|
||||
public @NotNull CompletableFuture<@NotNull Chunk> loadChunk(@NotNull Point point) {
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate(point.x());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate(point.z());
|
||||
return loadChunk(chunkX, chunkZ);
|
||||
@ -502,9 +501,9 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
* at the given {@link Point} with a callback.
|
||||
*
|
||||
* @param point the chunk position
|
||||
* @return a {@link CompletableFuture} completed once the chunk has been processed
|
||||
* @return a {@link CompletableFuture} completed once the chunk has been processed, null if not loaded
|
||||
*/
|
||||
public @NotNull CompletableFuture<Chunk> loadOptionalChunk(@NotNull Point point) {
|
||||
public @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(@NotNull Point point) {
|
||||
final int chunkX = ChunkUtils.getChunkCoordinate(point.x());
|
||||
final int chunkZ = ChunkUtils.getChunkCoordinate(point.z());
|
||||
return loadOptionalChunk(chunkX, chunkZ);
|
||||
|
@ -238,7 +238,7 @@ public class InstanceContainer extends Instance {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) {
|
||||
public @NotNull CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) {
|
||||
final Chunk chunk = getChunk(chunkX, chunkZ);
|
||||
if (chunk != null) {
|
||||
// Chunk already loaded
|
||||
@ -306,17 +306,17 @@ public class InstanceContainer extends Instance {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) {
|
||||
public @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) {
|
||||
return chunkLoader.saveChunk(chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> saveChunksToStorage() {
|
||||
public @NotNull CompletableFuture<Void> saveChunksToStorage() {
|
||||
Collection<Chunk> chunksCollection = chunks.values();
|
||||
return chunkLoader.saveChunks(chunksCollection);
|
||||
}
|
||||
|
||||
protected CompletableFuture<Chunk> retrieveChunk(int chunkX, int chunkZ) {
|
||||
protected @NotNull CompletableFuture<@NotNull Chunk> retrieveChunk(int chunkX, int chunkZ) {
|
||||
CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
|
||||
final Runnable loader = () -> chunkLoader.loadChunk(this, chunkX, chunkZ)
|
||||
.whenComplete((chunk, throwable) -> {
|
||||
@ -331,8 +331,7 @@ public class InstanceContainer extends Instance {
|
||||
});
|
||||
} else {
|
||||
// Not present
|
||||
createChunk(chunkX, chunkZ).whenComplete((c, t) ->
|
||||
completableFuture.complete(c));
|
||||
createChunk(chunkX, chunkZ).thenAccept(completableFuture::complete);
|
||||
}
|
||||
});
|
||||
if (chunkLoader.supportsParallelLoading()) {
|
||||
@ -344,7 +343,7 @@ public class InstanceContainer extends Instance {
|
||||
return completableFuture;
|
||||
}
|
||||
|
||||
protected CompletableFuture<Chunk> createChunk(int chunkX, int chunkZ) {
|
||||
protected @NotNull CompletableFuture<@NotNull Chunk> createChunk(int chunkX, int chunkZ) {
|
||||
Biome[] biomes = new Biome[Biome.getBiomeCount(getDimensionType())];
|
||||
if (chunkGenerator == null) {
|
||||
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
|
||||
@ -365,13 +364,12 @@ public class InstanceContainer extends Instance {
|
||||
if (chunkGenerator != null && chunk.shouldGenerate()) {
|
||||
// Execute the chunk generator to populate the chunk
|
||||
final ChunkGenerationBatch chunkBatch = new ChunkGenerationBatch(this, chunk);
|
||||
|
||||
return chunkBatch.generate(chunkGenerator)
|
||||
.whenComplete((c, t) -> chunkRegisterCallback.accept(c));
|
||||
} else {
|
||||
// No chunk generator, execute the callback with the empty chunk
|
||||
return CompletableFuture.completedFuture(chunk)
|
||||
.whenComplete((c, t) -> chunkRegisterCallback.accept(c));
|
||||
chunkRegisterCallback.accept(chunk);
|
||||
return CompletableFuture.completedFuture(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class SharedInstance extends Instance {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) {
|
||||
public @NotNull CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ) {
|
||||
return instanceContainer.loadChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@ -63,12 +63,12 @@ public class SharedInstance extends Instance {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) {
|
||||
public @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull Chunk chunk) {
|
||||
return instanceContainer.saveChunkToStorage(chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> saveChunksToStorage() {
|
||||
public @NotNull CompletableFuture<Void> saveChunksToStorage() {
|
||||
return instanceContainer.saveChunksToStorage();
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class ChunkGenerationBatch extends ChunkBatch {
|
||||
chunk.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
public CompletableFuture<Chunk> generate(@NotNull ChunkGenerator chunkGenerator) {
|
||||
public @NotNull CompletableFuture<@NotNull Chunk> generate(@NotNull ChunkGenerator chunkGenerator) {
|
||||
final CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
|
||||
BLOCK_BATCH_POOL.execute(() -> {
|
||||
synchronized (chunk) {
|
||||
|
@ -31,8 +31,8 @@ public final class ChunkUtils {
|
||||
* @param eachCallback the optional callback when a chunk get loaded
|
||||
* @return a {@link CompletableFuture} completed once all chunks have been processed
|
||||
*/
|
||||
public static CompletableFuture<Chunk> optionalLoadAll(@NotNull Instance instance, long @NotNull [] chunks,
|
||||
@Nullable ChunkCallback eachCallback) {
|
||||
public static @NotNull CompletableFuture<@Nullable Chunk> optionalLoadAll(@NotNull Instance instance, long @NotNull [] chunks,
|
||||
@Nullable ChunkCallback eachCallback) {
|
||||
CompletableFuture<Chunk> completableFuture = new CompletableFuture<>();
|
||||
final int length = chunks.length;
|
||||
AtomicInteger counter = new AtomicInteger(0);
|
||||
|
Loading…
Reference in New Issue
Block a user