mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-11 09:51:35 +01:00
chore: enforce and document notnull chunk loader, add noop impl
This commit is contained in:
parent
afae77a41c
commit
1903e8dff2
@ -19,6 +19,10 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
*/
|
||||
public interface IChunkLoader {
|
||||
|
||||
static @NotNull IChunkLoader noop() {
|
||||
return NoopChunkLoaderImpl.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads instance data from the loader.
|
||||
*
|
||||
|
@ -269,9 +269,7 @@ public class InstanceContainer extends Instance {
|
||||
// Clear cache
|
||||
this.chunks.remove(getChunkIndex(chunkX, chunkZ));
|
||||
chunk.unload();
|
||||
if (chunkLoader != null) {
|
||||
chunkLoader.unloadChunk(chunk);
|
||||
}
|
||||
chunkLoader.unloadChunk(chunk);
|
||||
var dispatcher = MinecraftServer.process().dispatcher();
|
||||
dispatcher.deletePartition(chunk);
|
||||
}
|
||||
@ -588,17 +586,19 @@ public class InstanceContainer extends Instance {
|
||||
*
|
||||
* @return the {@link IChunkLoader} of this instance
|
||||
*/
|
||||
public IChunkLoader getChunkLoader() {
|
||||
public @NotNull IChunkLoader getChunkLoader() {
|
||||
return chunkLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the {@link IChunkLoader} of this instance (to change how chunks are retrieved when not already loaded).
|
||||
*
|
||||
* <p>{@link IChunkLoader#noop()} can be used to do nothing.</p>
|
||||
*
|
||||
* @param chunkLoader the new {@link IChunkLoader}
|
||||
*/
|
||||
public void setChunkLoader(IChunkLoader chunkLoader) {
|
||||
this.chunkLoader = chunkLoader;
|
||||
public void setChunkLoader(@NotNull IChunkLoader chunkLoader) {
|
||||
this.chunkLoader = Objects.requireNonNull(chunkLoader, "Chunk loader cannot be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,23 @@
|
||||
package net.minestom.server.instance;
|
||||
|
||||
import net.minestom.server.utils.async.AsyncUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
final class NoopChunkLoaderImpl implements IChunkLoader {
|
||||
static final NoopChunkLoaderImpl INSTANCE = new NoopChunkLoaderImpl();
|
||||
|
||||
private NoopChunkLoaderImpl(){}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<@Nullable Chunk> loadChunk(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Void> saveChunk(@NotNull Chunk chunk) {
|
||||
return AsyncUtils.VOID_FUTURE;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user