Cleanup, make PingPlayer immutable

This commit is contained in:
TheMode 2021-04-11 20:46:48 +02:00
parent 9f3b7d4ca8
commit db8f071633
4 changed files with 31 additions and 14 deletions

View File

@ -6,7 +6,6 @@ import net.minestom.server.entity.fakeplayer.FakePlayer;
import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;

View File

@ -41,7 +41,6 @@ public class NettyPlayerConnection extends PlayerConnection {
private SocketAddress remoteAddress; private SocketAddress remoteAddress;
private boolean encrypted = false; private boolean encrypted = false;
private boolean compressed = false; private boolean compressed = false;

View File

@ -204,7 +204,6 @@ public abstract class PlayerConnection {
return connectionState; return connectionState;
} }
/** /**
* Gets the number of packet the client sent over the last second. * Gets the number of packet the client sent over the last second.
* *

View File

@ -9,7 +9,6 @@ import net.minestom.server.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -57,6 +56,7 @@ public class ResponseData {
/** /**
* Get the version name for the response. * Get the version name for the response.
*
* @return the version name for the response. * @return the version name for the response.
*/ */
public String getVersion() { public String getVersion() {
@ -74,11 +74,13 @@ public class ResponseData {
/** /**
* Get the response protocol version. * Get the response protocol version.
*
* @return the response protocol version. * @return the response protocol version.
*/ */
public int getProtocol() { public int getProtocol() {
return protocol; return protocol;
} }
/** /**
* Sets the response maximum player count. * Sets the response maximum player count.
* *
@ -90,11 +92,13 @@ public class ResponseData {
/** /**
* Get the response maximum player count. * Get the response maximum player count.
*
* @return the response maximum player count. * @return the response maximum player count.
*/ */
public int getMaxPlayer() { public int getMaxPlayer() {
return maxPlayer; return maxPlayer;
} }
/** /**
* Sets the response online count. * Sets the response online count.
* *
@ -140,23 +144,19 @@ public class ResponseData {
* @param uuid The unique identifier of the player. * @param uuid The unique identifier of the player.
*/ */
public void addPlayer(String name, UUID uuid) { public void addPlayer(String name, UUID uuid) {
PingPlayer pingPlayer = new PingPlayer(); PingPlayer pingPlayer = PingPlayer.of(name, uuid);
pingPlayer.name = name;
pingPlayer.uuid = uuid;
this.pingPlayers.add(pingPlayer); this.pingPlayers.add(pingPlayer);
} }
/** /**
* Adds a player to the response. * Adds a player to the response.
* * <p>
* {@link UUID#randomUUID()} is used as the player's UUID. * {@link UUID#randomUUID()} is used as the player's UUID.
* *
* @param name The name of the player. * @param name The name of the player.
*/ */
public void addPlayer(String name) { public void addPlayer(String name) {
PingPlayer pingPlayer = new PingPlayer(); PingPlayer pingPlayer = PingPlayer.of(name, UUID.randomUUID());
pingPlayer.name = name;
pingPlayer.uuid = UUID.randomUUID();
this.pingPlayers.add(pingPlayer); this.pingPlayers.add(pingPlayer);
} }
@ -170,6 +170,7 @@ public class ResponseData {
/** /**
* Get the list of the response players. * Get the list of the response players.
*
* @return the list of the response players. * @return the list of the response players.
*/ */
public List<PingPlayer> getPlayers() { public List<PingPlayer> getPlayers() {
@ -207,7 +208,7 @@ public class ResponseData {
/** /**
* Sets the response favicon. * Sets the response favicon.
* * <p>
* MUST start with "data:image/png;base64," * MUST start with "data:image/png;base64,"
* *
* @param favicon The favicon for the response data. * @param favicon The favicon for the response data.
@ -218,6 +219,7 @@ public class ResponseData {
/** /**
* Get the response favicon. * Get the response favicon.
*
* @return the response favicon. * @return the response favicon.
*/ */
public String getFavicon() { public String getFavicon() {
@ -267,7 +269,25 @@ public class ResponseData {
* Represents a player line in the server list hover. * Represents a player line in the server list hover.
*/ */
public static class PingPlayer { public static class PingPlayer {
public String name;
public UUID uuid; private static @NotNull PingPlayer of(@NotNull String name, @NotNull UUID uuid) {
return new PingPlayer(name, uuid);
}
private final String name;
private final UUID uuid;
private PingPlayer(@NotNull String name, @NotNull UUID uuid) {
this.name = name;
this.uuid = uuid;
}
public @NotNull String getName() {
return name;
}
public @NotNull UUID getUuid() {
return uuid;
}
} }
} }