mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Minor formatting and javadoc changes
This commit is contained in:
parent
2968ea2513
commit
42933e58b0
@ -6,7 +6,7 @@ import net.minestom.server.event.Event;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.ping.ResponseData;
|
||||
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.Nullable;
|
||||
|
||||
@ -18,7 +18,7 @@ import java.util.Objects;
|
||||
*/
|
||||
public class ServerListPingEvent extends Event implements CancellableEvent {
|
||||
private final PlayerConnection connection;
|
||||
private final ServerListPingVersion version;
|
||||
private final ServerListPingType type;
|
||||
|
||||
private boolean cancelled = false;
|
||||
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.
|
||||
*
|
||||
* @param version the ping version to respond with
|
||||
* @param type the ping type to respond with
|
||||
*/
|
||||
public ServerListPingEvent(@NotNull ServerListPingVersion version) {
|
||||
this(null, version);
|
||||
public ServerListPingEvent(@NotNull ServerListPingType type) {
|
||||
this(null, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new server list ping event.
|
||||
*
|
||||
* @param connection the player connection, if the ping version is modern
|
||||
* @param version the ping version to respond with
|
||||
* @param connection the player connection, if the ping type is modern
|
||||
* @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
|
||||
ResponseDataConsumer consumer = MinecraftServer.getResponseDataConsumer();
|
||||
this.responseData = new ResponseData();
|
||||
@ -48,7 +48,7 @@ public class ServerListPingEvent extends Event implements CancellableEvent {
|
||||
}
|
||||
|
||||
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
|
||||
* @see ServerListPingVersion
|
||||
* @return the ping type
|
||||
*/
|
||||
public @NotNull ServerListPingVersion getPingVersion() {
|
||||
return version;
|
||||
public @NotNull ServerListPingType getPingType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@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.
|
||||
* 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
|
||||
*/
|
||||
|
@ -10,10 +10,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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.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
|
||||
@ -51,6 +55,8 @@ public class OpenToLAN {
|
||||
* @return {@code true} if it was opened successfully, {@code false} otherwise
|
||||
*/
|
||||
public static boolean open(@NotNull OpenToLANConfig config) {
|
||||
Objects.requireNonNull(config, "config");
|
||||
|
||||
if (socket != null) {
|
||||
return false;
|
||||
} else {
|
||||
|
@ -1,15 +1,16 @@
|
||||
package net.minestom.server.extras.lan;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minestom.server.event.server.ServerListPingEvent;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Configuration for opening the server to LAN.
|
||||
*
|
||||
* @see OpenToLAN#open(OpenToLANConfig)
|
||||
*/
|
||||
public class OpenToLANConfig {
|
||||
|
@ -109,7 +109,7 @@ public class FullQueryResponse implements QueryResponse {
|
||||
* @param players the players
|
||||
*/
|
||||
public void setPlayers(@NotNull List<String> players) {
|
||||
this.players = Objects.requireNonNull(players, "players)");
|
||||
this.players = Objects.requireNonNull(players, "players");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
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 java.nio.charset.StandardCharsets;
|
||||
@ -39,12 +39,12 @@ public class LegacyPingHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
switch (length) {
|
||||
case 0:
|
||||
if (trySendResponse(ServerListPingVersion.LEGACY, ctx)) return;
|
||||
if (trySendResponse(ServerListPingType.LEGACY_UNVERSIONED, ctx)) return;
|
||||
break;
|
||||
case 1:
|
||||
if (buf.readUnsignedByte() != 1) return;
|
||||
|
||||
if (trySendResponse(ServerListPingVersion.LEGACY_VERSIONED, ctx)) return;
|
||||
if (trySendResponse(ServerListPingType.LEGACY_VERSIONED, ctx)) return;
|
||||
break;
|
||||
default:
|
||||
if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) return;
|
||||
@ -114,7 +114,7 @@ public class LegacyPingHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
this.buf = null;
|
||||
|
||||
trySendResponse(ServerListPingVersion.LEGACY_VERSIONED, ctx);
|
||||
trySendResponse(ServerListPingType.LEGACY_VERSIONED, ctx);
|
||||
}
|
||||
|
||||
private void removeHandler(ChannelHandlerContext ctx) {
|
||||
@ -141,7 +141,7 @@ public class LegacyPingHandler extends ChannelInboundHandlerAdapter {
|
||||
* @param ctx the context
|
||||
* @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);
|
||||
MinecraftServer.getGlobalEventHandler().callEvent(ServerListPingEvent.class, event);
|
||||
|
||||
|
@ -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.server.handshake.ResponsePacket;
|
||||
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.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -14,7 +14,7 @@ public class StatusRequestPacket implements ClientPreplayPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
MinecraftServer.getGlobalEventHandler().callCancellableEvent(ServerListPingEvent.class, statusRequestEvent, () -> {
|
||||
final ResponsePacket responsePacket = new ResponsePacket();
|
||||
|
@ -14,7 +14,7 @@ import java.util.*;
|
||||
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
|
||||
*/
|
||||
@ -47,7 +47,7 @@ public class ResponseData {
|
||||
* Sets the name for the response.
|
||||
*
|
||||
* @param name The name for the response data.
|
||||
* @deprecated Use {@link #setVersion(String)}
|
||||
* @deprecated This is named incorrectly, use {@link #setVersion(String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setName(String name) {
|
||||
@ -130,7 +130,7 @@ public class ResponseData {
|
||||
* Adds some players to the response.
|
||||
*
|
||||
* @param players the players
|
||||
* @deprecated See {@link #addEntries(Collection)}}
|
||||
* @deprecated Use {@link #addEntries(Collection)}}
|
||||
*/
|
||||
@Deprecated
|
||||
public void addPlayer(Iterable<Player> players) {
|
||||
@ -143,7 +143,7 @@ public class ResponseData {
|
||||
* Adds a player to the response.
|
||||
*
|
||||
* @param player the player
|
||||
* @deprecated See {@link #addEntry(NamedAndIdentified)}
|
||||
* @deprecated Use {@link #addEntry(NamedAndIdentified)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void addPlayer(Player player) {
|
||||
@ -155,7 +155,7 @@ public class ResponseData {
|
||||
*
|
||||
* @param name The name 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
|
||||
public void addPlayer(String name, UUID uuid) {
|
||||
@ -168,7 +168,7 @@ public class ResponseData {
|
||||
* {@link UUID#randomUUID()} is used as the player's UUID.
|
||||
*
|
||||
* @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
|
||||
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
|
||||
* will be empty this call returns.
|
||||
*
|
||||
* @deprecated See {@link #clearEntries()}
|
||||
* @deprecated Use {@link #clearEntries()}
|
||||
*/
|
||||
@Deprecated
|
||||
public void clearPlayers() {
|
||||
@ -190,7 +190,7 @@ public class ResponseData {
|
||||
* Get 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*
|
||||
public List<PingPlayer> getPlayers() {
|
||||
@ -298,11 +298,11 @@ public class ResponseData {
|
||||
* Converts the response data into a {@link JsonObject}.
|
||||
*
|
||||
* @return The converted response data as a json tree.
|
||||
* @deprecated Use {@link ServerListPingVersion#getPingResponse(ResponseData)}
|
||||
* @deprecated Use {@link ServerListPingType#getPingResponse(ResponseData)}
|
||||
*/
|
||||
@Deprecated
|
||||
public @NotNull JsonObject build() {
|
||||
return ServerListPingVersion.getModernPingResponse(this, true);
|
||||
return ServerListPingType.getModernPingResponse(this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.event.server.ServerListPingEvent;
|
||||
import net.minestom.server.extras.lan.OpenToLAN;
|
||||
import net.minestom.server.utils.identity.NamedAndIdentified;
|
||||
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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@ -35,18 +37,18 @@ public enum ServerListPingVersion {
|
||||
/**
|
||||
* 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.
|
||||
* Only the description formatted as a legacy string is sent.
|
||||
* 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;
|
||||
|
||||
ServerListPingVersion(@NotNull Function<ResponseData, String> pingResponseCreator) {
|
||||
ServerListPingType(@NotNull Function<ResponseData, String> pingResponseCreator) {
|
||||
this.pingResponseCreator = pingResponseCreator;
|
||||
}
|
||||
|
||||
@ -145,7 +147,7 @@ public enum ServerListPingVersion {
|
||||
* @param version the protocol 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) {
|
||||
return MODERN_FULL_RGB;
|
||||
} else {
|
@ -65,4 +65,4 @@ class NamedAndIdentifiedImpl implements NamedAndIdentified {
|
||||
public String toString() {
|
||||
return String.format("NamedAndIdentifiedImpl{name='%s', uuid=%s}", this.name, this.uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user