From 9e59ef4c4ae90d592c57db394b666e442aaa469a Mon Sep 17 00:00:00 2001 From: KennyTV Date: Wed, 28 Apr 2021 21:12:19 +0200 Subject: [PATCH] Hold the rest of the primitive Type instances under their actual class This brings no improvement now, but if primitive read/write methods for manual calls were implemented later, a signature break will have been prevented by this (aka breaking it now) --- .../com/viaversion/viaversion/api/ViaAPI.java | 24 +++++++++++++------ .../viaversion/viaversion/api/type/Type.java | 14 +++++------ .../com/viaversion/viaversion/ViaAPIBase.java | 10 ++++++-- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java index 89420a9dc..f5984ce31 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java @@ -23,11 +23,13 @@ package com.viaversion.viaversion.api; import com.viaversion.viaversion.api.connection.ConnectionManager; +import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.legacy.LegacyViaAPI; import com.viaversion.viaversion.api.platform.ViaPlatform; import com.viaversion.viaversion.api.protocol.ProtocolManager; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; import io.netty.buffer.ByteBuf; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.SortedSet; import java.util.UUID; @@ -35,7 +37,7 @@ import java.util.UUID; /** * General api point. For more specialized api methods, see {@link Via#getManager()}. * - * @param The player type for the specific platform, for bukkit it's {@code ViaAPI} + * @param player type for the specific platform * @see ViaManager * @see ProtocolManager * @see ConnectionManager @@ -51,7 +53,7 @@ public interface ViaAPI { ServerProtocolVersion getServerVersion(); /** - * Returns the protocol version from a player. + * Returns the protocol version of a player. * This will also retrieve the version from ProtocolSupport if it's being used. * * @param player the platform's player object, e.g. Bukkit this is Player @@ -60,7 +62,7 @@ public interface ViaAPI { int getPlayerVersion(T player); /** - * Returns the protocol version from a player. + * Returns the protocol version of a player. * * @param uuid UUID of a player * @return protocol version, for example (47=1.8-1.8.8, 107=1.9, 108=1.9.1), or -1 if not connected @@ -68,12 +70,20 @@ public interface ViaAPI { int getPlayerVersion(UUID uuid); /** - * Returns if Via injected into this player connection. + * Returns whether Via injected into this player connection. * - * @param playerUUID UUID of a player - * @return true if Via has a cached UserConnection for this player + * @param uuid uuid of the player + * @return whether Via has a cached a UserConnection for this player */ - boolean isInjected(UUID playerUUID); + boolean isInjected(UUID uuid); + + /** + * Returns the Via injected UserConnection if present. + * + * @param uuid uuid of the player + * @return user connection if present + */ + @Nullable UserConnection getConnection(UUID uuid); /** * Returns the version of the plugin. diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index 36eb231c9..0218c27a7 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -77,7 +77,7 @@ import java.util.UUID; public abstract class Type implements ByteBufReader, ByteBufWriter { /* Defined Types */ - public static final Type BYTE = new ByteType(); + public static final ByteType BYTE = new ByteType(); /** * @deprecated unreasonable overhead, use BYTE_ARRAY_PRIMITIVE */ @@ -87,21 +87,21 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type SHORT_BYTE_ARRAY = new ShortByteArrayType(); public static final Type REMAINING_BYTES = new RemainingBytesType(); - public static final Type UNSIGNED_BYTE = new UnsignedByteType(); + public static final UnsignedByteType UNSIGNED_BYTE = new UnsignedByteType(); /** * @deprecated unreasonable overhead */ @Deprecated public static final Type UNSIGNED_BYTE_ARRAY = new ArrayType<>(Type.UNSIGNED_BYTE); - public static final Type BOOLEAN = new BooleanType(); + public static final BooleanType BOOLEAN = new BooleanType(); /** * @deprecated unreasonable overhead */ @Deprecated public static final Type BOOLEAN_ARRAY = new ArrayType<>(Type.BOOLEAN); /* Number Types */ - public static final Type INT = new IntType(); + public static final IntType INT = new IntType(); /** * @deprecated unreasonable overhead */ @@ -137,7 +137,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { @Deprecated public static final Type SHORT_ARRAY = new ArrayType<>(Type.SHORT); - public static final Type UNSIGNED_SHORT = new UnsignedShortType(); + public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType(); /** * @deprecated unreasonable overhead */ @@ -159,7 +159,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { @Deprecated public static final Type VAR_INT_ARRAY = new ArrayType<>(Type.VAR_INT); public static final Type VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType(); - public static final Type OPTIONAL_VAR_INT = new OptionalVarIntType(); + public static final OptionalVarIntType OPTIONAL_VAR_INT = new OptionalVarIntType(); public static final VarLongType VAR_LONG = new VarLongType(); /** * @deprecated unreasonable overhead @@ -167,7 +167,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { @Deprecated public static final Type VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG); /* Special Types */ - public static final Type NOTHING = new VoidType(); // This is purely used for remapping. + public static final VoidType NOTHING = new VoidType(); // This is purely used for remapping. /* MC Types */ public static final Type POSITION = new PositionType(); public static final Type POSITION1_14 = new Position1_14Type(); diff --git a/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java b/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java index a78168840..efa182515 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaAPIBase.java @@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.legacy.LegacyViaAPI; import com.viaversion.viaversion.api.protocol.version.ServerProtocolVersion; import com.viaversion.viaversion.legacy.LegacyAPI; import io.netty.buffer.ByteBuf; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.SortedSet; import java.util.TreeSet; @@ -50,8 +51,13 @@ public abstract class ViaAPIBase implements ViaAPI { } @Override - public boolean isInjected(UUID playerUUID) { - return Via.getManager().getConnectionManager().isClientConnected(playerUUID); + public boolean isInjected(UUID uuid) { + return Via.getManager().getConnectionManager().isClientConnected(uuid); + } + + @Override + public @Nullable UserConnection getConnection(final UUID uuid) { + return Via.getManager().getConnectionManager().getConnectedClient(uuid); } @Override