From 7a54b4162d70ad11b630f8a8aa40d6aa86d5a6d6 Mon Sep 17 00:00:00 2001 From: themode Date: Tue, 26 Jan 2021 15:53:03 +0100 Subject: [PATCH] Style cleanup --- .../java/net/minestom/server/Bootstrap.java | 4 +- .../server/benchmark/ThreadResult.java | 10 +- .../minestom/server/ping/ResponseData.java | 271 +++++++++--------- .../server/scoreboard/Scoreboard.java | 17 +- .../net/minestom/server/scoreboard/Team.java | 18 +- .../server/scoreboard/TeamManager.java | 1 - .../net/minestom/server/utils/BufUtils.java | 38 +-- .../minestom/server/utils/math/ByteRange.java | 24 +- .../server/utils/math/DoubleRange.java | 24 +- .../minestom/server/utils/math/IntRange.java | 25 +- .../minestom/server/utils/math/LongRange.java | 24 +- 11 files changed, 240 insertions(+), 216 deletions(-) diff --git a/src/main/java/net/minestom/server/Bootstrap.java b/src/main/java/net/minestom/server/Bootstrap.java index 9e96b65df..5939923f7 100644 --- a/src/main/java/net/minestom/server/Bootstrap.java +++ b/src/main/java/net/minestom/server/Bootstrap.java @@ -34,7 +34,7 @@ public final class Bootstrap { Class mainClass = classLoader.loadClass(mainClassFullName); Method main = mainClass.getDeclaredMethod("main", String[].class); main.setAccessible(true); - main.invoke(null, new Object[] { args }); + main.invoke(null, new Object[]{args}); } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | ClassNotFoundException e) { e.printStackTrace(); } @@ -44,7 +44,7 @@ public final class Bootstrap { // hacks required to pass custom arguments Method start = MixinBootstrap.class.getDeclaredMethod("start"); start.setAccessible(true); - if (! ((boolean)start.invoke(null)) ) { + if (!((boolean) start.invoke(null))) { return; } diff --git a/src/main/java/net/minestom/server/benchmark/ThreadResult.java b/src/main/java/net/minestom/server/benchmark/ThreadResult.java index 3de6f51a9..be0a81a7a 100644 --- a/src/main/java/net/minestom/server/benchmark/ThreadResult.java +++ b/src/main/java/net/minestom/server/benchmark/ThreadResult.java @@ -2,9 +2,15 @@ package net.minestom.server.benchmark; public class ThreadResult { - private final double cpuPercentage, userPercentage, waitedPercentage, blockedPercentage; + private final double cpuPercentage; + private final double userPercentage; + private final double waitedPercentage; + private final double blockedPercentage; - protected ThreadResult(double cpuPercentage, double userPercentage, double waitedPercentage, double blockedPercentage) { + protected ThreadResult(double cpuPercentage, + double userPercentage, + double waitedPercentage, + double blockedPercentage) { this.cpuPercentage = cpuPercentage; this.userPercentage = userPercentage; this.waitedPercentage = waitedPercentage; diff --git a/src/main/java/net/minestom/server/ping/ResponseData.java b/src/main/java/net/minestom/server/ping/ResponseData.java index af8f18b4b..498c30ae8 100644 --- a/src/main/java/net/minestom/server/ping/ResponseData.java +++ b/src/main/java/net/minestom/server/ping/ResponseData.java @@ -2,6 +2,8 @@ package net.minestom.server.ping; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -14,138 +16,143 @@ import java.util.UUID; */ public class ResponseData { - private final JsonObject jsonObject; + private final JsonObject jsonObject; - private final JsonObject versionObject; - private final JsonObject playersObject; - private final JsonArray sampleArray; - private final JsonObject descriptionObject; - private final List pingPlayers; - private String name; - private int protocol; - private int maxPlayer; - private int online; - private String description; - - private String favicon; - - /** Constructs a new {@link ResponseData}. */ - public ResponseData() { - this.jsonObject = new JsonObject(); - this.versionObject = new JsonObject(); - this.playersObject = new JsonObject(); - this.sampleArray = new JsonArray(); - this.descriptionObject = new JsonObject(); - this.pingPlayers = new ArrayList<>(); - } - - /** - * Sets the name for the response. - * - * @param name The name for the response data. - */ - public void setName(String name) { - this.name = name; - } - - /** - * Sets the response protocol version. - * - * @param protocol The protocol version for the response data. - */ - public void setProtocol(int protocol) { - this.protocol = protocol; - } - - /** - * Sets the response maximum player count. - * - * @param maxPlayer The maximum player count for the response data. - */ - public void setMaxPlayer(int maxPlayer) { - this.maxPlayer = maxPlayer; - } - - /** - * Sets the response online count. - * - * @param online The online count for the response data. - */ - public void setOnline(int online) { - this.online = online; - } - - /** - * Adds a player to the response. - * - * @param name The name of the player. - * @param uuid The unique identifier of the player. - */ - public void addPlayer(String name, UUID uuid) { - PingPlayer pingPlayer = new PingPlayer(); - pingPlayer.name = name; - pingPlayer.uuid = uuid; - this.pingPlayers.add(pingPlayer); - } - - /** - * Removes all of the ping players from this {@link #pingPlayers}. The {@link #pingPlayers} list - * will be empty this call returns. - */ - public void clearPlayers() { - this.pingPlayers.clear(); - } - - /** - * Sets the response description. - * - * @param description The description for the response data. - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Sets the response favicon. - * - * @param favicon The favicon for the response data. - */ - public void setFavicon(String favicon) { - this.favicon = favicon; - } - - /** - * Converts the response data into a {@link JsonObject}. - * - * @return The converted response data as a json tree. - */ - public JsonObject build() { - versionObject.addProperty("name", name); - versionObject.addProperty("protocol", protocol); - - playersObject.addProperty("max", maxPlayer); - playersObject.addProperty("online", online); - - for (PingPlayer pingPlayer : pingPlayers) { - JsonObject pingPlayerObject = new JsonObject(); - pingPlayerObject.addProperty("name", pingPlayer.name); - pingPlayerObject.addProperty("id", pingPlayer.uuid.toString()); - sampleArray.add(pingPlayerObject); - } - playersObject.add("sample", sampleArray); - - descriptionObject.addProperty("text", description); - - jsonObject.add("version", versionObject); - jsonObject.add("players", playersObject); - jsonObject.add("description", descriptionObject); - jsonObject.addProperty("favicon", favicon); - return jsonObject; - } - - /** Represents a player line in the server list hover. */ - private static class PingPlayer { + private final JsonObject versionObject; + private final JsonObject playersObject; + private final JsonArray sampleArray; + private final JsonObject descriptionObject; + private final List pingPlayers; private String name; - private UUID uuid; - } + private int protocol; + private int maxPlayer; + private int online; + private String description; + + private String favicon; + + /** + * Constructs a new {@link ResponseData}. + */ + public ResponseData() { + this.jsonObject = new JsonObject(); + this.versionObject = new JsonObject(); + this.playersObject = new JsonObject(); + this.sampleArray = new JsonArray(); + this.descriptionObject = new JsonObject(); + this.pingPlayers = new ArrayList<>(); + } + + /** + * Sets the name for the response. + * + * @param name The name for the response data. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Sets the response protocol version. + * + * @param protocol The protocol version for the response data. + */ + public void setProtocol(int protocol) { + this.protocol = protocol; + } + + /** + * Sets the response maximum player count. + * + * @param maxPlayer The maximum player count for the response data. + */ + public void setMaxPlayer(int maxPlayer) { + this.maxPlayer = maxPlayer; + } + + /** + * Sets the response online count. + * + * @param online The online count for the response data. + */ + public void setOnline(int online) { + this.online = online; + } + + /** + * Adds a player to the response. + * + * @param name The name of the player. + * @param uuid The unique identifier of the player. + */ + public void addPlayer(String name, UUID uuid) { + PingPlayer pingPlayer = new PingPlayer(); + pingPlayer.name = name; + pingPlayer.uuid = uuid; + this.pingPlayers.add(pingPlayer); + } + + /** + * Removes all of the ping players from this {@link #pingPlayers}. The {@link #pingPlayers} list + * will be empty this call returns. + */ + public void clearPlayers() { + this.pingPlayers.clear(); + } + + /** + * Sets the response description. + * + * @param description The description for the response data. + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Sets the response favicon. + * + * @param favicon The favicon for the response data. + */ + public void setFavicon(String favicon) { + this.favicon = favicon; + } + + /** + * Converts the response data into a {@link JsonObject}. + * + * @return The converted response data as a json tree. + */ + @NotNull + public JsonObject build() { + versionObject.addProperty("name", name); + versionObject.addProperty("protocol", protocol); + + playersObject.addProperty("max", maxPlayer); + playersObject.addProperty("online", online); + + for (PingPlayer pingPlayer : pingPlayers) { + JsonObject pingPlayerObject = new JsonObject(); + pingPlayerObject.addProperty("name", pingPlayer.name); + pingPlayerObject.addProperty("id", pingPlayer.uuid.toString()); + sampleArray.add(pingPlayerObject); + } + playersObject.add("sample", sampleArray); + + descriptionObject.addProperty("text", description); + + jsonObject.add("version", versionObject); + jsonObject.add("players", playersObject); + jsonObject.add("description", descriptionObject); + jsonObject.addProperty("favicon", favicon); + return jsonObject; + } + + /** + * Represents a player line in the server list hover. + */ + private static class PingPlayer { + private String name; + private UUID uuid; + } } diff --git a/src/main/java/net/minestom/server/scoreboard/Scoreboard.java b/src/main/java/net/minestom/server/scoreboard/Scoreboard.java index 2361ae226..4e648e1cc 100644 --- a/src/main/java/net/minestom/server/scoreboard/Scoreboard.java +++ b/src/main/java/net/minestom/server/scoreboard/Scoreboard.java @@ -6,19 +6,21 @@ import net.minestom.server.entity.Player; import net.minestom.server.network.packet.server.play.DisplayScoreboardPacket; import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket; import net.minestom.server.network.packet.server.play.UpdateScorePacket; +import org.jetbrains.annotations.NotNull; /** - * This interface represents all scoreboard of Minecraft + * This interface represents all scoreboard of Minecraft. */ public interface Scoreboard extends Viewable { /** - * Creates a creation objective packet + * Creates a creation objective packet. * * @param value The value for the objective * @param type The type for the objective * @return the creation objective packet */ + @NotNull default ScoreboardObjectivePacket getCreationObjectivePacket(String value, ScoreboardObjectivePacket.Type type) { final ScoreboardObjectivePacket packet = new ScoreboardObjectivePacket(); packet.objectiveName = this.getObjectiveName(); @@ -30,10 +32,11 @@ public interface Scoreboard extends Viewable { } /** - * Creates the destruction objective packet + * Creates the destruction objective packet. * * @return the destruction objective packet */ + @NotNull default ScoreboardObjectivePacket getDestructionObjectivePacket() { final ScoreboardObjectivePacket packet = new ScoreboardObjectivePacket(); packet.objectiveName = this.getObjectiveName(); @@ -43,11 +46,12 @@ public interface Scoreboard extends Viewable { } /** - * Creates the {@link DisplayScoreboardPacket} + * Creates the {@link DisplayScoreboardPacket}. * * @param position The position of the scoreboard * @return the created display scoreboard packet */ + @NotNull default DisplayScoreboardPacket getDisplayScoreboardPacket(byte position) { final DisplayScoreboardPacket packet = new DisplayScoreboardPacket(); packet.position = position; @@ -57,7 +61,7 @@ public interface Scoreboard extends Viewable { } /** - * Updates the score of a {@link Player} + * Updates the score of a {@link Player}. * * @param player The player * @param score The new score @@ -73,10 +77,11 @@ public interface Scoreboard extends Viewable { } /** - * Gets the objective name of the scoreboard + * Gets the objective name of the scoreboard. * * @return the objective name */ + @NotNull String getObjectiveName(); } diff --git a/src/main/java/net/minestom/server/scoreboard/Team.java b/src/main/java/net/minestom/server/scoreboard/Team.java index 91673002c..2eb56f03e 100644 --- a/src/main/java/net/minestom/server/scoreboard/Team.java +++ b/src/main/java/net/minestom/server/scoreboard/Team.java @@ -25,43 +25,43 @@ public class Team { private static final ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager(); /** - * A collection of all registered entities who are on the team + * A collection of all registered entities who are on the team. */ private final Set members; /** - * The registry name of the team + * The registry name of the team. */ private final String teamName; /** - * The display name of the team + * The display name of the team. */ private JsonMessage teamDisplayName; /** - * A BitMask + * A BitMask. */ private byte friendlyFlags; /** - * The visibility of the team + * The visibility of the team. */ private NameTagVisibility nameTagVisibility; /** - * The collision rule of the team + * The collision rule of the team. */ private CollisionRule collisionRule; /** * Used to color the name of players on the team
- * The color of a team defines how the names of the team members are visualized + * The color of a team defines how the names of the team members are visualized. */ private ChatColor teamColor; /** - * Shown before the names of the players who belong to this team + * Shown before the names of the players who belong to this team. */ private JsonMessage prefix; /** - * Shown after the names of the player who belong to this team + * Shown after the names of the player who belong to this team. */ private JsonMessage suffix; diff --git a/src/main/java/net/minestom/server/scoreboard/TeamManager.java b/src/main/java/net/minestom/server/scoreboard/TeamManager.java index 033ade8f9..a9d02beec 100644 --- a/src/main/java/net/minestom/server/scoreboard/TeamManager.java +++ b/src/main/java/net/minestom/server/scoreboard/TeamManager.java @@ -2,7 +2,6 @@ package net.minestom.server.scoreboard; import net.minestom.server.MinecraftServer; import net.minestom.server.chat.ChatColor; -import net.minestom.server.chat.ColoredText; import net.minestom.server.chat.JsonMessage; import net.minestom.server.entity.LivingEntity; import net.minestom.server.entity.Player; diff --git a/src/main/java/net/minestom/server/utils/BufUtils.java b/src/main/java/net/minestom/server/utils/BufUtils.java index 7e622dcdd..dcf25c6a2 100644 --- a/src/main/java/net/minestom/server/utils/BufUtils.java +++ b/src/main/java/net/minestom/server/utils/BufUtils.java @@ -5,30 +5,30 @@ import io.netty.buffer.PooledByteBufAllocator; public class BufUtils { - private static final PooledByteBufAllocator alloc = PooledByteBufAllocator.DEFAULT; + private static final PooledByteBufAllocator alloc = PooledByteBufAllocator.DEFAULT; - public static ByteBuf getBuffer() { - return alloc.heapBuffer(); - } + public static ByteBuf getBuffer() { + return alloc.heapBuffer(); + } - public static ByteBuf getBuffer(boolean io) { - return io ? alloc.ioBuffer() : alloc.heapBuffer(); - } + public static ByteBuf getBuffer(boolean io) { + return io ? alloc.ioBuffer() : alloc.heapBuffer(); + } - public static ByteBuf getBuffer(int initialCapacity) { - return alloc.heapBuffer(initialCapacity); - } + public static ByteBuf getBuffer(int initialCapacity) { + return alloc.heapBuffer(initialCapacity); + } - public static ByteBuf getBuffer(boolean io, int initialCapacity) { - return io ? alloc.ioBuffer(initialCapacity) : alloc.heapBuffer(initialCapacity); - } + public static ByteBuf getBuffer(boolean io, int initialCapacity) { + return io ? alloc.ioBuffer(initialCapacity) : alloc.heapBuffer(initialCapacity); + } - public static ByteBuf getBuffer(int initialCapacity, int maxCapacity) { - return alloc.heapBuffer(initialCapacity, maxCapacity); - } + public static ByteBuf getBuffer(int initialCapacity, int maxCapacity) { + return alloc.heapBuffer(initialCapacity, maxCapacity); + } - public static ByteBuf getBuffer(boolean io, int initialCapacity, int maxCapacity) { - return io ? alloc.ioBuffer(initialCapacity, maxCapacity) : alloc.heapBuffer(initialCapacity, maxCapacity); - } + public static ByteBuf getBuffer(boolean io, int initialCapacity, int maxCapacity) { + return io ? alloc.ioBuffer(initialCapacity, maxCapacity) : alloc.heapBuffer(initialCapacity, maxCapacity); + } } diff --git a/src/main/java/net/minestom/server/utils/math/ByteRange.java b/src/main/java/net/minestom/server/utils/math/ByteRange.java index 6487991f6..8509d4037 100644 --- a/src/main/java/net/minestom/server/utils/math/ByteRange.java +++ b/src/main/java/net/minestom/server/utils/math/ByteRange.java @@ -2,17 +2,19 @@ package net.minestom.server.utils.math; public class ByteRange extends Range { - public ByteRange(Byte minimum, Byte maximum) { - super(minimum, maximum); - } + public ByteRange(Byte minimum, Byte maximum) { + super(minimum, maximum); + } - public ByteRange(Byte value) { - super(value); - } + public ByteRange(Byte value) { + super(value); + } - /** {@inheritDoc} */ - @Override - public boolean isInRange(Byte value) { - return value >= this.getMinimum() && value <= this.getMaximum(); - } + /** + * {@inheritDoc} + */ + @Override + public boolean isInRange(Byte value) { + return value >= this.getMinimum() && value <= this.getMaximum(); + } } diff --git a/src/main/java/net/minestom/server/utils/math/DoubleRange.java b/src/main/java/net/minestom/server/utils/math/DoubleRange.java index 6b0890e76..e117737ce 100644 --- a/src/main/java/net/minestom/server/utils/math/DoubleRange.java +++ b/src/main/java/net/minestom/server/utils/math/DoubleRange.java @@ -2,17 +2,19 @@ package net.minestom.server.utils.math; public class DoubleRange extends Range { - public DoubleRange(Double minimum, Double maximum) { - super(minimum, maximum); - } + public DoubleRange(Double minimum, Double maximum) { + super(minimum, maximum); + } - public DoubleRange(Double value) { - super(value); - } + public DoubleRange(Double value) { + super(value); + } - /** {@inheritDoc} */ - @Override - public boolean isInRange(Double value) { - return value >= this.getMinimum() && value <= this.getMaximum(); - } + /** + * {@inheritDoc} + */ + @Override + public boolean isInRange(Double value) { + return value >= this.getMinimum() && value <= this.getMaximum(); + } } diff --git a/src/main/java/net/minestom/server/utils/math/IntRange.java b/src/main/java/net/minestom/server/utils/math/IntRange.java index 7d0a77c2f..b06414b7d 100644 --- a/src/main/java/net/minestom/server/utils/math/IntRange.java +++ b/src/main/java/net/minestom/server/utils/math/IntRange.java @@ -2,18 +2,19 @@ package net.minestom.server.utils.math; public class IntRange extends Range { - public IntRange(Integer minimum, Integer maximum) { - super(minimum, maximum); - } + public IntRange(Integer minimum, Integer maximum) { + super(minimum, maximum); + } - public IntRange(Integer value) { - super(value); - } + public IntRange(Integer value) { + super(value); + } - /** {@inheritDoc} */ - @Override - public boolean isInRange(Integer value) { - return value >= this.getMinimum() && value <= this.getMaximum(); - - } + /** + * {@inheritDoc} + */ + @Override + public boolean isInRange(Integer value) { + return value >= this.getMinimum() && value <= this.getMaximum(); + } } diff --git a/src/main/java/net/minestom/server/utils/math/LongRange.java b/src/main/java/net/minestom/server/utils/math/LongRange.java index bc44c17b9..459a24011 100644 --- a/src/main/java/net/minestom/server/utils/math/LongRange.java +++ b/src/main/java/net/minestom/server/utils/math/LongRange.java @@ -2,17 +2,19 @@ package net.minestom.server.utils.math; public class LongRange extends Range { - public LongRange(Long minimum, Long maximum) { - super(minimum, maximum); - } + public LongRange(Long minimum, Long maximum) { + super(minimum, maximum); + } - public LongRange(Long value) { - super(value); - } + public LongRange(Long value) { + super(value); + } - /** {@inheritDoc} */ - @Override - public boolean isInRange(Long value) { - return value >= this.getMinimum() && value <= this.getMaximum(); - } + /** + * {@inheritDoc} + */ + @Override + public boolean isInRange(Long value) { + return value >= this.getMinimum() && value <= this.getMaximum(); + } }