13
0
geforkt von Mirrors/Velocity

Grab most of the low-hanging fruit.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-12-29 17:22:36 -05:00
Ursprung f898b766f1
Commit 89bcc9a100
23 geänderte Dateien mit 143 neuen und 44 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,6 @@
package com.velocitypowered.api.proxy.server; package com.velocitypowered.api.proxy.server;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.server.QueryResponse.PluginInformation; import com.velocitypowered.api.proxy.server.QueryResponse.PluginInformation;

Datei anzeigen

@ -1,6 +1,6 @@
package com.velocitypowered.api.proxy.server; package com.velocitypowered.api.proxy.server;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.server.ServerPing.Players; import com.velocitypowered.api.proxy.server.ServerPing.Players;

Datei anzeigen

@ -1,4 +1,8 @@
checkstyle { checkstyle {
toolVersion '8.14' toolVersion '8.14'
configFile new File(project.rootDir, ['config', 'checkstyle', 'checkstyle.xml'].join(File.separator)) configFile new File(project.rootDir, ['config', 'checkstyle', 'checkstyle.xml'].join(File.separator))
// The build should immediately fail if we have errors.
maxErrors = 0
maxWarnings = 0
} }

Datei anzeigen

@ -20,6 +20,10 @@ jar {
} }
} }
tasks.withType(Checkstyle) {
exclude('**/com/velocitypowered/proxy/protocol/packet/*.java')
}
dependencies { dependencies {
// Note: we depend on the API twice, first the main sourceset, and then the annotation processor. // Note: we depend on the API twice, first the main sourceset, and then the annotation processor.
compile project(':velocity-api') compile project(':velocity-api')

Datei anzeigen

@ -123,6 +123,12 @@ public class VelocityCommandManager implements CommandManager {
} }
} }
/**
* Determines if the {@code source} has permission to run the {@code cmdLine}.
* @param source the source to check against
* @param cmdLine the command to run
* @return {@code true} if the command can be run, otherwise {@code false}
*/
public boolean hasPermission(CommandSource source, String cmdLine) { public boolean hasPermission(CommandSource source, String cmdLine) {
Preconditions.checkNotNull(source, "source"); Preconditions.checkNotNull(source, "source");
Preconditions.checkNotNull(cmdLine, "cmdLine"); Preconditions.checkNotNull(cmdLine, "cmdLine");

Datei anzeigen

@ -36,7 +36,10 @@ public abstract class AnnotatedConfig {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
public @interface Table { public @interface Table {
/**
* The table's name.
* @return the table's name
*/
String value(); String value();
} }
@ -46,7 +49,10 @@ public abstract class AnnotatedConfig {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
public @interface Comment { public @interface Comment {
/**
* The comments to include with this key. Each entry is considered a line.
* @return the comments
*/
String[] value(); String[] value();
} }
@ -56,7 +62,10 @@ public abstract class AnnotatedConfig {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.TYPE})
public @interface ConfigKey { public @interface ConfigKey {
/**
* The name of this field in the configuration.
* @return the field's name
*/
String value(); String value();
} }

Datei anzeigen

@ -356,6 +356,12 @@ public class VelocityConfiguration extends AnnotatedConfig implements ProxyConfi
.toString(); .toString();
} }
/**
* Reads the Velocity configuration from {@code path}.
* @param path the path to read from
* @return the deserialized Velocity configuration
* @throws IOException if we could not read from the {@code path}.
*/
public static VelocityConfiguration read(Path path) throws IOException { public static VelocityConfiguration read(Path path) throws IOException {
Toml toml; Toml toml;
if (!path.toFile().exists()) { if (!path.toFile().exists()) {

Datei anzeigen

@ -5,8 +5,8 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;

Datei anzeigen

@ -53,6 +53,12 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
private long lastPingId; private long lastPingId;
private long lastPingSent; private long lastPingSent;
/**
* Initializes a new server connection.
* @param registeredServer the server to connect to
* @param proxyPlayer the player connecting to the server
* @param server the Velocity proxy instance
*/
public VelocityServerConnection(VelocityRegisteredServer registeredServer, public VelocityServerConnection(VelocityRegisteredServer registeredServer,
ConnectedPlayer proxyPlayer, VelocityServer server) { ConnectedPlayer proxyPlayer, VelocityServer server) {
this.registeredServer = registeredServer; this.registeredServer = registeredServer;
@ -60,6 +66,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
this.server = server; this.server = server;
} }
/**
* Connects to the server.
* @return a {@link com.velocitypowered.api.proxy.ConnectionRequestBuilder.Result} representing
* whether or not the connect succeeded
*/
public CompletableFuture<ConnectionRequestBuilder.Result> connect() { public CompletableFuture<ConnectionRequestBuilder.Result> connect() {
CompletableFuture<ConnectionRequestBuilder.Result> result = new CompletableFuture<>(); CompletableFuture<ConnectionRequestBuilder.Result> result = new CompletableFuture<>();
server.initializeGenericBootstrap() server.initializeGenericBootstrap()
@ -167,6 +178,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
return proxyPlayer; return proxyPlayer;
} }
/**
* Disconnects from the server.
*/
public void disconnect() { public void disconnect() {
if (connection != null) { if (connection != null) {
gracefulDisconnect = true; gracefulDisconnect = true;

Datei anzeigen

@ -188,7 +188,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null; MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null;
if (serverConn != null && backendConn != null) { if (serverConn != null && backendConn != null) {
if (backendConn.getState() != StateRegistry.PLAY) { if (backendConn.getState() != StateRegistry.PLAY) {
logger.warn("Plugin message was sent while the backend was in PLAY. Channel: {}. Packet discarded."); logger.warn("A plugin message was received while the backend server was not "
+ "ready. Channel: {}. Packet discarded.", packet.getChannel());
} else if (PluginMessageUtil.isRegister(packet)) { } else if (PluginMessageUtil.isRegister(packet)) {
List<String> actuallyRegistered = new ArrayList<>(); List<String> actuallyRegistered = new ArrayList<>();
List<String> channels = PluginMessageUtil.getChannels(packet); List<String> channels = PluginMessageUtil.getChannels(packet);

Datei anzeigen

@ -1,7 +1,7 @@
package com.velocitypowered.proxy.connection.client; package com.velocitypowered.proxy.connection.client;
import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.Disconnect;

Datei anzeigen

@ -2,10 +2,10 @@ package com.velocitypowered.proxy.connection.client;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.event.proxy.ProxyPingEvent; import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.InboundConnection; import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;

Datei anzeigen

@ -14,7 +14,8 @@ public class LegacyForgeConnectionType extends ConnectionTypeImpl {
new GameProfile.Property("forgeClient", "true", ""); new GameProfile.Property("forgeClient", "true", "");
public LegacyForgeConnectionType() { public LegacyForgeConnectionType() {
super(LegacyForgeHandshakeClientPhase.NOT_STARTED, LegacyForgeHandshakeBackendPhase.NOT_STARTED); super(LegacyForgeHandshakeClientPhase.NOT_STARTED,
LegacyForgeHandshakeBackendPhase.NOT_STARTED);
} }
@Override @Override

Datei anzeigen

@ -7,7 +7,7 @@ import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase; import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
/** /**
* Indicates the type of connection that has been made * Indicates the type of connection that has been made.
*/ */
public class ConnectionTypeImpl implements ConnectionType { public class ConnectionTypeImpl implements ConnectionType {

Datei anzeigen

@ -1,5 +1,7 @@
package com.velocitypowered.proxy.console; package com.velocitypowered.proxy.console;
import static com.velocitypowered.api.permission.PermissionFunction.*;
import com.velocitypowered.api.event.permission.PermissionsSetupEvent; import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.permission.Tristate;
@ -26,7 +28,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
private static final Logger logger = LogManager.getLogger(VelocityConsole.class); private static final Logger logger = LogManager.getLogger(VelocityConsole.class);
private final VelocityServer server; private final VelocityServer server;
private PermissionFunction permissionFunction = PermissionFunction.ALWAYS_TRUE; private PermissionFunction permissionFunction = ALWAYS_TRUE;
public VelocityConsole(VelocityServer server) { public VelocityConsole(VelocityServer server) {
this.server = server; this.server = server;
@ -43,20 +45,14 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
} }
public void setupStreams() { public void setupStreams() {
System.setOut(IoBuilder.forLogger(logger) System.setOut(IoBuilder.forLogger(logger).setLevel(Level.INFO).buildPrintStream());
.setLevel(Level.INFO) System.setErr(IoBuilder.forLogger(logger).setLevel(Level.ERROR).buildPrintStream());
.buildPrintStream());
System.setErr(IoBuilder.forLogger(logger)
.setLevel(Level.ERROR)
.buildPrintStream());
} }
public void setupPermissions() { public void setupPermissions() {
PermissionsSetupEvent event = new PermissionsSetupEvent(this, PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> ALWAYS_TRUE);
s -> PermissionFunction.ALWAYS_TRUE); // we can safely block here, this is before any listeners fire
this.server.getEventManager().fire(event) this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this);
.join(); // this is called on startup, we can safely #join
this.permissionFunction = event.createFunction(this);
} }
@Override @Override

Datei anzeigen

@ -20,6 +20,11 @@ public class ServerChannelInitializerHolder implements Supplier<ChannelInitializ
return this.initializer; return this.initializer;
} }
/**
* Sets the channel initializer.
* @param initializer the new initializer to use
* @deprecated Internal implementation detail
*/
@Deprecated @Deprecated
public void set(final ChannelInitializer<Channel> initializer) { public void set(final ChannelInitializer<Channel> initializer) {
LOGGER.warn("The server channel initializer has been replaced by {}", LOGGER.warn("The server channel initializer has been replaced by {}",

Datei anzeigen

@ -8,7 +8,7 @@ import com.velocitypowered.api.plugin.PluginDescription;
import com.velocitypowered.api.plugin.PluginManager; import com.velocitypowered.api.plugin.PluginManager;
import com.velocitypowered.api.plugin.meta.PluginDependency; import com.velocitypowered.api.plugin.meta.PluginDependency;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.plugin.loader.JavaPluginLoader; import com.velocitypowered.proxy.plugin.loader.java.JavaPluginLoader;
import com.velocitypowered.proxy.plugin.util.PluginDependencyUtils; import com.velocitypowered.proxy.plugin.util.PluginDependencyUtils;
import java.io.IOException; import java.io.IOException;
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;

Datei anzeigen

@ -1,4 +1,4 @@
package com.velocitypowered.proxy.plugin.loader; package com.velocitypowered.proxy.plugin.loader.java;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -10,6 +10,9 @@ import com.velocitypowered.api.plugin.meta.PluginDependency;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.plugin.PluginClassLoader; import com.velocitypowered.proxy.plugin.PluginClassLoader;
import com.velocitypowered.proxy.plugin.loader.PluginLoader;
import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer;
import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription;
import com.velocitypowered.proxy.plugin.loader.java.JavaVelocityPluginDescription; import com.velocitypowered.proxy.plugin.loader.java.JavaVelocityPluginDescription;
import com.velocitypowered.proxy.plugin.loader.java.VelocityPluginModule; import com.velocitypowered.proxy.plugin.loader.java.VelocityPluginModule;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;

Datei anzeigen

@ -9,11 +9,11 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class JavaVelocityPluginDescription extends VelocityPluginDescription { class JavaVelocityPluginDescription extends VelocityPluginDescription {
private final Class<?> mainClass; private final Class<?> mainClass;
public JavaVelocityPluginDescription(String id, @Nullable String name, @Nullable String version, JavaVelocityPluginDescription(String id, @Nullable String name, @Nullable String version,
@Nullable String description, @Nullable String url, @Nullable String description, @Nullable String url,
@Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source, @Nullable List<String> authors, Collection<PluginDependency> dependencies, Path source,
Class<?> mainClass) { Class<?> mainClass) {
@ -21,7 +21,7 @@ public class JavaVelocityPluginDescription extends VelocityPluginDescription {
this.mainClass = checkNotNull(mainClass); this.mainClass = checkNotNull(mainClass);
} }
public Class<?> getMainClass() { Class<?> getMainClass() {
return mainClass; return mainClass;
} }
} }

Datei anzeigen

@ -12,13 +12,13 @@ import java.nio.file.Path;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class VelocityPluginModule implements Module { class VelocityPluginModule implements Module {
private final ProxyServer server; private final ProxyServer server;
private final JavaVelocityPluginDescription description; private final JavaVelocityPluginDescription description;
private final Path basePluginPath; private final Path basePluginPath;
public VelocityPluginModule(ProxyServer server, JavaVelocityPluginDescription description, VelocityPluginModule(ProxyServer server, JavaVelocityPluginDescription description,
Path basePluginPath) { Path basePluginPath) {
this.server = server; this.server = server;
this.description = description; this.description = description;

Datei anzeigen

@ -83,6 +83,11 @@ public enum ProtocolUtils {
return str; return str;
} }
/**
* Writes the specified {@code str} to the {@code buf} with a VarInt prefix.
* @param buf the buffer to write to
* @param str the string to write
*/
public static void writeString(ByteBuf buf, String str) { public static void writeString(ByteBuf buf, String str) {
int size = ByteBufUtil.utf8Bytes(str); int size = ByteBufUtil.utf8Bytes(str);
writeVarInt(buf, size); writeVarInt(buf, size);
@ -93,6 +98,13 @@ public enum ProtocolUtils {
return readByteArray(buf, DEFAULT_MAX_STRING_SIZE); return readByteArray(buf, DEFAULT_MAX_STRING_SIZE);
} }
/**
* Reads a VarInt length-prefixed byte array from the {@code buf}, making sure to not go over
* {@code cap} size.
* @param buf the buffer to read from
* @param cap the maximum size of the string, in UTF-8 character length
* @return the byte array
*/
public static byte[] readByteArray(ByteBuf buf, int cap) { public static byte[] readByteArray(ByteBuf buf, int cap) {
int length = readVarInt(buf); int length = readVarInt(buf);
checkArgument(length <= cap, "Bad string size (got %s, maximum is %s)", length, cap); checkArgument(length <= cap, "Bad string size (got %s, maximum is %s)", length, cap);
@ -109,6 +121,11 @@ public enum ProtocolUtils {
buf.writeBytes(array); buf.writeBytes(array);
} }
/**
* Reads an VarInt-prefixed array of VarInt integers from the {@code buf}.
* @param buf the buffer to read from
* @return an array of integers
*/
public static int[] readIntegerArray(ByteBuf buf) { public static int[] readIntegerArray(ByteBuf buf) {
int len = readVarInt(buf); int len = readVarInt(buf);
int[] array = new int[len]; int[] array = new int[len];
@ -118,13 +135,11 @@ public enum ProtocolUtils {
return array; return array;
} }
public static void writeIntegerArray(ByteBuf buf, int[] array) { /**
writeVarInt(buf, array.length); * Reads an UUID from the {@code buf}.
for (int i : array) { * @param buf the buffer to read from
writeVarInt(buf, i); * @return the UUID from the buffer
} */
}
public static UUID readUuid(ByteBuf buf) { public static UUID readUuid(ByteBuf buf) {
long msb = buf.readLong(); long msb = buf.readLong();
long lsb = buf.readLong(); long lsb = buf.readLong();
@ -136,6 +151,11 @@ public enum ProtocolUtils {
buf.writeLong(uuid.getLeastSignificantBits()); buf.writeLong(uuid.getLeastSignificantBits());
} }
/**
* Writes a list of {@link com.velocitypowered.api.util.GameProfile.Property} to the buffer.
* @param buf the buffer to write to
* @param properties the properties to serialize
*/
public static void writeProperties(ByteBuf buf, List<GameProfile.Property> properties) { public static void writeProperties(ByteBuf buf, List<GameProfile.Property> properties) {
writeVarInt(buf, properties.size()); writeVarInt(buf, properties.size());
for (GameProfile.Property property : properties) { for (GameProfile.Property property : properties) {
@ -151,6 +171,11 @@ public enum ProtocolUtils {
} }
} }
/**
* Reads a list of {@link com.velocitypowered.api.util.GameProfile.Property} from the buffer.
* @param buf the buffer to read from
* @return the read properties
*/
public static List<GameProfile.Property> readProperties(ByteBuf buf) { public static List<GameProfile.Property> readProperties(ByteBuf buf) {
List<GameProfile.Property> properties = new ArrayList<>(); List<GameProfile.Property> properties = new ArrayList<>();
int size = readVarInt(buf); int size = readVarInt(buf);
@ -172,9 +197,9 @@ public enum ProtocolUtils {
CLIENTBOUND; CLIENTBOUND;
public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(StateRegistry state, public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(StateRegistry state,
ProtocolVersion protocolVersion) { ProtocolVersion version) {
return (this == SERVERBOUND ? state.serverbound : state.clientbound) return (this == SERVERBOUND ? state.serverbound : state.clientbound)
.getProtocolRegistry(protocolVersion); .getProtocolRegistry(version);
} }
} }
} }

Datei anzeigen

@ -50,7 +50,12 @@ import io.netty.util.collection.IntObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.util.*; import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -245,7 +250,7 @@ public enum StateRegistry {
this.versions = Collections.unmodifiableMap(mutableVersions); this.versions = Collections.unmodifiableMap(mutableVersions);
} }
public ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) { ProtocolRegistry getProtocolRegistry(final ProtocolVersion version) {
ProtocolRegistry registry = versions.get(version); ProtocolRegistry registry = versions.get(version);
if (registry == null) { if (registry == null) {
if (fallback) { if (fallback) {
@ -256,7 +261,7 @@ public enum StateRegistry {
return registry; return registry;
} }
public <P extends MinecraftPacket> void register(Class<P> clazz, Supplier<P> packetSupplier, <P extends MinecraftPacket> void register(Class<P> clazz, Supplier<P> packetSupplier,
PacketMapping... mappings) { PacketMapping... mappings) {
if (mappings.length == 0) { if (mappings.length == 0) {
throw new IllegalArgumentException("At least one mapping must be provided."); throw new IllegalArgumentException("At least one mapping must be provided.");
@ -301,6 +306,11 @@ public enum StateRegistry {
this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE); this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE);
} }
/**
* Attempts to create a packet from the specified {@code id}.
* @param id the packet ID
* @return the packet instance, or {@code null} if the ID is not registered
*/
public @Nullable MinecraftPacket createPacket(final int id) { public @Nullable MinecraftPacket createPacket(final int id) {
final Supplier<? extends MinecraftPacket> supplier = this.packetIdToSupplier.get(id); final Supplier<? extends MinecraftPacket> supplier = this.packetIdToSupplier.get(id);
if (supplier == null) { if (supplier == null) {
@ -309,6 +319,12 @@ public enum StateRegistry {
return supplier.get(); return supplier.get();
} }
/**
* Attempts to look up the packet ID for an {@code packet}.
* @param packet the packet to look up
* @return the packet ID
* @throws IllegalArgumentException if the packet ID is not found
*/
public int getPacketId(final MinecraftPacket packet) { public int getPacketId(final MinecraftPacket packet) {
final int id = this.packetClassToId.getInt(packet.getClass()); final int id = this.packetClassToId.getInt(packet.getClass());
if (id == Integer.MIN_VALUE) { if (id == Integer.MIN_VALUE) {
@ -328,7 +344,7 @@ public enum StateRegistry {
private final ProtocolVersion protocolVersion; private final ProtocolVersion protocolVersion;
private final boolean encodeOnly; private final boolean encodeOnly;
public PacketMapping(int id, ProtocolVersion protocolVersion, boolean packetDecoding) { PacketMapping(int id, ProtocolVersion protocolVersion, boolean packetDecoding) {
this.id = id; this.id = id;
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
this.encodeOnly = packetDecoding; this.encodeOnly = packetDecoding;

Datei anzeigen

@ -65,7 +65,12 @@ public class VelocityTabList implements TabList {
return Optional.ofNullable(entry); return Optional.ofNullable(entry);
} }
public void clearAll() { // Note: this method is called upon server switch /**
* Clears all entries from the tab list. Note that the entries are written with
* {@link MinecraftConnection#delayedWrite(Object)}, so make sure to do an explicit
* {@link MinecraftConnection#flush()}.
*/
public void clearAll() {
List<PlayerListItem.Item> items = new ArrayList<>(); List<PlayerListItem.Item> items = new ArrayList<>();
for (TabListEntry value : entries.values()) { for (TabListEntry value : entries.values()) {
items.add(PlayerListItem.Item.from(value)); items.add(PlayerListItem.Item.from(value));
@ -85,6 +90,10 @@ public class VelocityTabList implements TabList {
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode); return new VelocityTabListEntry(this, profile, displayName, latency, gameMode);
} }
/**
* Processes a tab list entry packet from the backend.
* @param packet the packet to process
*/
public void processBackendPacket(PlayerListItem packet) { public void processBackendPacket(PlayerListItem packet) {
// Packets are already forwarded on, so no need to do that here // Packets are already forwarded on, so no need to do that here
for (PlayerListItem.Item item : packet.getItems()) { for (PlayerListItem.Item item : packet.getItems()) {