mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-17 14:37:43 +01:00
Initial adjustments for better support of Bedrock
This commit is contained in:
@@ -32,10 +32,10 @@ import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginManager;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.connection.Player;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.ProxyVersion;
|
||||
import com.velocitypowered.proxy.command.VelocityCommandManager;
|
||||
import com.velocitypowered.proxy.command.builtin.GlistCommand;
|
||||
@@ -49,7 +49,7 @@ import com.velocitypowered.proxy.event.VelocityEventManager;
|
||||
import com.velocitypowered.proxy.network.ConnectionManager;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.serialization.FaviconSerializer;
|
||||
import com.velocitypowered.proxy.network.serialization.GameProfileSerializer;
|
||||
import com.velocitypowered.proxy.network.serialization.JavaPlayerIdentitySerializer;
|
||||
import com.velocitypowered.proxy.plugin.VelocityPluginManager;
|
||||
import com.velocitypowered.proxy.scheduler.VelocityScheduler;
|
||||
import com.velocitypowered.proxy.server.ServerMap;
|
||||
@@ -111,7 +111,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
private static final Logger logger = LogManager.getLogger(VelocityServer.class);
|
||||
public static final Gson GENERAL_GSON = new GsonBuilder()
|
||||
.registerTypeHierarchyAdapter(Favicon.class, FaviconSerializer.INSTANCE)
|
||||
.registerTypeHierarchyAdapter(GameProfile.class, GameProfileSerializer.INSTANCE)
|
||||
.registerTypeHierarchyAdapter(JavaPlayerIdentity.class, JavaPlayerIdentitySerializer.INSTANCE)
|
||||
.create();
|
||||
private static final Gson PRE_1_16_PING_SERIALIZER = ProtocolUtils
|
||||
.getJsonChatSerializer(ProtocolVersion.MINECRAFT_1_15_2)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection;
|
||||
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
|
||||
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
|
||||
@@ -42,13 +42,13 @@ public interface ConnectionType {
|
||||
BackendConnectionPhase getInitialBackendPhase();
|
||||
|
||||
/**
|
||||
* Adds properties to the {@link GameProfile} if required. If any properties
|
||||
* are added, the returned {@link GameProfile} will be a copy.
|
||||
* Adds properties to the {@link JavaPlayerIdentity} if required. If any properties
|
||||
* are added, the returned {@link JavaPlayerIdentity} will be a copy.
|
||||
*
|
||||
* @param original The original {@link GameProfile}
|
||||
* @param original The original {@link JavaPlayerIdentity}
|
||||
* @param forwardingType The Velocity {@link PlayerInfoForwarding}
|
||||
* @return The {@link GameProfile} with the properties added in.
|
||||
* @return The {@link JavaPlayerIdentity} with the properties added in.
|
||||
*/
|
||||
GameProfile addGameProfileTokensIfRequired(GameProfile original,
|
||||
JavaPlayerIdentity addGameProfileTokensIfRequired(JavaPlayerIdentity original,
|
||||
PlayerInfoForwarding forwardingType);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection.backend;
|
||||
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.PlayerIdentity;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||
@@ -41,6 +42,7 @@ import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
@@ -78,7 +80,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
.getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) {
|
||||
ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(),
|
||||
cleanRemoteAddress(serverConn.player().remoteAddress()),
|
||||
serverConn.player().gameProfile());
|
||||
serverConn.player().identity());
|
||||
ServerboundLoginPluginResponsePacket response = new ServerboundLoginPluginResponsePacket(
|
||||
packet.getId(), true, forwardingData);
|
||||
mc.write(response);
|
||||
@@ -164,14 +166,18 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
private static ByteBuf createForwardingData(byte[] hmacSecret, String address,
|
||||
GameProfile profile) {
|
||||
PlayerIdentity profile) {
|
||||
ByteBuf forwarded = Unpooled.buffer(2048);
|
||||
try {
|
||||
ProtocolUtils.writeVarInt(forwarded, VelocityConstants.FORWARDING_VERSION);
|
||||
ProtocolUtils.writeString(forwarded, address);
|
||||
ProtocolUtils.writeUuid(forwarded, profile.uuid());
|
||||
ProtocolUtils.writeString(forwarded, profile.name());
|
||||
ProtocolUtils.writeProperties(forwarded, profile.properties());
|
||||
if (profile instanceof JavaPlayerIdentity) {
|
||||
ProtocolUtils.writeProperties(forwarded, ((JavaPlayerIdentity) profile).properties());
|
||||
} else {
|
||||
ProtocolUtils.writeProperties(forwarded, List.of());
|
||||
}
|
||||
|
||||
SecretKey key = new SecretKeySpec(hmacSecret, "HmacSHA256");
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
|
||||
@@ -28,8 +28,10 @@ import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.connection.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.PluginChannelId;
|
||||
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity.Property;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import com.velocitypowered.api.util.GameProfile.Property;
|
||||
import com.velocitypowered.api.util.UuidUtils;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.ConnectionTypes;
|
||||
@@ -131,15 +133,18 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
if (!(playerRemoteAddress instanceof InetSocketAddress)) {
|
||||
return playerConnectedHostname();
|
||||
}
|
||||
|
||||
List<Property> properties = proxyPlayer.identity() instanceof JavaPlayerIdentity
|
||||
? ((JavaPlayerIdentity) proxyPlayer.identity()).properties()
|
||||
: List.of();
|
||||
StringBuilder data = new StringBuilder()
|
||||
.append(playerConnectedHostname())
|
||||
.append('\0')
|
||||
.append(((InetSocketAddress) proxyPlayer.remoteAddress()).getHostString())
|
||||
.append('\0')
|
||||
.append(proxyPlayer.gameProfile().undashedId())
|
||||
.append(UuidUtils.toUndashed(proxyPlayer.id()))
|
||||
.append('\0');
|
||||
GENERAL_GSON
|
||||
.toJson(propertiesTransform.apply(proxyPlayer.gameProfile().properties()), data);
|
||||
GENERAL_GSON.toJson(propertiesTransform.apply(properties), data);
|
||||
return data.toString();
|
||||
}
|
||||
|
||||
@@ -234,7 +239,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[server connection] " + proxyPlayer.gameProfile().name() + " -> "
|
||||
return "[server connection] " + proxyPlayer.identity().name() + " -> "
|
||||
+ registeredServer.serverInfo().name();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,11 @@ import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.proxy.connection.Player;
|
||||
import com.velocitypowered.api.proxy.connection.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.PluginChannelId;
|
||||
import com.velocitypowered.api.proxy.player.ClientSettings;
|
||||
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.player.PlayerIdentity;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaClientSettings;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.ModInfo;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
@@ -102,6 +103,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
@@ -112,20 +114,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ConnectedPlayer.class);
|
||||
|
||||
private final Identity identity = new IdentityImpl();
|
||||
/**
|
||||
* The actual Minecraft connection. This is actually a wrapper object around the Netty channel.
|
||||
*/
|
||||
private final MinecraftConnection connection;
|
||||
private final @Nullable InetSocketAddress virtualHost;
|
||||
private GameProfile profile;
|
||||
private PlayerIdentity identity;
|
||||
private PermissionFunction permissionFunction;
|
||||
private int tryIndex = 0;
|
||||
private long ping = -1;
|
||||
private final boolean onlineMode;
|
||||
private @Nullable VelocityServerConnection connectedServer;
|
||||
private @Nullable VelocityServerConnection connectionInFlight;
|
||||
private @Nullable ClientSettings settings;
|
||||
private @Nullable JavaClientSettings settings;
|
||||
private @Nullable ModInfo modInfo;
|
||||
private Component playerListHeader = Component.empty();
|
||||
private Component playerListFooter = Component.empty();
|
||||
@@ -136,10 +137,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
private final CompletableFuture<Void> teardownFuture = new CompletableFuture<>();
|
||||
private @MonotonicNonNull List<String> serversToTry = null;
|
||||
|
||||
ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection,
|
||||
ConnectedPlayer(VelocityServer server, PlayerIdentity identity, MinecraftConnection connection,
|
||||
@Nullable InetSocketAddress virtualHost, boolean onlineMode) {
|
||||
this.server = server;
|
||||
this.profile = profile;
|
||||
this.identity = identity;
|
||||
this.connection = connection;
|
||||
this.virtualHost = virtualHost;
|
||||
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
|
||||
@@ -154,19 +155,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Identity identity() {
|
||||
return this.identity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String username() {
|
||||
return profile.name();
|
||||
return identity.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID id() {
|
||||
return profile.uuid();
|
||||
return identity.uuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,8 +183,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile gameProfile() {
|
||||
return profile;
|
||||
public @NotNull PlayerIdentity identity() {
|
||||
return identity;
|
||||
}
|
||||
|
||||
public MinecraftConnection getConnection() {
|
||||
@@ -210,12 +206,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSettings clientSettings() {
|
||||
return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings;
|
||||
public JavaClientSettings clientSettings() {
|
||||
return settings == null ? JavaClientSettingsWrapper.DEFAULT : this.settings;
|
||||
}
|
||||
|
||||
void setPlayerSettings(ServerboundClientSettingsPacket settings) {
|
||||
ClientSettingsWrapper cs = new ClientSettingsWrapper(settings);
|
||||
JavaClientSettingsWrapper cs = new JavaClientSettingsWrapper(settings);
|
||||
this.settings = cs;
|
||||
server.eventManager().fireAndForget(new PlayerClientSettingsChangedEventImpl(this, cs));
|
||||
}
|
||||
@@ -255,7 +251,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
public Component translateMessage(Component message) {
|
||||
Locale locale = this.settings == null ? Locale.getDefault() : this.settings.getLocale();
|
||||
Locale locale = this.settings == null ? Locale.getDefault() : this.settings.locale();
|
||||
return GlobalTranslator.render(message, locale);
|
||||
}
|
||||
|
||||
@@ -377,8 +373,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameProfileProperties(List<GameProfile.Property> properties) {
|
||||
this.profile = profile.withProperties(properties);
|
||||
public void setGameProfileProperties(List<JavaPlayerIdentity.Property> properties) {
|
||||
if (this.identity instanceof JavaPlayerIdentity) {
|
||||
this.identity = ((JavaPlayerIdentity) identity).withProperties(properties);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -729,7 +727,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[connected player] " + profile.name() + " (" + remoteAddress() + ")";
|
||||
return "[connected player] " + identity.name() + " (" + remoteAddress() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -840,13 +838,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
return minecraftOrFmlMessage || knownChannels.contains(message.getChannel());
|
||||
}
|
||||
|
||||
private class IdentityImpl implements Identity {
|
||||
@Override
|
||||
public @NonNull UUID uuid() {
|
||||
return ConnectedPlayer.this.id();
|
||||
}
|
||||
}
|
||||
|
||||
private class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {
|
||||
|
||||
private final RegisteredServer toConnect;
|
||||
|
||||
@@ -17,28 +17,28 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection.client;
|
||||
|
||||
import com.velocitypowered.api.proxy.player.ClientSettings;
|
||||
import com.velocitypowered.api.proxy.player.SkinParts;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaClientSettings;
|
||||
import com.velocitypowered.api.proxy.player.java.SkinParts;
|
||||
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientSettingsWrapper implements ClientSettings {
|
||||
public class JavaClientSettingsWrapper implements JavaClientSettings {
|
||||
|
||||
static final ClientSettings DEFAULT = new ClientSettingsWrapper(
|
||||
static final JavaClientSettings DEFAULT = new JavaClientSettingsWrapper(
|
||||
new ServerboundClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1));
|
||||
|
||||
private final ServerboundClientSettingsPacket settings;
|
||||
private final SkinParts parts;
|
||||
private @Nullable Locale locale;
|
||||
|
||||
ClientSettingsWrapper(ServerboundClientSettingsPacket settings) {
|
||||
JavaClientSettingsWrapper(ServerboundClientSettingsPacket settings) {
|
||||
this.settings = settings;
|
||||
this.parts = new SkinParts((byte) settings.getSkinParts());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
public Locale locale() {
|
||||
if (locale == null) {
|
||||
locale = Locale.forLanguageTag(settings.getLocale().replaceAll("_", "-"));
|
||||
}
|
||||
@@ -46,12 +46,12 @@ public class ClientSettingsWrapper implements ClientSettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getViewDistance() {
|
||||
public byte viewDistance() {
|
||||
return settings.getViewDistance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatMode getChatMode() {
|
||||
public ChatMode chatMode() {
|
||||
int chat = settings.getChatVisibility();
|
||||
if (chat < 0 || chat > 2) {
|
||||
return ChatMode.SHOWN;
|
||||
@@ -65,12 +65,12 @@ public class ClientSettingsWrapper implements ClientSettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SkinParts getSkinParts() {
|
||||
public SkinParts skinParts() {
|
||||
return parts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MainHand getMainHand() {
|
||||
public MainHand mainHand() {
|
||||
return settings.getMainHand() == 1 ? MainHand.RIGHT : MainHand.LEFT;
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ import com.velocitypowered.api.event.player.PostLoginEventImpl;
|
||||
import com.velocitypowered.api.event.player.PreLoginEvent;
|
||||
import com.velocitypowered.api.event.player.PreLoginEventImpl;
|
||||
import com.velocitypowered.api.permission.PermissionFunction;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.UuidUtils;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
@@ -151,7 +151,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
if (profileResponse.getStatusCode() == 200) {
|
||||
// All went well, initialize the session.
|
||||
initializePlayer(GENERAL_GSON.fromJson(profileResponse.getResponseBody(),
|
||||
GameProfile.class), true);
|
||||
JavaPlayerIdentity.class), true);
|
||||
} else if (profileResponse.getStatusCode() == 204) {
|
||||
// Apparently an offline-mode user logged onto this online-mode proxy.
|
||||
inbound.disconnect(Component.translatable("velocity.error.online-mode-only",
|
||||
@@ -206,7 +206,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
this.verify = Arrays.copyOf(request.getVerifyToken(), 4);
|
||||
mcConnection.write(request);
|
||||
} else {
|
||||
initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false);
|
||||
initializePlayer(JavaPlayerIdentity.forOfflinePlayer(login.getUsername()), false);
|
||||
}
|
||||
}, mcConnection.eventLoop())
|
||||
.exceptionally((ex) -> {
|
||||
@@ -225,13 +225,13 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
return request;
|
||||
}
|
||||
|
||||
private void initializePlayer(GameProfile profile, boolean onlineMode) {
|
||||
private void initializePlayer(JavaPlayerIdentity profile, boolean onlineMode) {
|
||||
// Some connection types may need to alter the game profile.
|
||||
profile = mcConnection.getType().addGameProfileTokensIfRequired(profile,
|
||||
server.configuration().getPlayerInfoForwardingMode());
|
||||
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEventImpl(inbound, profile,
|
||||
onlineMode);
|
||||
final GameProfile finalProfile = profile;
|
||||
final JavaPlayerIdentity finalProfile = profile;
|
||||
|
||||
server.eventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> {
|
||||
if (mcConnection.isClosed()) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection.forge.legacy;
|
||||
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.ConnectionTypes;
|
||||
import com.velocitypowered.proxy.connection.util.ConnectionTypeImpl;
|
||||
@@ -27,8 +27,8 @@ import com.velocitypowered.proxy.connection.util.ConnectionTypeImpl;
|
||||
*/
|
||||
public class LegacyForgeConnectionType extends ConnectionTypeImpl {
|
||||
|
||||
private static final GameProfile.Property IS_FORGE_CLIENT_PROPERTY =
|
||||
new GameProfile.Property("forgeClient", "true", "");
|
||||
private static final JavaPlayerIdentity.Property IS_FORGE_CLIENT_PROPERTY =
|
||||
new JavaPlayerIdentity.Property("forgeClient", "true", "");
|
||||
|
||||
public LegacyForgeConnectionType() {
|
||||
super(LegacyForgeHandshakeClientPhase.NOT_STARTED,
|
||||
@@ -36,7 +36,7 @@ public class LegacyForgeConnectionType extends ConnectionTypeImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile addGameProfileTokensIfRequired(GameProfile original,
|
||||
public JavaPlayerIdentity addGameProfileTokensIfRequired(JavaPlayerIdentity original,
|
||||
PlayerInfoForwarding forwardingType) {
|
||||
// We can't forward the FML token to the server when we are running in legacy forwarding mode,
|
||||
// since both use the "hostname" field in the handshake. We add a special property to the
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.connection.util;
|
||||
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.connection.ConnectionType;
|
||||
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
|
||||
@@ -48,7 +48,7 @@ public class ConnectionTypeImpl implements ConnectionType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile addGameProfileTokensIfRequired(GameProfile original,
|
||||
public JavaPlayerIdentity addGameProfileTokensIfRequired(JavaPlayerIdentity original,
|
||||
PlayerInfoForwarding forwardingType) {
|
||||
return original;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.velocitypowered.proxy.network.NettyPreconditions.checkFrame;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.network.pipeline.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.network.serialization.VelocityLegacyHoverEventSerializer;
|
||||
import com.velocitypowered.proxy.util.except.QuietDecoderException;
|
||||
@@ -385,13 +385,13 @@ public enum ProtocolUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a list of {@link com.velocitypowered.api.util.GameProfile.Property} to the buffer.
|
||||
* Writes a list of {@link JavaPlayerIdentity.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<JavaPlayerIdentity.Property> properties) {
|
||||
writeVarInt(buf, properties.size());
|
||||
for (GameProfile.Property property : properties) {
|
||||
for (JavaPlayerIdentity.Property property : properties) {
|
||||
writeString(buf, property.name());
|
||||
writeString(buf, property.value());
|
||||
String signature = property.signature();
|
||||
@@ -405,12 +405,12 @@ public enum ProtocolUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a list of {@link com.velocitypowered.api.util.GameProfile.Property} from the buffer.
|
||||
* Reads a list of {@link JavaPlayerIdentity.Property} from the buffer.
|
||||
* @param buf the buffer to read from
|
||||
* @return the read properties
|
||||
*/
|
||||
public static List<GameProfile.Property> readProperties(ByteBuf buf) {
|
||||
List<GameProfile.Property> properties = new ArrayList<>();
|
||||
public static List<JavaPlayerIdentity.Property> readProperties(ByteBuf buf) {
|
||||
List<JavaPlayerIdentity.Property> properties = new ArrayList<>();
|
||||
int size = readVarInt(buf);
|
||||
for (int i = 0; i < size; i++) {
|
||||
String name = readString(buf);
|
||||
@@ -420,7 +420,7 @@ public enum ProtocolUtils {
|
||||
if (hasSignature) {
|
||||
signature = readString(buf);
|
||||
}
|
||||
properties.add(new GameProfile.Property(name, value, signature));
|
||||
properties.add(new JavaPlayerIdentity.Property(name, value, signature));
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.google.common.base.VerifyException;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
@@ -193,7 +193,7 @@ public class ClientboundPlayerListItemPacket implements Packet {
|
||||
|
||||
private final @Nullable UUID uuid;
|
||||
private String name = "";
|
||||
private List<GameProfile.Property> properties = ImmutableList.of();
|
||||
private List<JavaPlayerIdentity.Property> properties = ImmutableList.of();
|
||||
private int gameMode;
|
||||
private int latency;
|
||||
private @Nullable Component displayName;
|
||||
@@ -228,11 +228,11 @@ public class ClientboundPlayerListItemPacket implements Packet {
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<GameProfile.Property> getProperties() {
|
||||
public List<JavaPlayerIdentity.Property> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public Item setProperties(List<GameProfile.Property> properties) {
|
||||
public Item setProperties(List<JavaPlayerIdentity.Property> properties) {
|
||||
this.properties = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -25,31 +25,31 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.GameProfile.Property;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity.Property;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
public final class GameProfileSerializer implements JsonSerializer<GameProfile>,
|
||||
JsonDeserializer<GameProfile> {
|
||||
public final class JavaPlayerIdentitySerializer implements JsonSerializer<JavaPlayerIdentity>,
|
||||
JsonDeserializer<JavaPlayerIdentity> {
|
||||
|
||||
public static final GameProfileSerializer INSTANCE = new GameProfileSerializer();
|
||||
public static final JavaPlayerIdentitySerializer INSTANCE = new JavaPlayerIdentitySerializer();
|
||||
private static final Type propertyList = new TypeToken<List<Property>>() {}.getType();
|
||||
|
||||
private GameProfileSerializer() {
|
||||
private JavaPlayerIdentitySerializer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile deserialize(JsonElement json, Type typeOfT,
|
||||
public JavaPlayerIdentity deserialize(JsonElement json, Type typeOfT,
|
||||
JsonDeserializationContext context) {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
return new GameProfile(obj.get("id").getAsString(), obj.get("name").getAsString(),
|
||||
return new JavaPlayerIdentity(obj.get("id").getAsString(), obj.get("name").getAsString(),
|
||||
context.deserialize(obj.get("properties"), propertyList));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(GameProfile src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
public JsonElement serialize(JavaPlayerIdentity src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.add("id", new JsonPrimitive(src.undashedId()));
|
||||
obj.add("name", new JsonPrimitive(src.name()));
|
||||
@@ -20,7 +20,7 @@ package com.velocitypowered.proxy.tablist;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.proxy.player.TabList;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
@@ -130,7 +130,7 @@ public class VelocityTabList implements TabList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry buildEntry(GameProfile profile,
|
||||
public TabListEntry buildEntry(JavaPlayerIdentity profile,
|
||||
net.kyori.adventure.text.@Nullable Component displayName, int latency, int gameMode) {
|
||||
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode);
|
||||
}
|
||||
@@ -158,13 +158,13 @@ public class VelocityTabList implements TabList {
|
||||
case ClientboundPlayerListItemPacket.ADD_PLAYER: {
|
||||
// ensure that name and properties are available
|
||||
String name = item.getName();
|
||||
List<GameProfile.Property> properties = item.getProperties();
|
||||
List<JavaPlayerIdentity.Property> properties = item.getProperties();
|
||||
if (name == null || properties == null) {
|
||||
throw new IllegalStateException("Got null game profile for ADD_PLAYER");
|
||||
}
|
||||
entries.put(uuid, (VelocityTabListEntry) TabListEntry.builder()
|
||||
.tabList(this)
|
||||
.profile(new GameProfile(uuid, name, properties))
|
||||
.profile(new JavaPlayerIdentity(uuid, name, properties))
|
||||
.displayName(item.getDisplayName())
|
||||
.latency(item.getLatency())
|
||||
.gameMode(item.getGameMode())
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.velocitypowered.proxy.tablist;
|
||||
|
||||
import com.velocitypowered.api.proxy.player.TabList;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -27,12 +27,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
public class VelocityTabListEntry implements TabListEntry {
|
||||
|
||||
private final VelocityTabList tabList;
|
||||
private final GameProfile profile;
|
||||
private final JavaPlayerIdentity profile;
|
||||
private @Nullable Component displayName;
|
||||
private int latency;
|
||||
private int gameMode;
|
||||
|
||||
VelocityTabListEntry(VelocityTabList tabList, GameProfile profile,
|
||||
VelocityTabListEntry(VelocityTabList tabList, JavaPlayerIdentity profile,
|
||||
@Nullable Component displayName, int latency, int gameMode) {
|
||||
this.tabList = tabList;
|
||||
this.profile = profile;
|
||||
@@ -47,7 +47,7 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile gameProfile() {
|
||||
public JavaPlayerIdentity gameProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
package com.velocitypowered.proxy.tablist;
|
||||
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class VelocityTabListEntryLegacy extends VelocityTabListEntry {
|
||||
|
||||
VelocityTabListEntryLegacy(VelocityTabListLegacy tabList, GameProfile profile,
|
||||
VelocityTabListEntryLegacy(VelocityTabListLegacy tabList, JavaPlayerIdentity profile,
|
||||
@Nullable Component displayName, int latency, int gameMode) {
|
||||
super(tabList, profile, displayName, latency, gameMode);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.velocitypowered.proxy.tablist;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket.Item;
|
||||
@@ -89,7 +89,7 @@ public class VelocityTabListLegacy extends VelocityTabList {
|
||||
nameMapping.put(item.getName(), uuid);
|
||||
entries.put(uuid, (VelocityTabListEntry) TabListEntry.builder()
|
||||
.tabList(this)
|
||||
.profile(new GameProfile(uuid, item.getName(), ImmutableList.of()))
|
||||
.profile(new JavaPlayerIdentity(uuid, item.getName(), ImmutableList.of()))
|
||||
.latency(item.getLatency())
|
||||
.build());
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class VelocityTabListLegacy extends VelocityTabList {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
|
||||
public TabListEntry buildEntry(JavaPlayerIdentity profile, @Nullable Component displayName, int latency,
|
||||
int gameMode) {
|
||||
return new VelocityTabListEntryLegacy(this, profile, displayName, latency, gameMode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user