Minor formatting and javadoc changes

This commit is contained in:
Kieran Wallbanks 2021-05-05 15:53:47 +01:00
parent 2968ea2513
commit 42933e58b0
9 changed files with 51 additions and 43 deletions

View File

@ -6,7 +6,7 @@ import net.minestom.server.event.Event;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.ping.ResponseData; import net.minestom.server.ping.ResponseData;
import net.minestom.server.ping.ResponseDataConsumer; import net.minestom.server.ping.ResponseDataConsumer;
import net.minestom.server.ping.ServerListPingVersion; import net.minestom.server.ping.ServerListPingType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -18,7 +18,7 @@ import java.util.Objects;
*/ */
public class ServerListPingEvent extends Event implements CancellableEvent { public class ServerListPingEvent extends Event implements CancellableEvent {
private final PlayerConnection connection; private final PlayerConnection connection;
private final ServerListPingVersion version; private final ServerListPingType type;
private boolean cancelled = false; private boolean cancelled = false;
private ResponseData responseData; private ResponseData responseData;
@ -26,19 +26,19 @@ public class ServerListPingEvent extends Event implements CancellableEvent {
/** /**
* Creates a new server list ping event with no player connection. * Creates a new server list ping event with no player connection.
* *
* @param version the ping version to respond with * @param type the ping type to respond with
*/ */
public ServerListPingEvent(@NotNull ServerListPingVersion version) { public ServerListPingEvent(@NotNull ServerListPingType type) {
this(null, version); this(null, type);
} }
/** /**
* Creates a new server list ping event. * Creates a new server list ping event.
* *
* @param connection the player connection, if the ping version is modern * @param connection the player connection, if the ping type is modern
* @param version the ping version to respond with * @param type the ping type to respond with
*/ */
public ServerListPingEvent(@Nullable PlayerConnection connection, @NotNull ServerListPingVersion version) { public ServerListPingEvent(@Nullable PlayerConnection connection, @NotNull ServerListPingType type) {
//noinspection deprecation we need to continue doing this until the consumer is removed - todo remove //noinspection deprecation we need to continue doing this until the consumer is removed - todo remove
ResponseDataConsumer consumer = MinecraftServer.getResponseDataConsumer(); ResponseDataConsumer consumer = MinecraftServer.getResponseDataConsumer();
this.responseData = new ResponseData(); this.responseData = new ResponseData();
@ -48,7 +48,7 @@ public class ServerListPingEvent extends Event implements CancellableEvent {
} }
this.connection = connection; this.connection = connection;
this.version = version; this.type = type;
} }
/** /**
@ -81,13 +81,12 @@ public class ServerListPingEvent extends Event implements CancellableEvent {
} }
/** /**
* Gets the ping version that the client is pinging with. * Gets the ping type that the client is pinging with.
* *
* @return the ping version * @return the ping type
* @see ServerListPingVersion
*/ */
public @NotNull ServerListPingVersion getPingVersion() { public @NotNull ServerListPingType getPingType() {
return version; return type;
} }
@Override @Override
@ -97,7 +96,7 @@ public class ServerListPingEvent extends Event implements CancellableEvent {
/** /**
* Cancelling this event will cause the server to appear offline in the vanilla server list. * Cancelling this event will cause the server to appear offline in the vanilla server list.
* Note that this will have no effect if the ping version is {@link ServerListPingVersion#OPEN_TO_LAN}. * Note that this will have no effect if the ping version is {@link ServerListPingType#OPEN_TO_LAN}.
* *
* @param cancel true if the event should be cancelled, false otherwise * @param cancel true if the event should be cancelled, false otherwise
*/ */

View File

@ -10,10 +10,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.net.*; import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects;
import static net.minestom.server.ping.ServerListPingVersion.OPEN_TO_LAN; import static net.minestom.server.ping.ServerListPingType.OPEN_TO_LAN;
/** /**
* Utility class to manage opening the server to LAN. Note that this <b>doesn't</b> actually * Utility class to manage opening the server to LAN. Note that this <b>doesn't</b> actually
@ -51,6 +55,8 @@ public class OpenToLAN {
* @return {@code true} if it was opened successfully, {@code false} otherwise * @return {@code true} if it was opened successfully, {@code false} otherwise
*/ */
public static boolean open(@NotNull OpenToLANConfig config) { public static boolean open(@NotNull OpenToLANConfig config) {
Objects.requireNonNull(config, "config");
if (socket != null) { if (socket != null) {
return false; return false;
} else { } else {

View File

@ -1,15 +1,16 @@
package net.minestom.server.extras.lan; package net.minestom.server.extras.lan;
import java.util.Objects;
import net.minestom.server.event.server.ServerListPingEvent; import net.minestom.server.event.server.ServerListPingEvent;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption; import net.minestom.server.utils.time.UpdateOption;
import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/** /**
* Configuration for opening the server to LAN. * Configuration for opening the server to LAN.
*
* @see OpenToLAN#open(OpenToLANConfig) * @see OpenToLAN#open(OpenToLANConfig)
*/ */
public class OpenToLANConfig { public class OpenToLANConfig {

View File

@ -109,7 +109,7 @@ public class FullQueryResponse implements QueryResponse {
* @param players the players * @param players the players
*/ */
public void setPlayers(@NotNull List<String> players) { public void setPlayers(@NotNull List<String> players) {
this.players = Objects.requireNonNull(players, "players)"); this.players = Objects.requireNonNull(players, "players");
} }
/** /**

View File

@ -7,7 +7,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.event.server.ServerListPingEvent; import net.minestom.server.event.server.ServerListPingEvent;
import net.minestom.server.ping.ServerListPingVersion; import net.minestom.server.ping.ServerListPingType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -39,12 +39,12 @@ public class LegacyPingHandler extends ChannelInboundHandlerAdapter {
switch (length) { switch (length) {
case 0: case 0:
if (trySendResponse(ServerListPingVersion.LEGACY, ctx)) return; if (trySendResponse(ServerListPingType.LEGACY_UNVERSIONED, ctx)) return;
break; break;
case 1: case 1:
if (buf.readUnsignedByte() != 1) return; if (buf.readUnsignedByte() != 1) return;
if (trySendResponse(ServerListPingVersion.LEGACY_VERSIONED, ctx)) return; if (trySendResponse(ServerListPingType.LEGACY_VERSIONED, ctx)) return;
break; break;
default: default:
if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) return; if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) return;
@ -114,7 +114,7 @@ public class LegacyPingHandler extends ChannelInboundHandlerAdapter {
this.buf = null; this.buf = null;
trySendResponse(ServerListPingVersion.LEGACY_VERSIONED, ctx); trySendResponse(ServerListPingType.LEGACY_VERSIONED, ctx);
} }
private void removeHandler(ChannelHandlerContext ctx) { private void removeHandler(ChannelHandlerContext ctx) {
@ -141,7 +141,7 @@ public class LegacyPingHandler extends ChannelInboundHandlerAdapter {
* @param ctx the context * @param ctx the context
* @return {@code true} if the response was cancelled, {@code false} otherwise * @return {@code true} if the response was cancelled, {@code false} otherwise
*/ */
private static boolean trySendResponse(@NotNull ServerListPingVersion version, @NotNull ChannelHandlerContext ctx) { private static boolean trySendResponse(@NotNull ServerListPingType version, @NotNull ChannelHandlerContext ctx) {
final ServerListPingEvent event = new ServerListPingEvent(version); final ServerListPingEvent event = new ServerListPingEvent(version);
MinecraftServer.getGlobalEventHandler().callEvent(ServerListPingEvent.class, event); MinecraftServer.getGlobalEventHandler().callEvent(ServerListPingEvent.class, event);

View File

@ -5,7 +5,7 @@ import net.minestom.server.event.server.ServerListPingEvent;
import net.minestom.server.network.packet.client.ClientPreplayPacket; import net.minestom.server.network.packet.client.ClientPreplayPacket;
import net.minestom.server.network.packet.server.handshake.ResponsePacket; import net.minestom.server.network.packet.server.handshake.ResponsePacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.ping.ServerListPingVersion; import net.minestom.server.ping.ServerListPingType;
import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -14,7 +14,7 @@ public class StatusRequestPacket implements ClientPreplayPacket {
@Override @Override
public void process(@NotNull PlayerConnection connection) { public void process(@NotNull PlayerConnection connection) {
final ServerListPingVersion pingVersion = ServerListPingVersion.fromModernProtocolVersion(connection.getProtocolVersion()); final ServerListPingType pingVersion = ServerListPingType.fromModernProtocolVersion(connection.getProtocolVersion());
final ServerListPingEvent statusRequestEvent = new ServerListPingEvent(connection, pingVersion); final ServerListPingEvent statusRequestEvent = new ServerListPingEvent(connection, pingVersion);
MinecraftServer.getGlobalEventHandler().callCancellableEvent(ServerListPingEvent.class, statusRequestEvent, () -> { MinecraftServer.getGlobalEventHandler().callCancellableEvent(ServerListPingEvent.class, statusRequestEvent, () -> {
final ResponsePacket responsePacket = new ResponsePacket(); final ResponsePacket responsePacket = new ResponsePacket();

View File

@ -14,7 +14,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* Represents the data sent to the player when refreshing the server list. * Represents the data sent to the player when responding to a ping event.
* *
* @see ServerListPingEvent * @see ServerListPingEvent
*/ */
@ -47,7 +47,7 @@ public class ResponseData {
* Sets the name for the response. * Sets the name for the response.
* *
* @param name The name for the response data. * @param name The name for the response data.
* @deprecated Use {@link #setVersion(String)} * @deprecated This is named incorrectly, use {@link #setVersion(String)} instead
*/ */
@Deprecated @Deprecated
public void setName(String name) { public void setName(String name) {
@ -130,7 +130,7 @@ public class ResponseData {
* Adds some players to the response. * Adds some players to the response.
* *
* @param players the players * @param players the players
* @deprecated See {@link #addEntries(Collection)}} * @deprecated Use {@link #addEntries(Collection)}}
*/ */
@Deprecated @Deprecated
public void addPlayer(Iterable<Player> players) { public void addPlayer(Iterable<Player> players) {
@ -143,7 +143,7 @@ public class ResponseData {
* Adds a player to the response. * Adds a player to the response.
* *
* @param player the player * @param player the player
* @deprecated See {@link #addEntry(NamedAndIdentified)} * @deprecated Use {@link #addEntry(NamedAndIdentified)}
*/ */
@Deprecated @Deprecated
public void addPlayer(Player player) { public void addPlayer(Player player) {
@ -155,7 +155,7 @@ public class ResponseData {
* *
* @param name The name of the player. * @param name The name of the player.
* @param uuid The unique identifier of the player. * @param uuid The unique identifier of the player.
* @deprecated See {@link #addEntry(NamedAndIdentified)} using {@link NamedAndIdentified#of(String, UUID)} * @deprecated Use {@link #addEntry(NamedAndIdentified)} with {@link NamedAndIdentified#of(String, UUID)}
*/ */
@Deprecated @Deprecated
public void addPlayer(String name, UUID uuid) { public void addPlayer(String name, UUID uuid) {
@ -168,7 +168,7 @@ public class ResponseData {
* {@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.
* @deprecated See {@link #addEntry(NamedAndIdentified)} using {@link NamedAndIdentified#named(String)} * @deprecated Use {@link #addEntry(NamedAndIdentified)} with {@link NamedAndIdentified#named(String)}
*/ */
@Deprecated @Deprecated
public void addPlayer(String name) { public void addPlayer(String name) {
@ -179,7 +179,7 @@ public class ResponseData {
* Removes all of the ping players from this {@link #entries}. The {@link #entries} list * Removes all of the ping players from this {@link #entries}. The {@link #entries} list
* will be empty this call returns. * will be empty this call returns.
* *
* @deprecated See {@link #clearEntries()} * @deprecated Use {@link #clearEntries()}
*/ */
@Deprecated @Deprecated
public void clearPlayers() { public void clearPlayers() {
@ -190,7 +190,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.
* @deprecated See {@link #getEntries()}. This return value is now unmodifiable and this operation is incredibly costly. * @deprecated Use {@link #getEntries()}. This return value is now unmodifiable and this operation is incredibly costly.
*/ */
@Deprecated(forRemoval = true) // to throw an error for people using it - this method is *horrible* @Deprecated(forRemoval = true) // to throw an error for people using it - this method is *horrible*
public List<PingPlayer> getPlayers() { public List<PingPlayer> getPlayers() {
@ -298,11 +298,11 @@ public class ResponseData {
* Converts the response data into a {@link JsonObject}. * Converts the response data into a {@link JsonObject}.
* *
* @return The converted response data as a json tree. * @return The converted response data as a json tree.
* @deprecated Use {@link ServerListPingVersion#getPingResponse(ResponseData)} * @deprecated Use {@link ServerListPingType#getPingResponse(ResponseData)}
*/ */
@Deprecated @Deprecated
public @NotNull JsonObject build() { public @NotNull JsonObject build() {
return ServerListPingVersion.getModernPingResponse(this, true); return ServerListPingType.getModernPingResponse(this, true);
} }
/** /**

View File

@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.event.server.ServerListPingEvent;
import net.minestom.server.extras.lan.OpenToLAN; import net.minestom.server.extras.lan.OpenToLAN;
import net.minestom.server.utils.identity.NamedAndIdentified; import net.minestom.server.utils.identity.NamedAndIdentified;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -15,8 +16,9 @@ import java.util.function.Function;
* An enum containing the different types of server list ping responses. * An enum containing the different types of server list ping responses.
* *
* @see <a href="https://wiki.vg/Server_List_Ping">https://wiki.vg/Server_List_Ping</a> * @see <a href="https://wiki.vg/Server_List_Ping">https://wiki.vg/Server_List_Ping</a>
* @see ServerListPingEvent
*/ */
public enum ServerListPingVersion { public enum ServerListPingType {
/** /**
* The client is on version 1.16 or higher and supports full RGB with JSON text formatting. * The client is on version 1.16 or higher and supports full RGB with JSON text formatting.
*/ */
@ -35,18 +37,18 @@ public enum ServerListPingVersion {
/** /**
* The client is on version 1.5 or lower and supports a description and the player count. * The client is on version 1.5 or lower and supports a description and the player count.
*/ */
LEGACY(data -> getLegacyPingResponse(data, false)), LEGACY_UNVERSIONED(data -> getLegacyPingResponse(data, false)),
/** /**
* The ping that is sent when {@link OpenToLAN} is enabled and sending packets. * The ping that is sent when {@link OpenToLAN} is enabled and sending packets.
* Only the description formatted as a legacy string is sent. * Only the description formatted as a legacy string is sent.
* Ping events with this ping version are <b>not</b> cancellable. * Ping events with this ping version are <b>not</b> cancellable.
*/ */
OPEN_TO_LAN(ServerListPingVersion::getOpenToLANPing); OPEN_TO_LAN(ServerListPingType::getOpenToLANPing);
private final Function<ResponseData, String> pingResponseCreator; private final Function<ResponseData, String> pingResponseCreator;
ServerListPingVersion(@NotNull Function<ResponseData, String> pingResponseCreator) { ServerListPingType(@NotNull Function<ResponseData, String> pingResponseCreator) {
this.pingResponseCreator = pingResponseCreator; this.pingResponseCreator = pingResponseCreator;
} }
@ -145,7 +147,7 @@ public enum ServerListPingVersion {
* @param version the protocol version * @param version the protocol version
* @return the corresponding server list ping version * @return the corresponding server list ping version
*/ */
public static @NotNull ServerListPingVersion fromModernProtocolVersion(int version) { public static @NotNull ServerListPingType fromModernProtocolVersion(int version) {
if (version >= 713) { if (version >= 713) {
return MODERN_FULL_RGB; return MODERN_FULL_RGB;
} else { } else {

View File

@ -65,4 +65,4 @@ class NamedAndIdentifiedImpl implements NamedAndIdentified {
public String toString() { public String toString() {
return String.format("NamedAndIdentifiedImpl{name='%s', uuid=%s}", this.name, this.uuid); return String.format("NamedAndIdentifiedImpl{name='%s', uuid=%s}", this.name, this.uuid);
} }
} }