Style cleanup

This commit is contained in:
themode 2021-01-26 15:53:03 +01:00
parent 73c53a9b17
commit 7a54b4162d
11 changed files with 240 additions and 216 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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<PingPlayer> 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<PingPlayer> 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;
}
}

View File

@ -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();
}

View File

@ -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<String> 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 <br>
* 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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -2,17 +2,19 @@ package net.minestom.server.utils.math;
public class ByteRange extends Range<Byte> {
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();
}
}

View File

@ -2,17 +2,19 @@ package net.minestom.server.utils.math;
public class DoubleRange extends Range<Double> {
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();
}
}

View File

@ -2,18 +2,19 @@ package net.minestom.server.utils.math;
public class IntRange extends Range<Integer> {
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();
}
}

View File

@ -2,17 +2,19 @@ package net.minestom.server.utils.math;
public class LongRange extends Range<Long> {
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();
}
}