From 588b1f9c6d8c85f7b0f8a34c6ec3d01cea536c8d Mon Sep 17 00:00:00 2001 From: themode Date: Sun, 30 Aug 2020 21:42:21 +0200 Subject: [PATCH] A few comments --- .../minestom/server/instance/Instance.java | 6 +++++ .../server/instance/InstanceContainer.java | 25 ++++++++++++------- .../minestom/server/reader/ChunkReader.java | 11 ++++++++ .../storage/systems/FileStorageSystem.java | 5 ++-- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index 2f5f5a3c5..ebe0bffbc 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -80,6 +80,12 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta // Pathfinder private final PFInstanceSpace instanceSpace = new PFInstanceSpace(this); + /** + * Create a new instance + * + * @param uniqueId the unique id of the instance + * @param dimensionType the dimension type of the instance + */ public Instance(UUID uniqueId, DimensionType dimensionType) { this.uniqueId = uniqueId; this.dimensionType = dimensionType; diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index 5f5707d89..ea072395f 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -66,21 +66,28 @@ public class InstanceContainer extends Instance { @Setter private BiFunction chunkDecider; + /** + * Create an {@link InstanceContainer} + * + * @param uniqueId the unique id of the instance + * @param dimensionType the dimension type of the instance + * @param storageFolder the {@link StorageFolder} of the instance, + * can be null if you do not wish to save the instance latter on + */ public InstanceContainer(UUID uniqueId, DimensionType dimensionType, StorageFolder storageFolder) { super(uniqueId, dimensionType); this.storageFolder = storageFolder; - chunkLoader = new MinestomBasicChunkLoader(storageFolder); + this.chunkLoader = new MinestomBasicChunkLoader(storageFolder); - if (storageFolder == null) { - return; + // Get instance data from the saved data if a StorageFolder is defined + if (storageFolder != null) { + // Retrieve instance data + this.uniqueId = storageFolder.getOrDefault(UUID_KEY, UUID.class, uniqueId); + + final Data data = storageFolder.getOrDefault(DATA_KEY, SerializableData.class, null); + setData(data); } - - // Retrieve instance data - this.uniqueId = storageFolder.getOrDefault(UUID_KEY, UUID.class, uniqueId); - - final Data data = storageFolder.getOrDefault(DATA_KEY, SerializableData.class, null); - setData(data); } @Override diff --git a/src/main/java/net/minestom/server/reader/ChunkReader.java b/src/main/java/net/minestom/server/reader/ChunkReader.java index 9686e7867..8f5d3fb3a 100644 --- a/src/main/java/net/minestom/server/reader/ChunkReader.java +++ b/src/main/java/net/minestom/server/reader/ChunkReader.java @@ -17,6 +17,15 @@ public class ChunkReader { private static final BiomeManager BIOME_MANAGER = MinecraftServer.getBiomeManager(); + /** + * Read a chunk from a byte array, the array should contain the whole chunk and only it + * + * @param b the byte array containing the chunk + * @param instance the instance of the chunk + * @param chunkX the chunk X + * @param chunkZ the chunk Z + * @param callback the consumer called once the chunk has been read + */ public static void readChunk(byte[] b, Instance instance, int chunkX, int chunkZ, Consumer callback) { BinaryReader binaryReader = new BinaryReader(b); @@ -26,8 +35,10 @@ public class ChunkReader { ChunkBatch chunkBatch = null; try { + // Get if the chunk has data indexes (used for blocks data) final boolean hasIndex = binaryReader.readBoolean(); if (hasIndex) { + // Get the data indexes which will be used to read all the individual data typeToIndexMap = DataReader.readDataIndexes(binaryReader); } diff --git a/src/main/java/net/minestom/server/storage/systems/FileStorageSystem.java b/src/main/java/net/minestom/server/storage/systems/FileStorageSystem.java index 5c24a99b4..71fba3d8b 100644 --- a/src/main/java/net/minestom/server/storage/systems/FileStorageSystem.java +++ b/src/main/java/net/minestom/server/storage/systems/FileStorageSystem.java @@ -4,7 +4,8 @@ import net.minestom.server.storage.StorageOptions; import net.minestom.server.storage.StorageSystem; import org.rocksdb.*; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; /** * A storage system which is local using OS files system @@ -20,7 +21,7 @@ public class FileStorageSystem implements StorageSystem { @Override public boolean exists(String folderPath) { - return new File(folderPath).exists(); + return Files.isDirectory(Paths.get(folderPath)); } @Override