From 3ddca82aaa5ae134f72cb492fa7359c5c1c9b483 Mon Sep 17 00:00:00 2001 From: themode Date: Tue, 10 Nov 2020 08:01:27 +0100 Subject: [PATCH] Cleanup 2 --- .../server/benchmark/BenchmarkManager.java | 7 +++-- .../net/minestom/server/bossbar/BarColor.java | 2 +- .../minestom/server/bossbar/BarDivision.java | 2 +- .../minestom/server/chat/ChatHoverEvent.java | 4 +-- .../net/minestom/server/chat/JsonMessage.java | 2 +- .../server/collision/BoundingBox.java | 11 +++---- .../server/collision/CollisionUtils.java | 2 +- .../server/command/builder/Command.java | 3 +- .../arguments/ArgumentDynamicStringArray.java | 3 +- .../arguments/ArgumentDynamicWord.java | 3 +- .../server/extras/velocity/VelocityProxy.java | 2 +- .../minestom/server/instance/Instance.java | 4 +-- .../inventory/type/FurnaceInventory.java | 2 +- .../network/player/NettyPlayerConnection.java | 2 +- .../minestom/server/utils/NamespaceID.java | 11 +++---- .../server/world/DimensionTypeManager.java | 29 ++++++++++--------- 16 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java b/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java index ddb824b32..269f1ff85 100644 --- a/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java +++ b/src/main/java/net/minestom/server/benchmark/BenchmarkManager.java @@ -7,6 +7,7 @@ import net.minestom.server.chat.ChatColor; import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.time.UpdateOption; import net.minestom.server.utils.validate.Check; +import org.jetbrains.annotations.NotNull; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; @@ -24,6 +25,8 @@ import static net.minestom.server.MinecraftServer.*; *

* Needs to be enabled with {@link #enable(UpdateOption)}. Memory can then be accessed with {@link #getUsedMemory()} * and the CPUs usage with {@link #getResultMap()} or {@link #getCpuMonitoringMessage()}. + *

+ * Be aware that this is not the most accurate method, you should use a proper java profiler depending on your needs. */ public final class BenchmarkManager { @@ -53,7 +56,7 @@ public final class BenchmarkManager { private long time; - public void enable(UpdateOption updateOption) { + public void enable(@NotNull UpdateOption updateOption) { Check.stateCondition(enabled, "A benchmark is already running, please disable it first."); time = updateOption.getTimeUnit().toMilliseconds(updateOption.getValue()); @@ -84,7 +87,7 @@ public final class BenchmarkManager { this.enabled = false; } - public void addThreadMonitor(String threadName) { + public void addThreadMonitor(@NotNull String threadName) { THREADS.add(threadName); } diff --git a/src/main/java/net/minestom/server/bossbar/BarColor.java b/src/main/java/net/minestom/server/bossbar/BarColor.java index 63ccd523c..79c997ae5 100644 --- a/src/main/java/net/minestom/server/bossbar/BarColor.java +++ b/src/main/java/net/minestom/server/bossbar/BarColor.java @@ -1,7 +1,7 @@ package net.minestom.server.bossbar; /** - * Represents the displayed color of a {@link BossBar} + * Represents the displayed color of a {@link BossBar}. */ public enum BarColor { PINK, diff --git a/src/main/java/net/minestom/server/bossbar/BarDivision.java b/src/main/java/net/minestom/server/bossbar/BarDivision.java index 113da4d39..317aed640 100644 --- a/src/main/java/net/minestom/server/bossbar/BarDivision.java +++ b/src/main/java/net/minestom/server/bossbar/BarDivision.java @@ -1,7 +1,7 @@ package net.minestom.server.bossbar; /** - * Used to define the number of segments on a {@link BossBar} + * Used to define the number of segments on a {@link BossBar}. */ public enum BarDivision { SOLID, diff --git a/src/main/java/net/minestom/server/chat/ChatHoverEvent.java b/src/main/java/net/minestom/server/chat/ChatHoverEvent.java index be292addf..cf66a0d96 100644 --- a/src/main/java/net/minestom/server/chat/ChatHoverEvent.java +++ b/src/main/java/net/minestom/server/chat/ChatHoverEvent.java @@ -13,8 +13,8 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound; public class ChatHoverEvent { private final String action; - private String value; - private JsonObject valueObject; + private final String value; + private final JsonObject valueObject; private final boolean isJson; private ChatHoverEvent(@NotNull String action, @NotNull String value) { diff --git a/src/main/java/net/minestom/server/chat/JsonMessage.java b/src/main/java/net/minestom/server/chat/JsonMessage.java index d9881ea59..08729948b 100644 --- a/src/main/java/net/minestom/server/chat/JsonMessage.java +++ b/src/main/java/net/minestom/server/chat/JsonMessage.java @@ -58,7 +58,7 @@ public abstract class JsonMessage { public static class RawJsonMessage extends JsonMessage { - private JsonObject jsonObject; + private final JsonObject jsonObject; public RawJsonMessage(@NotNull JsonObject jsonObject) { this.jsonObject = jsonObject; diff --git a/src/main/java/net/minestom/server/collision/BoundingBox.java b/src/main/java/net/minestom/server/collision/BoundingBox.java index ebc527cc4..821338d3c 100644 --- a/src/main/java/net/minestom/server/collision/BoundingBox.java +++ b/src/main/java/net/minestom/server/collision/BoundingBox.java @@ -61,28 +61,25 @@ public class BoundingBox { final float offsetX = 1; final float x = blockPosition.getX(); - final float minX = x; final float maxX = x + offsetX; - final boolean checkX = getMinX() < maxX && getMaxX() > minX; + final boolean checkX = getMinX() < maxX && getMaxX() > x; if (!checkX) return false; final float y = blockPosition.getY(); - final float minY = y; final float maxY = y + 0.99999f; - final boolean checkY = getMinY() < maxY && getMaxY() > minY; + final boolean checkY = getMinY() < maxY && getMaxY() > y; if (!checkY) return false; final float offsetZ = 1; final float z = blockPosition.getZ(); - final float minZ = z; final float maxZ = z + offsetZ; - final boolean checkZ = getMinZ() < maxZ && getMaxZ() > minZ; - return checkZ; + // Z check + return getMinZ() < maxZ && getMaxZ() > z; } public boolean intersect(float x, float y, float z) { diff --git a/src/main/java/net/minestom/server/collision/CollisionUtils.java b/src/main/java/net/minestom/server/collision/CollisionUtils.java index ef7746af2..b4780accb 100644 --- a/src/main/java/net/minestom/server/collision/CollisionUtils.java +++ b/src/main/java/net/minestom/server/collision/CollisionUtils.java @@ -105,7 +105,7 @@ public class CollisionUtils { if (!collisionFound) { Vector direction = new Vector(); direction.copy(axis); - collisionFound |= !stepOnce(instance, direction, remainingLength, cornersCopy, cornerPositions); + collisionFound = !stepOnce(instance, direction, remainingLength, cornersCopy, cornerPositions); } // find the corner which moved the least diff --git a/src/main/java/net/minestom/server/command/builder/Command.java b/src/main/java/net/minestom/server/command/builder/Command.java index 811d7d6ae..6302a0b05 100644 --- a/src/main/java/net/minestom/server/command/builder/Command.java +++ b/src/main/java/net/minestom/server/command/builder/Command.java @@ -163,9 +163,10 @@ public class Command { } /** - * Sets the default {@link CommandExecutor} (which is called when there is no argument). + * Sets the default {@link CommandExecutor}. * * @param executor the new default executor, null to remove it + * @see #getDefaultExecutor() */ public void setDefaultExecutor(@Nullable CommandExecutor executor) { this.defaultExecutor = executor; diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java index 71689b35e..23128e3c0 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java @@ -35,8 +35,7 @@ public class ArgumentDynamicStringArray extends Argument { public int getConditionResult(@NotNull String[] value) { // true if 'value' is valid based on the dynamic restriction - final boolean restrictionCheck = dynamicRestriction != null ? - dynamicRestriction.isValid(value) : true; + final boolean restrictionCheck = dynamicRestriction == null || dynamicRestriction.isValid(value); if (!restrictionCheck) { return RESTRICTION_ERROR; diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java index df259bebe..331ca68b6 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java @@ -37,8 +37,7 @@ public class ArgumentDynamicWord extends Argument { public int getConditionResult(@NotNull String value) { // true if 'value' is valid based on the dynamic restriction - final boolean restrictionCheck = dynamicRestriction != null ? - dynamicRestriction.isValid(value) : true; + final boolean restrictionCheck = dynamicRestriction == null || dynamicRestriction.isValid(value); if (!restrictionCheck) { return RESTRICTION_ERROR; diff --git a/src/main/java/net/minestom/server/extras/velocity/VelocityProxy.java b/src/main/java/net/minestom/server/extras/velocity/VelocityProxy.java index 0510d3a21..f479ac110 100644 --- a/src/main/java/net/minestom/server/extras/velocity/VelocityProxy.java +++ b/src/main/java/net/minestom/server/extras/velocity/VelocityProxy.java @@ -10,7 +10,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /** - * Support for Velocity proxy. + * Support for Velocity modern forwarding. *

* Can be enabled by simply calling {@link #enable(String)}. */ diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index 055b86e5b..8b22da131 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -661,8 +661,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta * Sends a {@link BlockActionPacket} for all the viewers of the specific position. * * @param blockPosition the block position - * @param actionId - * @param actionParam + * @param actionId the action id, depends on the block + * @param actionParam the action parameter, depends on the block * @see BlockActionPacket for the action id & param */ public void sendBlockAction(@NotNull BlockPosition blockPosition, byte actionId, byte actionParam) { diff --git a/src/main/java/net/minestom/server/inventory/type/FurnaceInventory.java b/src/main/java/net/minestom/server/inventory/type/FurnaceInventory.java index 48bd187a5..6943fb8ce 100644 --- a/src/main/java/net/minestom/server/inventory/type/FurnaceInventory.java +++ b/src/main/java/net/minestom/server/inventory/type/FurnaceInventory.java @@ -27,7 +27,7 @@ public class FurnaceInventory extends Inventory { /** * Represents the amount of tick until the fire icon come empty. * - * @param remainingFuelTick + * @param remainingFuelTick the amount of tick until the fire icon is empty */ public void setRemainingFuelTick(short remainingFuelTick) { this.remainingFuelTick = remainingFuelTick; diff --git a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java index d2e0bd24c..c360bf800 100644 --- a/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java +++ b/src/main/java/net/minestom/server/network/player/NettyPlayerConnection.java @@ -45,7 +45,7 @@ public class NettyPlayerConnection extends PlayerConnection { // Used for the login plugin request packet, to retrieve the channel from a message id, // cleared once the player enters the play state - private Map pluginRequestMap = new ConcurrentHashMap<>(); + private final Map pluginRequestMap = new ConcurrentHashMap<>(); public NettyPlayerConnection(@NotNull SocketChannel channel) { super(); diff --git a/src/main/java/net/minestom/server/utils/NamespaceID.java b/src/main/java/net/minestom/server/utils/NamespaceID.java index 527b3b884..9c22c76b2 100644 --- a/src/main/java/net/minestom/server/utils/NamespaceID.java +++ b/src/main/java/net/minestom/server/utils/NamespaceID.java @@ -22,10 +22,11 @@ public class NamespaceID implements CharSequence { * Extracts the domain from the namespace ID. "minecraft:stone" would return "minecraft". * If no ':' character is found, "minecraft" is returned. * - * @param namespaceID + * @param namespaceID the namespace id to get the domain from * @return the domain of the namespace ID */ - public static String getDomain(String namespaceID) { + @NotNull + public static String getDomain(@NotNull String namespaceID) { final int index = namespaceID.indexOf(':'); if (index < 0) return "minecraft"; @@ -37,10 +38,10 @@ public class NamespaceID implements CharSequence { * Extracts the path from the namespace ID. "minecraft:blocks/stone" would return "blocks/stone". * If no ':' character is found, the

namespaceID
is returned. * - * @param namespaceID + * @param namespaceID the namespace id to get the path from * @return the path of the namespace ID */ - public static String getPath(String namespaceID) { + public static String getPath(@NotNull String namespaceID) { final int index = namespaceID.indexOf(':'); if (index < 0) return namespaceID; @@ -61,7 +62,7 @@ public class NamespaceID implements CharSequence { return from(getDomain(id), getPath(id)); } - private NamespaceID(String path) { + private NamespaceID(@NotNull String path) { final int index = path.indexOf(':'); if (index < 0) { this.domain = "minecraft"; diff --git a/src/main/java/net/minestom/server/world/DimensionTypeManager.java b/src/main/java/net/minestom/server/world/DimensionTypeManager.java index f45dc2900..ad184317d 100644 --- a/src/main/java/net/minestom/server/world/DimensionTypeManager.java +++ b/src/main/java/net/minestom/server/world/DimensionTypeManager.java @@ -1,5 +1,6 @@ package net.minestom.server.world; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTList; import org.jglrxavpok.hephaistos.nbt.NBTTypes; @@ -9,45 +10,47 @@ import java.util.LinkedList; import java.util.List; /** - * Allows servers to register custom dimensions. Also used during player joining to send the list of all existing dimensions. - * + * Allows servers to register custom dimensions. Also used during player login to send the list of all existing dimensions. + *

* Contains {@link DimensionType#OVERWORLD} by default but can be removed. */ -public class DimensionTypeManager { +public final class DimensionTypeManager { - private List dimensionTypes = new LinkedList<>(); + private final List dimensionTypes = new LinkedList<>(); public DimensionTypeManager() { addDimension(DimensionType.OVERWORLD); } /** - * Add a new dimension type. This does NOT send the new list to players. - * @param dimensionType + * Adds a new dimension type. This does NOT send the new list to players. + * + * @param dimensionType the dimension to add */ - public void addDimension(DimensionType dimensionType) { + public void addDimension(@NotNull DimensionType dimensionType) { dimensionTypes.add(dimensionType); } /** * Removes a dimension type. This does NOT send the new list to players. - * @param dimensionType + * + * @param dimensionType the dimension to remove * @return if the dimension type was removed, false if it was not present before */ - public boolean removeDimension(DimensionType dimensionType) { + public boolean removeDimension(@NotNull DimensionType dimensionType) { return dimensionTypes.remove(dimensionType); } /** - * Returns an immutable copy of the dimension types already registered - * @return + * Returns an immutable copy of the dimension types already registered. + * + * @return an unmodifiable {@link List} containing all the added dimensions */ + @NotNull public List unmodifiableList() { return Collections.unmodifiableList(dimensionTypes); } - - public NBTCompound toNBT() { NBTCompound dimensions = new NBTCompound(); dimensions.setString("type", "minecraft:dimension_type");