From c4f36a9cea0d3d8c4ecdf283445250aa71a710bb Mon Sep 17 00:00:00 2001 From: themode Date: Sat, 31 Oct 2020 05:09:30 +0100 Subject: [PATCH] Cleanup + comments --- .../java/net/minestom/server/Viewable.java | 20 +++++++++---------- .../server/collision/BoundingBox.java | 19 +++++++++++++----- .../server/entity/ai/GoalSelector.java | 8 +++++--- .../server/entity/ai/TargetSelector.java | 6 +++++- .../entity/ai/goal/FollowTargetGoal.java | 3 ++- .../entity/ai/goal/MeleeAttackGoal.java | 10 ++++++++-- .../entity/ai/goal/RandomStrollGoal.java | 4 +++- .../ai/target/LastEntityDamagerTarget.java | 3 ++- .../server/instance/InstanceContainer.java | 13 +++++++----- .../listener/manager/PacketConsumer.java | 14 ++++++++++++- .../listener/manager/PacketController.java | 16 +++++++++++---- .../manager/PacketListenerConsumer.java | 5 +++++ .../manager/PacketListenerManager.java | 20 +++++++++++++------ .../server/network/PacketWriterUtils.java | 8 ++++---- .../packet/client/ClientPlayPacket.java | 10 +++++++++- .../minestom/server/utils/UniqueIdUtils.java | 4 ++-- .../minestom/server/utils/WeightedRandom.java | 4 ++-- .../net/minestom/server/world/Difficulty.java | 5 +++++ 18 files changed, 123 insertions(+), 49 deletions(-) diff --git a/src/main/java/net/minestom/server/Viewable.java b/src/main/java/net/minestom/server/Viewable.java index 4477b36cf..467dd019f 100644 --- a/src/main/java/net/minestom/server/Viewable.java +++ b/src/main/java/net/minestom/server/Viewable.java @@ -38,7 +38,7 @@ public interface Viewable { Set getViewers(); /** - * Gets if a player is seeing this viewable object + * Gets if a player is seeing this viewable object. * * @param player the player to check * @return true if {@code player} is a viewer, false otherwise @@ -48,10 +48,10 @@ public interface Viewable { } /** - * Sends a packet to all viewers + * Sends a packet to all viewers. *

* It is better than looping through the viewers - * to send a packet since it is here only serialized once + * to send a packet since it is here only serialized once. * * @param packet the packet to send to all viewers */ @@ -60,10 +60,10 @@ public interface Viewable { } /** - * Sends multiple packets to all viewers + * Sends multiple packets to all viewers. *

* It is better than looping through the viewers - * to send a packet since it is here only serialized once + * to send a packet since it is here only serialized once. * * @param packets the packets to send */ @@ -74,16 +74,16 @@ public interface Viewable { } /** - * Sends a packet to all viewers and the viewable element if it is a player + * Sends a packet to all viewers and the viewable element if it is a player. *

- * If 'this' isn't a player, then {@link #sendPacketToViewers(ServerPacket)} is called instead + * If 'this' isn't a player, then {@link #sendPacketToViewers(ServerPacket)} is called instead. * * @param packet the packet to send */ default void sendPacketToViewersAndSelf(@NotNull ServerPacket packet) { if (this instanceof Player) { if (getViewers().isEmpty()) { - ((Player) this).getPlayerConnection().sendPacket(packet); + PacketWriterUtils.writeAndSend((Player) this, packet); } else { UNSAFE_sendPacketToViewersAndSelf(packet); } @@ -93,9 +93,9 @@ public interface Viewable { } /** - * Sends a packet to all the viewers and 'this' + * Sends a packet to all the viewers and 'this'. *

- * Unsafe because of a cast to {@link Player} without any check beforehand + * Unsafe because of a cast to {@link Player} without any check beforehand. * * @param packet the packet to send */ diff --git a/src/main/java/net/minestom/server/collision/BoundingBox.java b/src/main/java/net/minestom/server/collision/BoundingBox.java index a3ff36a74..ebc527cc4 100644 --- a/src/main/java/net/minestom/server/collision/BoundingBox.java +++ b/src/main/java/net/minestom/server/collision/BoundingBox.java @@ -4,6 +4,7 @@ import net.minestom.server.entity.Entity; import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.Position; import net.minestom.server.utils.Vector; +import org.jetbrains.annotations.NotNull; /** * See https://wiki.vg/Entity_metadata#Mobs_2 @@ -21,7 +22,7 @@ public class BoundingBox { * @param y the height size * @param z the depth size */ - public BoundingBox(Entity entity, float x, float y, float z) { + public BoundingBox(@NotNull Entity entity, float x, float y, float z) { this.entity = entity; this.x = x; this.y = y; @@ -34,7 +35,7 @@ public class BoundingBox { * @param boundingBox the {@link BoundingBox} to check * @return true if the two {@link BoundingBox} intersect with each other, false otherwise */ - public boolean intersect(BoundingBox boundingBox) { + public boolean intersect(@NotNull BoundingBox boundingBox) { return (getMinX() <= boundingBox.getMaxX() && getMaxX() >= boundingBox.getMinX()) && (getMinY() <= boundingBox.getMaxY() && getMaxY() >= boundingBox.getMinY()) && (getMinZ() <= boundingBox.getMaxZ() && getMaxZ() >= boundingBox.getMinZ()); @@ -46,7 +47,7 @@ public class BoundingBox { * @param entity the entity to check the bounding box * @return true if this bounding box intersects with the entity, false otherwise */ - public boolean intersect(Entity entity) { + public boolean intersect(@NotNull Entity entity) { return intersect(entity.getBoundingBox()); } @@ -56,7 +57,7 @@ public class BoundingBox { * @param blockPosition the position to check * @return true if the bounding box intersects with the position, false otherwise */ - public boolean intersect(BlockPosition blockPosition) { + public boolean intersect(@NotNull BlockPosition blockPosition) { final float offsetX = 1; final float x = blockPosition.getX(); @@ -90,7 +91,7 @@ public class BoundingBox { (z >= getMinZ() && z <= getMaxZ()); } - public boolean intersect(Position position) { + public boolean intersect(@NotNull Position position) { return intersect(position.getX(), position.getY(), position.getZ()); } @@ -102,6 +103,7 @@ public class BoundingBox { * @param z the Z offset * @return a new {@link BoundingBox} expanded */ + @NotNull public BoundingBox expand(float x, float y, float z) { return new BoundingBox(entity, this.x + x, this.y + y, this.z + z); } @@ -114,6 +116,7 @@ public class BoundingBox { * @param z the Z offset * @return a new bounding box contracted */ + @NotNull public BoundingBox contract(float x, float y, float z) { return new BoundingBox(entity, this.x - x, this.y - y, this.z - z); } @@ -204,6 +207,7 @@ public class BoundingBox { * * @return the points at the bottom of the {@link BoundingBox} */ + @NotNull public Vector[] getBottomFace() { return new Vector[]{ new Vector(getMinX(), getMinY(), getMinZ()), @@ -218,6 +222,7 @@ public class BoundingBox { * * @return the points at the top of the {@link BoundingBox} */ + @NotNull public Vector[] getTopFace() { return new Vector[]{ new Vector(getMinX(), getMaxY(), getMinZ()), @@ -232,6 +237,7 @@ public class BoundingBox { * * @return the points on the left face of the {@link BoundingBox} */ + @NotNull public Vector[] getLeftFace() { return new Vector[]{ new Vector(getMinX(), getMinY(), getMinZ()), @@ -246,6 +252,7 @@ public class BoundingBox { * * @return the points on the right face of the {@link BoundingBox} */ + @NotNull public Vector[] getRightFace() { return new Vector[]{ new Vector(getMaxX(), getMinY(), getMinZ()), @@ -260,6 +267,7 @@ public class BoundingBox { * * @return the points at the front of the {@link BoundingBox} */ + @NotNull public Vector[] getFrontFace() { return new Vector[]{ new Vector(getMinX(), getMinY(), getMinZ()), @@ -274,6 +282,7 @@ public class BoundingBox { * * @return the points at the back of the {@link BoundingBox} */ + @NotNull public Vector[] getBackFace() { return new Vector[]{ new Vector(getMinX(), getMinY(), getMaxZ()), diff --git a/src/main/java/net/minestom/server/entity/ai/GoalSelector.java b/src/main/java/net/minestom/server/entity/ai/GoalSelector.java index 1f9505129..f8728809c 100644 --- a/src/main/java/net/minestom/server/entity/ai/GoalSelector.java +++ b/src/main/java/net/minestom/server/entity/ai/GoalSelector.java @@ -2,6 +2,7 @@ package net.minestom.server.entity.ai; import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityCreature; +import org.jetbrains.annotations.Nullable; public abstract class GoalSelector { @@ -19,7 +20,7 @@ public abstract class GoalSelector { public abstract boolean shouldStart(); /** - * Start this {@link GoalSelector} + * Starts this {@link GoalSelector}. */ public abstract void start(); @@ -38,15 +39,16 @@ public abstract class GoalSelector { public abstract boolean shouldEnd(); /** - * End this {@link GoalSelector} + * Ends this {@link GoalSelector}. */ public abstract void end(); /** - * Find a target based on the entity {@link TargetSelector} + * Finds a target based on the entity {@link TargetSelector}. * * @return the target entity, null if not found */ + @Nullable public Entity findTarget() { for (TargetSelector targetSelector : entityCreature.getTargetSelectors()) { final Entity entity = targetSelector.findTarget(); diff --git a/src/main/java/net/minestom/server/entity/ai/TargetSelector.java b/src/main/java/net/minestom/server/entity/ai/TargetSelector.java index face68def..49dcacd88 100644 --- a/src/main/java/net/minestom/server/entity/ai/TargetSelector.java +++ b/src/main/java/net/minestom/server/entity/ai/TargetSelector.java @@ -2,6 +2,8 @@ package net.minestom.server.entity.ai; import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityCreature; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * The target selector is called each time the entity receives an "attack" instruction @@ -11,7 +13,7 @@ public abstract class TargetSelector { protected final EntityCreature entityCreature; - public TargetSelector(EntityCreature entityCreature) { + public TargetSelector(@NotNull EntityCreature entityCreature) { this.entityCreature = entityCreature; } @@ -23,6 +25,7 @@ public abstract class TargetSelector { * * @return the target, null if not any */ + @Nullable public abstract Entity findTarget(); /** @@ -30,6 +33,7 @@ public abstract class TargetSelector { * * @return the entity */ + @NotNull public EntityCreature getEntityCreature() { return entityCreature; } diff --git a/src/main/java/net/minestom/server/entity/ai/goal/FollowTargetGoal.java b/src/main/java/net/minestom/server/entity/ai/goal/FollowTargetGoal.java index c8ea28530..9467c0fce 100644 --- a/src/main/java/net/minestom/server/entity/ai/goal/FollowTargetGoal.java +++ b/src/main/java/net/minestom/server/entity/ai/goal/FollowTargetGoal.java @@ -4,10 +4,11 @@ import net.minestom.server.entity.Entity; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.ai.GoalSelector; import net.minestom.server.utils.Position; +import org.jetbrains.annotations.NotNull; public class FollowTargetGoal extends GoalSelector { - public FollowTargetGoal(EntityCreature entityCreature) { + public FollowTargetGoal(@NotNull EntityCreature entityCreature) { super(entityCreature); } diff --git a/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java b/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java index de4884379..30fe5f750 100644 --- a/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java +++ b/src/main/java/net/minestom/server/entity/ai/goal/MeleeAttackGoal.java @@ -7,6 +7,9 @@ import net.minestom.server.entity.ai.TargetSelector; import net.minestom.server.utils.Position; import net.minestom.server.utils.time.CooldownUtils; import net.minestom.server.utils.time.TimeUnit; +import net.minestom.server.utils.validate.Check; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Attacks the entity's target ({@link EntityCreature#getTarget()}) OR the closest entity @@ -25,7 +28,7 @@ public class MeleeAttackGoal extends GoalSelector { * @param delay the delay between each attacks * @param timeUnit the unit of the delay */ - public MeleeAttackGoal(EntityCreature entityCreature, int delay, TimeUnit timeUnit) { + public MeleeAttackGoal(@NotNull EntityCreature entityCreature, int delay, @NotNull TimeUnit timeUnit) { super(entityCreature); this.delay = delay; this.timeUnit = timeUnit; @@ -38,7 +41,9 @@ public class MeleeAttackGoal extends GoalSelector { @Override public void start() { - final Position targetPosition = getTarget().getPosition(); + final Entity target = getTarget(); + Check.notNull(target, "The target is not expected to be null!"); + final Position targetPosition = target.getPosition(); entityCreature.setPathTo(targetPosition); } @@ -85,6 +90,7 @@ public class MeleeAttackGoal extends GoalSelector { * * @return the target of the entity */ + @Nullable private Entity getTarget() { final Entity target = entityCreature.getTarget(); return target == null ? findTarget() : target; diff --git a/src/main/java/net/minestom/server/entity/ai/goal/RandomStrollGoal.java b/src/main/java/net/minestom/server/entity/ai/goal/RandomStrollGoal.java index 58bab35d0..55a7f30a6 100644 --- a/src/main/java/net/minestom/server/entity/ai/goal/RandomStrollGoal.java +++ b/src/main/java/net/minestom/server/entity/ai/goal/RandomStrollGoal.java @@ -3,6 +3,7 @@ package net.minestom.server.entity.ai.goal; import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.ai.GoalSelector; import net.minestom.server.utils.Position; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; @@ -17,7 +18,7 @@ public class RandomStrollGoal extends GoalSelector { private long lastStroll; - public RandomStrollGoal(EntityCreature entityCreature, int radius) { + public RandomStrollGoal(@NotNull EntityCreature entityCreature, int radius) { super(entityCreature); this.radius = radius; @@ -62,6 +63,7 @@ public class RandomStrollGoal extends GoalSelector { return radius; } + @NotNull private List getNearbyBlocks(int radius) { List blocks = new ArrayList<>(); for (int x = -radius; x <= radius; x++) { diff --git a/src/main/java/net/minestom/server/entity/ai/target/LastEntityDamagerTarget.java b/src/main/java/net/minestom/server/entity/ai/target/LastEntityDamagerTarget.java index ea8e11def..a58d4358b 100644 --- a/src/main/java/net/minestom/server/entity/ai/target/LastEntityDamagerTarget.java +++ b/src/main/java/net/minestom/server/entity/ai/target/LastEntityDamagerTarget.java @@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityCreature; import net.minestom.server.entity.ai.TargetSelector; import net.minestom.server.entity.damage.DamageType; import net.minestom.server.entity.damage.EntityDamage; +import org.jetbrains.annotations.NotNull; /** * Targets the last damager of this entity. @@ -13,7 +14,7 @@ public class LastEntityDamagerTarget extends TargetSelector { private final float range; - public LastEntityDamagerTarget(EntityCreature entityCreature, float range) { + public LastEntityDamagerTarget(@NotNull EntityCreature entityCreature, float range) { super(entityCreature); this.range = range; } diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index 421c1e0d0..3975b7d4a 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -73,14 +73,14 @@ public class InstanceContainer extends Instance { private ChunkSupplier chunkSupplier; /** - * Create an {@link InstanceContainer} + * Creates an {@link InstanceContainer}. * * @param uniqueId the unique id of the instance * @param dimensionType the dimension type of the instance * @param storageLocation the {@link StorageLocation} of the instance, * can be null if you do not wish to save the instance later on */ - public InstanceContainer(UUID uniqueId, DimensionType dimensionType, StorageLocation storageLocation) { + public InstanceContainer(@NotNull UUID uniqueId, @NotNull DimensionType dimensionType, @Nullable StorageLocation storageLocation) { super(uniqueId, dimensionType); this.storageLocation = storageLocation; @@ -102,7 +102,7 @@ public class InstanceContainer extends Instance { } @Override - public void setBlockStateId(int x, int y, int z, short blockStateId, Data data) { + public void setBlockStateId(int x, int y, int z, short blockStateId, @Nullable Data data) { setBlock(x, y, z, blockStateId, null, data); } @@ -114,7 +114,7 @@ public class InstanceContainer extends Instance { } @Override - public void setSeparateBlocks(int x, int y, int z, short blockStateId, short customBlockId, Data data) { + public void setSeparateBlocks(int x, int y, int z, short blockStateId, short customBlockId, @Nullable Data data) { final CustomBlock customBlock = BLOCK_MANAGER.getCustomBlock(customBlockId); setBlock(x, y, z, blockStateId, customBlock, data); } @@ -132,7 +132,8 @@ public class InstanceContainer extends Instance { * @param customBlock the {@link CustomBlock}, null if none * @param data the {@link Data}, null if none */ - private synchronized void setBlock(int x, int y, int z, short blockStateId, CustomBlock customBlock, Data data) { + private synchronized void setBlock(int x, int y, int z, short blockStateId, + @Nullable CustomBlock customBlock, @Nullable Data data) { final Chunk chunk = getChunkAt(x, z); if (ChunkUtils.isLoaded(chunk)) { UNSAFE_setBlock(chunk, x, y, z, blockStateId, customBlock, data); @@ -160,6 +161,8 @@ public class InstanceContainer extends Instance { */ private void UNSAFE_setBlock(@NotNull Chunk chunk, int x, int y, int z, short blockStateId, @Nullable CustomBlock customBlock, @Nullable Data data) { + + // Cannot place block in a read-only chunk if (chunk.isReadOnly()) { return; } diff --git a/src/main/java/net/minestom/server/listener/manager/PacketConsumer.java b/src/main/java/net/minestom/server/listener/manager/PacketConsumer.java index 86a35e591..5d88111ae 100644 --- a/src/main/java/net/minestom/server/listener/manager/PacketConsumer.java +++ b/src/main/java/net/minestom/server/listener/manager/PacketConsumer.java @@ -2,8 +2,20 @@ package net.minestom.server.listener.manager; import net.minestom.server.entity.Player; import net.minestom.server.network.packet.client.ClientPlayPacket; +import org.jetbrains.annotations.NotNull; +/** + * Interface used to add a listener for incoming packets with {@link net.minestom.server.network.ConnectionManager#onPacketReceive(PacketConsumer)}. + */ @FunctionalInterface public interface PacketConsumer { - void accept(Player player, PacketController packetController, ClientPlayPacket packet); + + /** + * Called when a packet is received from the client. + * + * @param player the player who sent the packet + * @param packetController the packet controller, used to cancel or control which listener will be called + * @param packet the received packet + */ + void accept(@NotNull Player player, @NotNull PacketController packetController, @NotNull ClientPlayPacket packet); } diff --git a/src/main/java/net/minestom/server/listener/manager/PacketController.java b/src/main/java/net/minestom/server/listener/manager/PacketController.java index a0557aa3a..926dce935 100644 --- a/src/main/java/net/minestom/server/listener/manager/PacketController.java +++ b/src/main/java/net/minestom/server/listener/manager/PacketController.java @@ -1,11 +1,18 @@ package net.minestom.server.listener.manager; +import net.minestom.server.entity.Player; +import net.minestom.server.network.packet.client.ClientPlayPacket; +import org.jetbrains.annotations.Nullable; + +/** + * Used to control the output of a packet in {@link PacketConsumer#accept(Player, PacketController, ClientPlayPacket)}. + */ public class PacketController { private boolean cancel; private PacketListenerConsumer packetListenerConsumer; - protected PacketController(PacketListenerConsumer packetListenerConsumer) { + protected PacketController(@Nullable PacketListenerConsumer packetListenerConsumer) { this.packetListenerConsumer = packetListenerConsumer; } @@ -30,8 +37,9 @@ public class PacketController { /** * Gets the listener associated with the packet. * - * @return the packet's listener + * @return the packet's listener, null if not present */ + @Nullable public PacketListenerConsumer getPacketListenerConsumer() { return packetListenerConsumer; } @@ -41,9 +49,9 @@ public class PacketController { *

* WARNING: this will overwrite the default minestom listener. * - * @param packetListenerConsumer the new packet listener + * @param packetListenerConsumer the new packet listener, can be null */ - public void setPacketListenerConsumer(PacketListenerConsumer packetListenerConsumer) { + public void setPacketListenerConsumer(@Nullable PacketListenerConsumer packetListenerConsumer) { this.packetListenerConsumer = packetListenerConsumer; } } diff --git a/src/main/java/net/minestom/server/listener/manager/PacketListenerConsumer.java b/src/main/java/net/minestom/server/listener/manager/PacketListenerConsumer.java index 04ec0bd96..800531eb7 100644 --- a/src/main/java/net/minestom/server/listener/manager/PacketListenerConsumer.java +++ b/src/main/java/net/minestom/server/listener/manager/PacketListenerConsumer.java @@ -3,6 +3,11 @@ package net.minestom.server.listener.manager; import net.minestom.server.entity.Player; import net.minestom.server.network.packet.client.ClientPlayPacket; +/** + * Small convenient interface to use method references with {@link PacketListenerManager#setListener(Class, PacketListenerConsumer)}. + * + * @param the packet type + */ @FunctionalInterface public interface PacketListenerConsumer { void accept(T packet, Player player); diff --git a/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java b/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java index 454e801c4..cb7eadfcd 100644 --- a/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java +++ b/src/main/java/net/minestom/server/listener/manager/PacketListenerManager.java @@ -6,11 +6,12 @@ import net.minestom.server.listener.*; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.packet.client.ClientPlayPacket; import net.minestom.server.network.packet.client.play.*; +import org.jetbrains.annotations.NotNull; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public class PacketListenerManager { +public final class PacketListenerManager { private static final ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager(); @@ -48,7 +49,14 @@ public class PacketListenerManager { setListener(ClientAdvancementTabPacket.class, AdvancementTabListener::listener); } - public void process(T packet, Player player) { + /** + * Processes a packet by getting its {@link PacketListenerConsumer} and calling all the packet listeners. + * + * @param packet the received packet + * @param player the player who sent the packet + * @param the packet type + */ + public void process(@NotNull T packet, @NotNull Player player) { final Class clazz = packet.getClass(); @@ -56,7 +64,7 @@ public class PacketListenerManager { // Listener can be null if none has been set before, call PacketConsumer anyway if (packetListenerConsumer == null) { - System.err.println("Packet " + clazz + " does not have any default listener!"); + System.err.println("Packet " + clazz + " does not have any default listener! (The issue comes from Minestom)"); } @@ -79,15 +87,15 @@ public class PacketListenerManager { } /** - * Set the listener of a packet + * Sets the listener of a packet. *

- * WARNING: this will overwrite the default minestom listener, this is not reversible + * WARNING: this will overwrite the default minestom listener, this is not reversible. * * @param packetClass the class of the packet * @param consumer the new packet's listener * @param the type of the packet */ - public void setListener(Class packetClass, PacketListenerConsumer consumer) { + public void setListener(@NotNull Class packetClass, @NotNull PacketListenerConsumer consumer) { this.listeners.put(packetClass, consumer); } diff --git a/src/main/java/net/minestom/server/network/PacketWriterUtils.java b/src/main/java/net/minestom/server/network/PacketWriterUtils.java index 2bbe4dee3..f305ea761 100644 --- a/src/main/java/net/minestom/server/network/PacketWriterUtils.java +++ b/src/main/java/net/minestom/server/network/PacketWriterUtils.java @@ -24,7 +24,7 @@ public final class PacketWriterUtils { private static final ExecutorService PACKET_WRITER_POOL = new MinestomThread(MinecraftServer.THREAD_COUNT_PACKET_WRITER, MinecraftServer.THREAD_NAME_PACKET_WRITER); /** - * Write the {@link ServerPacket} in the writer thread pool. + * Writes the {@link ServerPacket} in the writer thread pool. *

* WARNING: should not be used if the packet receive order is important * @@ -39,7 +39,7 @@ public final class PacketWriterUtils { } /** - * Write a {@link ServerPacket} in the writer thread pool and send it to every players in {@code players}. + * Writes a {@link ServerPacket} in the writer thread pool and send it to every players in {@code players}. *

* WARNING: should not be used if the packet receive order is important * @@ -65,7 +65,7 @@ public final class PacketWriterUtils { } /** - * Write a {@link ServerPacket} and send it to a {@link PlayerConnection}. + * Writes a {@link ServerPacket} and send it to a {@link PlayerConnection}. *

* WARNING: should not be used if the packet receive order is important * @@ -86,7 +86,7 @@ public final class PacketWriterUtils { } /** - * Write a {@link ServerPacket} and send it to a {@link Player}. + * Writes a {@link ServerPacket} and send it to a {@link Player}. *

* WARNING: should not be used if the packet receive order is important * diff --git a/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java b/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java index 2f5df038b..f23360efc 100644 --- a/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/ClientPlayPacket.java @@ -3,12 +3,20 @@ package net.minestom.server.network.packet.client; import net.minestom.server.MinecraftServer; import net.minestom.server.entity.Player; import net.minestom.server.listener.manager.PacketListenerManager; +import org.jetbrains.annotations.NotNull; public abstract class ClientPlayPacket implements ClientPacket { private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager(); - public void process(Player player) { + /** + * Processes the packet for {@code player}. + *

+ * Called during the player tick and forwarded to the {@link PacketListenerManager}. + * + * @param player the player who sent the packet + */ + public void process(@NotNull Player player) { PACKET_LISTENER_MANAGER.process(this, player); } diff --git a/src/main/java/net/minestom/server/utils/UniqueIdUtils.java b/src/main/java/net/minestom/server/utils/UniqueIdUtils.java index a0999d351..788406c9a 100644 --- a/src/main/java/net/minestom/server/utils/UniqueIdUtils.java +++ b/src/main/java/net/minestom/server/utils/UniqueIdUtils.java @@ -4,14 +4,14 @@ import java.util.UUID; import java.util.regex.Pattern; /** - * An utilities class for {@link UUID} + * An utilities class for {@link UUID}. */ public final class UniqueIdUtils { public static final Pattern UNIQUE_ID_PATTERN = Pattern.compile("\\b[0-9a-f]{8}\\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\\b[0-9a-f]{12}\\b"); /** - * Checks whether the {@code input} string is an {@link UUID} + * Checks whether the {@code input} string is an {@link UUID}. * * @param input The input string to be checked * @return {@code true} if the input an unique identifier, otherwise {@code false} diff --git a/src/main/java/net/minestom/server/utils/WeightedRandom.java b/src/main/java/net/minestom/server/utils/WeightedRandom.java index ba674fe1d..8d9c9b76e 100644 --- a/src/main/java/net/minestom/server/utils/WeightedRandom.java +++ b/src/main/java/net/minestom/server/utils/WeightedRandom.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.Random; /** - * Produces a random element from a given set, with weights applied + * Produces a random element from a given set, with weights applied. * * @param */ @@ -33,7 +33,7 @@ public class WeightedRandom { } /** - * Gets a random element from this set + * Gets a random element from this set. * * @param rng Random Number Generator to generate random numbers with * @return a random element from this set diff --git a/src/main/java/net/minestom/server/world/Difficulty.java b/src/main/java/net/minestom/server/world/Difficulty.java index 9a7a2be75..514209e32 100644 --- a/src/main/java/net/minestom/server/world/Difficulty.java +++ b/src/main/java/net/minestom/server/world/Difficulty.java @@ -1,5 +1,10 @@ package net.minestom.server.world; +/** + * Those are all the difficulties which can be displayed in the player menu. + *

+ * Sets with {@link net.minestom.server.MinecraftServer#setDifficulty(Difficulty)}. + */ public enum Difficulty { PEACEFUL((byte) 0), EASY((byte) 1), NORMAL((byte) 2), HARD((byte) 3);