diff --git a/src/main/java/net/minestom/server/entity/EntityManager.java b/src/main/java/net/minestom/server/entity/EntityManager.java
index 87cf67a58..7b3c3dedf 100644
--- a/src/main/java/net/minestom/server/entity/EntityManager.java
+++ b/src/main/java/net/minestom/server/entity/EntityManager.java
@@ -36,10 +36,7 @@ public final class EntityManager {
Check.notNull(spawningInstance, "You need to specify a spawning instance in the PlayerLoginEvent");
- {
- final Player finalWaitingPlayer = waitingPlayer;
- spawningInstance.scheduleNextTick(instance -> finalWaitingPlayer.setInstance(instance));
- }
+ spawningInstance.scheduleNextTick(waitingPlayer::setInstance);
}
}
diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java
index 2e58b0e37..e9a7e0587 100644
--- a/src/main/java/net/minestom/server/entity/Player.java
+++ b/src/main/java/net/minestom/server/entity/Player.java
@@ -62,7 +62,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
/**
- * Those are the major actors of the server, they are not necessary backed by a {@link NettyPlayerConnection} as shown by {@link FakePlayer}
+ * Those are the major actors of the server,
+ * they are not necessary backed by a {@link NettyPlayerConnection} as shown by {@link FakePlayer}
*
* You can easily create your own implementation of this and use it with {@link ConnectionManager#setPlayerProvider(PlayerProvider)}.
*/
@@ -1945,7 +1946,7 @@ public class Player extends LivingEntity implements CommandSender {
// Get if multi player breaking is enabled
final boolean multiPlayerBreaking = targetCustomBlock.enableMultiPlayerBreaking();
- // Get the stage from the custom block object if it is, otherwise use the local fieldl
+ // Get the stage from the custom block object if it is, otherwise use the local field
final byte stage = multiPlayerBreaking ? targetCustomBlock.getBreakStage(instance, targetBlockPosition) : targetStage;
// Retrieve the break delay for the current stage
this.targetBreakDelay = targetCustomBlock.getBreakDelay(this, targetBlockPosition, stage, breakers);
diff --git a/src/main/java/net/minestom/server/entity/PlayerSkin.java b/src/main/java/net/minestom/server/entity/PlayerSkin.java
index efdf4414e..418664a15 100644
--- a/src/main/java/net/minestom/server/entity/PlayerSkin.java
+++ b/src/main/java/net/minestom/server/entity/PlayerSkin.java
@@ -9,7 +9,10 @@ import net.minestom.server.utils.url.URLUtils;
import java.io.IOException;
/**
- * Contains all the data required to store a skin
+ * Contains all the data required to store a skin.
+ *
+ * Can be applied to a player with {@link Player#setSkin(PlayerSkin)}
+ * or in the linked event {@link net.minestom.server.event.player.PlayerSkinInitEvent}.
*/
public class PlayerSkin {
@@ -22,7 +25,7 @@ public class PlayerSkin {
}
/**
- * Get the skin textures value
+ * Get the skin textures value.
*
* @return the textures value
*/
@@ -31,7 +34,7 @@ public class PlayerSkin {
}
/**
- * Get the skin signature
+ * Get the skin signature.
*
* @return the skin signature
*/
@@ -40,7 +43,7 @@ public class PlayerSkin {
}
/**
- * Get a skin from a Mojang UUID
+ * Get a skin from a Mojang UUID.
*
* @param uuid Mojang UUID
* @return a player skin based on the UUID, null if not found
@@ -70,7 +73,7 @@ public class PlayerSkin {
}
/**
- * Get a skin from a Minecraft username
+ * Get a skin from a Minecraft username.
*
* @param username the Minecraft username
* @return a skin based on a Minecraft username, null if not found
diff --git a/src/main/java/net/minestom/server/instance/Chunk.java b/src/main/java/net/minestom/server/instance/Chunk.java
index 2d2dfe970..9c5a06b85 100644
--- a/src/main/java/net/minestom/server/instance/Chunk.java
+++ b/src/main/java/net/minestom/server/instance/Chunk.java
@@ -62,7 +62,7 @@ public abstract class Chunk implements Viewable, DataContainer {
protected int chunkX, chunkZ;
// Options
- private boolean shouldGenerate;
+ private final boolean shouldGenerate;
// Packet cache
private volatile boolean enableCachePacket;
diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java
index b3a816155..1a4bd275e 100644
--- a/src/main/java/net/minestom/server/instance/InstanceContainer.java
+++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java
@@ -50,7 +50,7 @@ public class InstanceContainer extends Instance {
private StorageLocation storageLocation;
// the shared instances assigned to this instance
- private List sharedInstances = new CopyOnWriteArrayList<>();
+ private final List sharedInstances = new CopyOnWriteArrayList<>();
// the chunk generator used, can be null
private ChunkGenerator chunkGenerator;
@@ -59,8 +59,8 @@ public class InstanceContainer extends Instance {
// contains all the chunks to remove during the next instance tick
protected final Set scheduledChunksToRemove = new HashSet<>();
- private ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
- private Map currentlyChangingBlocks = new HashMap<>();
+ private final ReadWriteLock changingBlockLock = new ReentrantReadWriteLock();
+ private final Map currentlyChangingBlocks = new HashMap<>();
// the chunk loader, used when trying to load/save a chunk from another source
private IChunkLoader chunkLoader;
@@ -85,7 +85,7 @@ public class InstanceContainer extends Instance {
this.storageLocation = storageLocation;
// Set the default chunk supplier using DynamicChunk
- setChunkSupplier((instance, biomes, chunkX, chunkZ) -> new DynamicChunk(instance, biomes, chunkX, chunkZ));
+ setChunkSupplier(DynamicChunk::new);
// Set the default chunk loader which use the instance's StorageLocation and ChunkSupplier to save and load chunks
setChunkLoader(new MinestomBasicChunkLoader(this));
@@ -136,11 +136,9 @@ public class InstanceContainer extends Instance {
UNSAFE_setBlock(chunk, x, y, z, blockStateId, customBlock, data);
} else {
if (hasEnabledAutoChunkLoad()) {
- final int chunkX = ChunkUtils.getChunkCoordinate((int) x);
- final int chunkZ = ChunkUtils.getChunkCoordinate((int) z);
- loadChunk(chunkX, chunkZ, c -> {
- UNSAFE_setBlock(c, x, y, z, blockStateId, customBlock, data);
- });
+ final int chunkX = ChunkUtils.getChunkCoordinate(x);
+ final int chunkZ = ChunkUtils.getChunkCoordinate(z);
+ loadChunk(chunkX, chunkZ, c -> UNSAFE_setBlock(c, x, y, z, blockStateId, customBlock, data));
} else {
throw new IllegalStateException("Tried to set a block to an unloaded chunk with auto chunk load disabled");
}
@@ -371,9 +369,7 @@ public class InstanceContainer extends Instance {
ParticlePacket particlePacket = ParticleCreator.createParticlePacket(Particle.BLOCK, false,
x + 0.5f, y, z + 0.5f,
0.4f, 0.5f, 0.4f,
- 0.3f, 125, writer -> {
- writer.writeVarInt(blockStateId);
- });
+ 0.3f, 125, writer -> writer.writeVarInt(blockStateId));
chunk.getViewers().forEach(p -> {
// The player who breaks the block already get particles client-side
@@ -478,9 +474,7 @@ public class InstanceContainer extends Instance {
public void saveChunksToStorage(Runnable callback) {
if (chunkLoader.supportsParallelSaving()) {
ExecutorService parallelSavingThreadPool = new MinestomThread(MinecraftServer.THREAD_COUNT_PARALLEL_CHUNK_SAVING, MinecraftServer.THREAD_NAME_PARALLEL_CHUNK_SAVING, true);
- getChunks().forEach(c -> parallelSavingThreadPool.execute(() -> {
- saveChunkToStorage(c, null);
- }));
+ getChunks().forEach(c -> parallelSavingThreadPool.execute(() -> saveChunkToStorage(c, null)));
try {
parallelSavingThreadPool.shutdown();
parallelSavingThreadPool.awaitTermination(1L, java.util.concurrent.TimeUnit.DAYS);
diff --git a/src/main/java/net/minestom/server/instance/SharedInstance.java b/src/main/java/net/minestom/server/instance/SharedInstance.java
index c1a5b764d..b367a88fe 100644
--- a/src/main/java/net/minestom/server/instance/SharedInstance.java
+++ b/src/main/java/net/minestom/server/instance/SharedInstance.java
@@ -28,7 +28,7 @@ public class SharedInstance extends Instance {
@Override
public void refreshBlockStateId(BlockPosition blockPosition, short blockStateId) {
- instanceContainer.refreshBlockStateId(blockPosition, blockStateId);
+ this.instanceContainer.refreshBlockStateId(blockPosition, blockStateId);
}
@Override
@@ -38,12 +38,12 @@ public class SharedInstance extends Instance {
@Override
public void loadChunk(int chunkX, int chunkZ, ChunkCallback callback) {
- instanceContainer.loadChunk(chunkX, chunkZ, callback);
+ this.instanceContainer.loadChunk(chunkX, chunkZ, callback);
}
@Override
public void loadOptionalChunk(int chunkX, int chunkZ, ChunkCallback callback) {
- instanceContainer.loadOptionalChunk(chunkX, chunkZ, callback);
+ this.instanceContainer.loadOptionalChunk(chunkX, chunkZ, callback);
}
@Override
@@ -58,7 +58,7 @@ public class SharedInstance extends Instance {
@Override
public void saveChunkToStorage(Chunk chunk, Runnable callback) {
- instanceContainer.saveChunkToStorage(chunk, callback);
+ this.instanceContainer.saveChunkToStorage(chunk, callback);
}
@Override
@@ -78,7 +78,7 @@ public class SharedInstance extends Instance {
@Override
public void setChunkGenerator(ChunkGenerator chunkGenerator) {
- instanceContainer.setChunkGenerator(chunkGenerator);
+ this.instanceContainer.setChunkGenerator(chunkGenerator);
}
@Override
@@ -98,17 +98,17 @@ public class SharedInstance extends Instance {
@Override
public void setStorageLocation(StorageLocation storageLocation) {
- instanceContainer.setStorageLocation(storageLocation);
+ this.instanceContainer.setStorageLocation(storageLocation);
}
@Override
public void retrieveChunk(int chunkX, int chunkZ, ChunkCallback callback) {
- instanceContainer.retrieveChunk(chunkX, chunkZ, callback);
+ this.instanceContainer.retrieveChunk(chunkX, chunkZ, callback);
}
@Override
protected void createChunk(int chunkX, int chunkZ, ChunkCallback callback) {
- instanceContainer.createChunk(chunkX, chunkZ, callback);
+ this.instanceContainer.createChunk(chunkX, chunkZ, callback);
}
@Override
@@ -128,22 +128,22 @@ public class SharedInstance extends Instance {
@Override
public void setBlockStateId(int x, int y, int z, short blockStateId, Data data) {
- instanceContainer.setBlockStateId(x, y, z, blockStateId, data);
+ this.instanceContainer.setBlockStateId(x, y, z, blockStateId, data);
}
@Override
public void setCustomBlock(int x, int y, int z, short customBlockId, Data data) {
- instanceContainer.setCustomBlock(x, y, z, customBlockId, data);
+ this.instanceContainer.setCustomBlock(x, y, z, customBlockId, data);
}
@Override
public void setSeparateBlocks(int x, int y, int z, short blockStateId, short customBlockId, Data data) {
- instanceContainer.setSeparateBlocks(x, y, z, blockStateId, customBlockId, data);
+ this.instanceContainer.setSeparateBlocks(x, y, z, blockStateId, customBlockId, data);
}
@Override
public void scheduleUpdate(int time, TimeUnit unit, BlockPosition position) {
- instanceContainer.scheduleUpdate(time, unit, position);
+ this.instanceContainer.scheduleUpdate(time, unit, position);
}
/**
diff --git a/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java b/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java
index fb0944f07..df2987bf9 100644
--- a/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java
+++ b/src/main/java/net/minestom/server/instance/batch/ChunkBatch.java
@@ -86,7 +86,7 @@ public class ChunkBatch implements InstanceBatch {
/**
* Execute the batch in the dedicated pool and run the callback during the next instance update when blocks are placed
- * (which means that the callback can be called 50ms after, and in a determinable thread)
+ * (which means that the callback can be called 50ms after, but in a determinable thread)
*
* @param callback the callback to execute once the blocks are placed
*/
diff --git a/src/main/java/net/minestom/server/inventory/EquipmentHandler.java b/src/main/java/net/minestom/server/inventory/EquipmentHandler.java
index 9f9b0434b..9372b970d 100644
--- a/src/main/java/net/minestom/server/inventory/EquipmentHandler.java
+++ b/src/main/java/net/minestom/server/inventory/EquipmentHandler.java
@@ -6,45 +6,46 @@ import net.minestom.server.entity.Player;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
import net.minestom.server.network.player.PlayerConnection;
+import net.minestom.server.utils.validate.Check;
import java.util.ArrayList;
import java.util.List;
/**
- * Represent an {@link Entity} which can have {@link ItemStack} in hands and armor slots
+ * Represents an {@link Entity} which can have {@link ItemStack} in hands and armor slots
*/
public interface EquipmentHandler {
/**
- * Get the {@link ItemStack} in main hand
+ * Get the {@link ItemStack} in main hand.
*
* @return the {@link ItemStack} in main hand
*/
ItemStack getItemInMainHand();
/**
- * Change the main hand {@link ItemStack}
+ * Change the main hand {@link ItemStack}.
*
* @param itemStack the main hand {@link ItemStack}
*/
void setItemInMainHand(ItemStack itemStack);
/**
- * Get the {@link ItemStack} in off hand
+ * Get the {@link ItemStack} in off hand.
*
* @return the item in off hand
*/
ItemStack getItemInOffHand();
/**
- * Change the off hand {@link ItemStack}
+ * Change the off hand {@link ItemStack}.
*
* @param itemStack the off hand {@link ItemStack}
*/
void setItemInOffHand(ItemStack itemStack);
/**
- * Get the {@link ItemStack} in the specific hand
+ * Get the {@link ItemStack} in the specific hand.
*
* @param hand the Hand to get the {@link ItemStack} from
* @return the {@link ItemStack} in {@code hand}
@@ -63,7 +64,7 @@ public interface EquipmentHandler {
}
/**
- * Change the {@link ItemStack} in the specific hand
+ * Change the {@link ItemStack} in the specific hand.
*
* @param hand the hand to set the item to
* @param stack the {@link ItemStack} to set
@@ -81,63 +82,63 @@ public interface EquipmentHandler {
}
/**
- * Get the helmet
+ * Get the helmet.
*
* @return the helmet
*/
ItemStack getHelmet();
/**
- * Change the helmet
+ * Change the helmet.
*
* @param itemStack the helmet
*/
void setHelmet(ItemStack itemStack);
/**
- * Get the chestplate
+ * Get the chestplate.
*
* @return the chestplate
*/
ItemStack getChestplate();
/**
- * Change the chestplate
+ * Change the chestplate.
*
* @param itemStack the chestplate
*/
void setChestplate(ItemStack itemStack);
/**
- * Get the leggings
+ * Get the leggings.
*
* @return the leggings
*/
ItemStack getLeggings();
/**
- * Change the leggings
+ * Change the leggings.
*
* @param itemStack the leggings
*/
void setLeggings(ItemStack itemStack);
/**
- * Get the boots
+ * Get the boots.
*
* @return the boots
*/
ItemStack getBoots();
/**
- * Change the boots
+ * Change the boots.
*
* @param itemStack the boots
*/
void setBoots(ItemStack itemStack);
/**
- * Get the equipment in a specific slot
+ * Get the equipment in a specific slot.
*
* @param slot the equipment to get the item from
* @return the equipment {@link ItemStack}
@@ -162,7 +163,7 @@ public interface EquipmentHandler {
}
/**
- * Send all the equipments to a {@link PlayerConnection}
+ * Send all the equipments to a {@link PlayerConnection}.
*
* @param connection the connection to send the equipments to
*/
@@ -174,7 +175,7 @@ public interface EquipmentHandler {
}
/**
- * Send all the equipments to all viewers
+ * Send all the equipments to all viewers.
*/
default void syncEquipments() {
if (!(this instanceof Viewable))
@@ -190,7 +191,7 @@ public interface EquipmentHandler {
}
/**
- * Send a specific equipment to viewers
+ * Send a specific equipment to viewers.
*
* @param slot the slot of the equipment
*/
@@ -212,13 +213,13 @@ public interface EquipmentHandler {
}
/**
- * Get the packet with all the equipments
+ * Get the packet with all the equipments.
*
* @return the packet with the equipments
+ * @throws IllegalStateException if 'this' is not an {@link Entity}
*/
default EntityEquipmentPacket getEquipmentsPacket() {
- if (!(this instanceof Entity))
- throw new IllegalStateException("Only accessible for Entity");
+ Check.stateCondition(!(this instanceof Entity), "Only accessible for Entity");
Entity entity = (Entity) this;