3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 14:40:21 +02:00

Initial adjustments for better support of Bedrock

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-05-30 16:52:34 -04:00
Ursprung e093c91a26
Commit 3772bc1e0b
28 geänderte Dateien mit 240 neuen und 181 gelöschten Zeilen

Datei anzeigen

@ -9,7 +9,7 @@ package com.velocitypowered.api.event.player;
import com.velocitypowered.api.event.Event; import com.velocitypowered.api.event.Event;
import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.connection.InboundConnection;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
@ -22,7 +22,7 @@ public interface GameProfileRequestEvent extends Event {
String username(); String username();
GameProfile initialProfile(); JavaPlayerIdentity initialProfile();
boolean isOnlineMode(); boolean isOnlineMode();
@ -31,14 +31,14 @@ public interface GameProfileRequestEvent extends Event {
* be currently specified, the one generated by the proxy (for offline mode) or retrieved from the * be currently specified, the one generated by the proxy (for offline mode) or retrieved from the
* Mojang session servers (for online mode) will be returned instead. * Mojang session servers (for online mode) will be returned instead.
* *
* @return the user's {@link GameProfile} * @return the user's {@link JavaPlayerIdentity}
*/ */
GameProfile gameProfile(); JavaPlayerIdentity gameProfile();
/** /**
* Sets the game profile to use for this connection. * Sets the game profile to use for this connection.
* *
* @param gameProfile the profile for this connection, {@code null} uses the original profile * @param javaPlayerIdentity the profile for this connection, {@code null} uses the original profile
*/ */
void setGameProfile(@Nullable GameProfile gameProfile); void setGameProfile(@Nullable JavaPlayerIdentity javaPlayerIdentity);
} }

Datei anzeigen

@ -9,7 +9,7 @@ package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.connection.InboundConnection;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
@ -20,17 +20,17 @@ public final class GameProfileRequestEventImpl implements GameProfileRequestEven
private final String username; private final String username;
private final InboundConnection connection; private final InboundConnection connection;
private final GameProfile originalProfile; private final JavaPlayerIdentity originalProfile;
private final boolean onlineMode; private final boolean onlineMode;
private @Nullable GameProfile gameProfile; private @Nullable JavaPlayerIdentity javaPlayerIdentity;
/** /**
* Creates a new instance. * Creates a new instance.
* @param connection the connection connecting to the proxy * @param connection the connection connecting to the proxy
* @param originalProfile the original {@link GameProfile} for the user * @param originalProfile the original {@link JavaPlayerIdentity} for the user
* @param onlineMode whether or not the user connected in online or offline mode * @param onlineMode whether or not the user connected in online or offline mode
*/ */
public GameProfileRequestEventImpl(InboundConnection connection, GameProfile originalProfile, public GameProfileRequestEventImpl(InboundConnection connection, JavaPlayerIdentity originalProfile,
boolean onlineMode) { boolean onlineMode) {
this.connection = Preconditions.checkNotNull(connection, "connection"); this.connection = Preconditions.checkNotNull(connection, "connection");
this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile"); this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile");
@ -49,7 +49,7 @@ public final class GameProfileRequestEventImpl implements GameProfileRequestEven
} }
@Override @Override
public GameProfile initialProfile() { public JavaPlayerIdentity initialProfile() {
return originalProfile; return originalProfile;
} }
@ -63,28 +63,28 @@ public final class GameProfileRequestEventImpl implements GameProfileRequestEven
* be currently specified, the one generated by the proxy (for offline mode) or retrieved from the * be currently specified, the one generated by the proxy (for offline mode) or retrieved from the
* Mojang session servers (for online mode) will be returned instead. * Mojang session servers (for online mode) will be returned instead.
* *
* @return the user's {@link GameProfile} * @return the user's {@link JavaPlayerIdentity}
*/ */
@Override @Override
public GameProfile gameProfile() { public JavaPlayerIdentity gameProfile() {
return gameProfile == null ? originalProfile : gameProfile; return javaPlayerIdentity == null ? originalProfile : javaPlayerIdentity;
} }
/** /**
* Sets the game profile to use for this connection. * Sets the game profile to use for this connection.
* *
* @param gameProfile the profile for this connection, {@code null} uses the original profile * @param javaPlayerIdentity the profile for this connection, {@code null} uses the original profile
*/ */
@Override @Override
public void setGameProfile(@Nullable GameProfile gameProfile) { public void setGameProfile(@Nullable JavaPlayerIdentity javaPlayerIdentity) {
this.gameProfile = gameProfile; this.javaPlayerIdentity = javaPlayerIdentity;
} }
@Override @Override
public String toString() { public String toString() {
return "GameProfileRequestEvent{" return "GameProfileRequestEvent{"
+ "username=" + username + "username=" + username
+ ", gameProfile=" + gameProfile + ", gameProfile=" + javaPlayerIdentity
+ "}"; + "}";
} }

Datei anzeigen

@ -9,11 +9,11 @@ package com.velocitypowered.api.event.player;
import com.velocitypowered.api.event.Event; import com.velocitypowered.api.event.Event;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.java.JavaClientSettings;
public interface PlayerClientSettingsChangedEvent extends Event { public interface PlayerClientSettingsChangedEvent extends Event {
Player player(); Player player();
ClientSettings settings(); JavaClientSettings settings();
} }

Datei anzeigen

@ -10,17 +10,17 @@ package com.velocitypowered.api.event.player;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.java.JavaClientSettings;
public final class PlayerClientSettingsChangedEventImpl implements public final class PlayerClientSettingsChangedEventImpl implements
PlayerClientSettingsChangedEvent { PlayerClientSettingsChangedEvent {
private final Player player; private final Player player;
private final ClientSettings clientSettings; private final JavaClientSettings javaClientSettings;
public PlayerClientSettingsChangedEventImpl(Player player, ClientSettings clientSettings) { public PlayerClientSettingsChangedEventImpl(Player player, JavaClientSettings javaClientSettings) {
this.player = Preconditions.checkNotNull(player, "player"); this.player = Preconditions.checkNotNull(player, "player");
this.clientSettings = Preconditions.checkNotNull(clientSettings, "playerSettings"); this.javaClientSettings = Preconditions.checkNotNull(javaClientSettings, "playerSettings");
} }
@Override @Override
@ -29,15 +29,15 @@ public final class PlayerClientSettingsChangedEventImpl implements
} }
@Override @Override
public ClientSettings settings() { public JavaClientSettings settings() {
return clientSettings; return javaClientSettings;
} }
@Override @Override
public String toString() { public String toString() {
return MoreObjects.toStringHelper(this) return MoreObjects.toStringHelper(this)
.add("player", player) .add("player", player)
.add("playerSettings", clientSettings) .add("playerSettings", javaClientSettings)
.toString(); .toString();
} }
} }

Datei anzeigen

@ -12,23 +12,26 @@ import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent;
import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
import com.velocitypowered.api.proxy.messages.PluginChannelId; 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.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.player.PlatformActions;
import com.velocitypowered.api.proxy.player.PlayerIdentity;
import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabList;
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.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Represents a player who is connected to the proxy. * Represents a player who is connected to the proxy.
*/ */
public interface Player extends CommandSource, Identified, InboundConnection, public interface Player extends CommandSource, Identified, InboundConnection,
ChannelMessageSource, ChannelMessageSink { ChannelMessageSource, ChannelMessageSink, PlatformActions {
/** /**
* Returns the player's current username. * Returns the player's current username.
@ -57,7 +60,7 @@ public interface Player extends CommandSource, Identified, InboundConnection,
* *
* @return the settings * @return the settings
*/ */
ClientSettings clientSettings(); JavaClientSettings clientSettings();
/** /**
* Returns the player's mod info if they have a modded client. * Returns the player's mod info if they have a modded client.
@ -93,12 +96,14 @@ public interface Player extends CommandSource, Identified, InboundConnection,
* *
* @param properties the properties * @param properties the properties
*/ */
void setGameProfileProperties(List<GameProfile.Property> properties); void setGameProfileProperties(List<JavaPlayerIdentity.Property> properties);
/** /**
* Returns the player's game profile. * Returns the player's identity, which depends on what version of Minecraft they are currently
* playing.
*/ */
GameProfile gameProfile(); @Override
@NonNull PlayerIdentity identity();
/** /**
* Returns the player's tab list. * Returns the player's tab list.

Datei anzeigen

@ -0,0 +1,17 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.proxy.player;
/**
* Provides certain actions that may be implemented across platforms (or not at all). Similar to
* Adventure's {@link net.kyori.adventure.audience.Audience}, methods that are not implemented for
* a platform will silently fail.
*/
public interface PlatformActions {
}

Datei anzeigen

@ -0,0 +1,30 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.proxy.player;
import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Indicates an identity for a given player. This is a marker interface.
*/
public interface PlayerIdentity extends Identified, Identity {
/**
* Returns a "friendly name" to identity the player as.
*
* @return a friendly name to use for the player
*/
String name();
@Override
default @NonNull Identity identity() {
return this;
}
}

Datei anzeigen

@ -8,7 +8,7 @@
package com.velocitypowered.api.proxy.player; package com.velocitypowered.api.proxy.player;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -40,7 +40,7 @@ public interface TabList {
void addEntry(TabListEntry entry); void addEntry(TabListEntry entry);
/** /**
* Removes the {@link TabListEntry} from the tab list with the {@link GameProfile} identified with * Removes the {@link TabListEntry} from the tab list with the {@link JavaPlayerIdentity} identified with
* the specified {@link UUID}. * the specified {@link UUID}.
* *
* @param uuid of the entry * @param uuid of the entry
@ -74,6 +74,6 @@ public interface TabList {
* @return entry * @return entry
*/ */
@Deprecated @Deprecated
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, TabListEntry buildEntry(JavaPlayerIdentity profile, @Nullable Component displayName, int latency,
int gameMode); int gameMode);
} }

Datei anzeigen

@ -7,7 +7,7 @@
package com.velocitypowered.api.proxy.player; package com.velocitypowered.api.proxy.player;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -24,18 +24,18 @@ public interface TabListEntry {
TabList parent(); TabList parent();
/** /**
* Returns the {@link GameProfile} of the entry, which uniquely identifies the entry with the * Returns the {@link JavaPlayerIdentity} of the entry, which uniquely identifies the entry with the
* containing {@link java.util.UUID}, as well as deciding what is shown as the player head in the * containing {@link java.util.UUID}, as well as deciding what is shown as the player head in the
* tab list. * tab list.
* *
* @return {@link GameProfile} of the entry * @return {@link JavaPlayerIdentity} of the entry
*/ */
GameProfile gameProfile(); JavaPlayerIdentity gameProfile();
/** /**
* Returns an optional text {@link Component}, which if present is the text * Returns an optional text {@link Component}, which if present is the text
* displayed for {@code this} entry in the {@link TabList}, otherwise * displayed for {@code this} entry in the {@link TabList}, otherwise
* {@link GameProfile#name()} is shown. * {@link JavaPlayerIdentity#name()} is shown.
* *
* @return text {@link Component} of name displayed in the tab list * @return text {@link Component} of name displayed in the tab list
*/ */
@ -43,7 +43,7 @@ public interface TabListEntry {
/** /**
* Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}. If * Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}. If
* {@code null}, {@link GameProfile#name()} will be shown. * {@code null}, {@link JavaPlayerIdentity#name()} will be shown.
* *
* @param displayName to show in the {@link TabList} for {@code this} entry * @param displayName to show in the {@link TabList} for {@code this} entry
* @return {@code this}, for chaining * @return {@code this}, for chaining
@ -118,7 +118,7 @@ public interface TabListEntry {
class Builder { class Builder {
private @Nullable TabList tabList; private @Nullable TabList tabList;
private @Nullable GameProfile profile; private @Nullable JavaPlayerIdentity profile;
private @Nullable Component displayName; private @Nullable Component displayName;
private int latency = 0; private int latency = 0;
private int gameMode = 0; private int gameMode = 0;
@ -139,13 +139,13 @@ public interface TabListEntry {
} }
/** /**
* Sets the {@link GameProfile} of the {@link TabListEntry}. * Sets the {@link JavaPlayerIdentity} of the {@link TabListEntry}.
* *
* @param profile to set * @param profile to set
* @return {@code this}, for chaining * @return {@code this}, for chaining
* @see TabListEntry#gameProfile() * @see TabListEntry#gameProfile()
*/ */
public Builder profile(GameProfile profile) { public Builder profile(JavaPlayerIdentity profile) {
this.profile = profile; this.profile = profile;
return this; return this;
} }

Datei anzeigen

@ -5,21 +5,21 @@
* reference the LICENSE file in the api top-level directory. * reference the LICENSE file in the api top-level directory.
*/ */
package com.velocitypowered.api.proxy.player; package com.velocitypowered.api.proxy.player.java;
import java.util.Locale; import java.util.Locale;
/** /**
* Represents the client settings for the player. * Represents the client settings for the player.
*/ */
public interface ClientSettings { public interface JavaClientSettings {
/** /**
* Returns the locale of the Minecraft client. * Returns the locale of the Minecraft client.
* *
* @return the client locale * @return the client locale
*/ */
Locale getLocale(); Locale locale();
/** /**
* Returns the client's view distance. This does not guarantee the client will see this many * Returns the client's view distance. This does not guarantee the client will see this many
@ -27,14 +27,14 @@ public interface ClientSettings {
* *
* @return the client view distance * @return the client view distance
*/ */
byte getViewDistance(); byte viewDistance();
/** /**
* Returns the chat setting for the client. * Returns the chat setting for the client.
* *
* @return the chat setting * @return the chat setting
*/ */
ChatMode getChatMode(); ChatMode chatMode();
/** /**
* Returns whether or not the client has chat colors disabled. * Returns whether or not the client has chat colors disabled.
@ -48,14 +48,14 @@ public interface ClientSettings {
* *
* @return the skin parts for the client * @return the skin parts for the client
*/ */
SkinParts getSkinParts(); SkinParts skinParts();
/** /**
* Returns the primary hand of the client. * Returns the primary hand of the client.
* *
* @return the primary hand of the client * @return the primary hand of the client
*/ */
MainHand getMainHand(); MainHand mainHand();
enum ChatMode { enum ChatMode {
SHOWN, SHOWN,

Datei anzeigen

@ -5,10 +5,12 @@
* reference the LICENSE file in the api top-level directory. * reference the LICENSE file in the api top-level directory.
*/ */
package com.velocitypowered.api.util; package com.velocitypowered.api.proxy.player.java;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.player.PlayerIdentity;
import com.velocitypowered.api.util.UuidUtils;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identified;
@ -17,9 +19,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* Represents a Mojang game profile. This class is immutable. * Represents a {@code Minecraft: Java Edition} player identity.
*/ */
public final class GameProfile implements Identified, Identity { public final class JavaPlayerIdentity implements Identified, PlayerIdentity {
private final UUID id; private final UUID id;
private final String undashedId; private final String undashedId;
@ -32,7 +34,7 @@ public final class GameProfile implements Identified, Identity {
* @param name the profile's username * @param name the profile's username
* @param properties properties for the profile * @param properties properties for the profile
*/ */
public GameProfile(UUID id, String name, List<Property> properties) { public JavaPlayerIdentity(UUID id, String name, List<Property> properties) {
this(Preconditions.checkNotNull(id, "id"), UuidUtils.toUndashed(id), this(Preconditions.checkNotNull(id, "id"), UuidUtils.toUndashed(id),
Preconditions.checkNotNull(name, "name"), ImmutableList.copyOf(properties)); Preconditions.checkNotNull(name, "name"), ImmutableList.copyOf(properties));
} }
@ -43,12 +45,12 @@ public final class GameProfile implements Identified, Identity {
* @param name the profile's username * @param name the profile's username
* @param properties properties for the profile * @param properties properties for the profile
*/ */
public GameProfile(String undashedId, String name, List<Property> properties) { public JavaPlayerIdentity(String undashedId, String name, List<Property> properties) {
this(UuidUtils.fromUndashed(Preconditions.checkNotNull(undashedId, "undashedId")), undashedId, this(UuidUtils.fromUndashed(Preconditions.checkNotNull(undashedId, "undashedId")), undashedId,
Preconditions.checkNotNull(name, "name"), ImmutableList.copyOf(properties)); Preconditions.checkNotNull(name, "name"), ImmutableList.copyOf(properties));
} }
private GameProfile(UUID id, String undashedId, String name, List<Property> properties) { private JavaPlayerIdentity(UUID id, String undashedId, String name, List<Property> properties) {
this.id = id; this.id = id;
this.undashedId = undashedId; this.undashedId = undashedId;
this.name = name; this.name = name;
@ -94,8 +96,8 @@ public final class GameProfile implements Identified, Identity {
* @param id the new unique id * @param id the new unique id
* @return the new {@code GameProfile} * @return the new {@code GameProfile}
*/ */
public GameProfile withUuid(UUID id) { public JavaPlayerIdentity withUuid(UUID id) {
return new GameProfile(Preconditions.checkNotNull(id, "id"), UuidUtils.toUndashed(id), return new JavaPlayerIdentity(Preconditions.checkNotNull(id, "id"), UuidUtils.toUndashed(id),
this.name, this.properties); this.name, this.properties);
} }
@ -105,10 +107,10 @@ public final class GameProfile implements Identified, Identity {
* @param undashedId the new undashed id * @param undashedId the new undashed id
* @return the new {@code GameProfile} * @return the new {@code GameProfile}
*/ */
public GameProfile withUndashedId(String undashedId) { public JavaPlayerIdentity withUndashedId(String undashedId) {
return new GameProfile( return new JavaPlayerIdentity(
UuidUtils.fromUndashed(Preconditions.checkNotNull(undashedId, "undashedId")), undashedId, UuidUtils.fromUndashed(Preconditions.checkNotNull(undashedId, "undashedId")),
this.name, this.properties); undashedId, this.name, this.properties);
} }
/** /**
@ -117,8 +119,9 @@ public final class GameProfile implements Identified, Identity {
* @param name the new name * @param name the new name
* @return the new {@code GameProfile} * @return the new {@code GameProfile}
*/ */
public GameProfile withName(String name) { public JavaPlayerIdentity withName(String name) {
return new GameProfile(this.id, this.undashedId, Preconditions.checkNotNull(name, "name"), return new JavaPlayerIdentity(this.id, this.undashedId,
Preconditions.checkNotNull(name, "name"),
this.properties); this.properties);
} }
@ -128,8 +131,9 @@ public final class GameProfile implements Identified, Identity {
* @param properties the new properties * @param properties the new properties
* @return the new {@code GameProfile} * @return the new {@code GameProfile}
*/ */
public GameProfile withProperties(List<Property> properties) { public JavaPlayerIdentity withProperties(List<Property> properties) {
return new GameProfile(this.id, this.undashedId, this.name, ImmutableList.copyOf(properties)); return new JavaPlayerIdentity(this.id, this.undashedId, this.name,
ImmutableList.copyOf(properties));
} }
/** /**
@ -139,8 +143,8 @@ public final class GameProfile implements Identified, Identity {
* @param properties the properties to add * @param properties the properties to add
* @return the new {@code GameProfile} * @return the new {@code GameProfile}
*/ */
public GameProfile addProperties(Iterable<Property> properties) { public JavaPlayerIdentity addProperties(Iterable<Property> properties) {
return new GameProfile(this.id, this.undashedId, this.name, return new JavaPlayerIdentity(this.id, this.undashedId, this.name,
ImmutableList.<Property>builder().addAll(this.properties).addAll(properties).build()); ImmutableList.<Property>builder().addAll(this.properties).addAll(properties).build());
} }
@ -151,8 +155,8 @@ public final class GameProfile implements Identified, Identity {
* @param property the property to add * @param property the property to add
* @return the new {@code GameProfile} * @return the new {@code GameProfile}
*/ */
public GameProfile addProperty(Property property) { public JavaPlayerIdentity addProperty(Property property) {
return new GameProfile(this.id, this.undashedId, this.name, return new JavaPlayerIdentity(this.id, this.undashedId, this.name,
ImmutableList.<Property>builder().addAll(this.properties).add(property).build()); ImmutableList.<Property>builder().addAll(this.properties).add(property).build());
} }
@ -162,9 +166,9 @@ public final class GameProfile implements Identified, Identity {
* @param username the username to use * @param username the username to use
* @return the new offline-mode game profile * @return the new offline-mode game profile
*/ */
public static GameProfile forOfflinePlayer(String username) { public static JavaPlayerIdentity forOfflinePlayer(String username) {
Preconditions.checkNotNull(username, "username"); Preconditions.checkNotNull(username, "username");
return new GameProfile(UuidUtils.generateOfflinePlayerUuid(username), username, return new JavaPlayerIdentity(UuidUtils.generateOfflinePlayerUuid(username), username,
ImmutableList.of()); ImmutableList.of());
} }
@ -183,7 +187,8 @@ public final class GameProfile implements Identified, Identity {
} }
/** /**
* Represents a Mojang profile property. Just like {@link GameProfile}, this class is immutable. * Represents a Mojang profile property. Just like {@link JavaPlayerIdentity}, this class is
* immutable.
*/ */
public static final class Property { public static final class Property {

Datei anzeigen

@ -5,7 +5,7 @@
* reference the LICENSE file in the api top-level directory. * reference the LICENSE file in the api top-level directory.
*/ */
package com.velocitypowered.api.proxy.player; package com.velocitypowered.api.proxy.player.java;
public final class SkinParts { public final class SkinParts {

Datei anzeigen

@ -32,10 +32,10 @@ import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginManager; import com.velocitypowered.api.plugin.PluginManager;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.connection.Player; 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.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.api.util.Favicon; import com.velocitypowered.api.util.Favicon;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ProxyVersion; import com.velocitypowered.api.util.ProxyVersion;
import com.velocitypowered.proxy.command.VelocityCommandManager; import com.velocitypowered.proxy.command.VelocityCommandManager;
import com.velocitypowered.proxy.command.builtin.GlistCommand; 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.ConnectionManager;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.serialization.FaviconSerializer; 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.plugin.VelocityPluginManager;
import com.velocitypowered.proxy.scheduler.VelocityScheduler; import com.velocitypowered.proxy.scheduler.VelocityScheduler;
import com.velocitypowered.proxy.server.ServerMap; 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); private static final Logger logger = LogManager.getLogger(VelocityServer.class);
public static final Gson GENERAL_GSON = new GsonBuilder() public static final Gson GENERAL_GSON = new GsonBuilder()
.registerTypeHierarchyAdapter(Favicon.class, FaviconSerializer.INSTANCE) .registerTypeHierarchyAdapter(Favicon.class, FaviconSerializer.INSTANCE)
.registerTypeHierarchyAdapter(GameProfile.class, GameProfileSerializer.INSTANCE) .registerTypeHierarchyAdapter(JavaPlayerIdentity.class, JavaPlayerIdentitySerializer.INSTANCE)
.create(); .create();
private static final Gson PRE_1_16_PING_SERIALIZER = ProtocolUtils private static final Gson PRE_1_16_PING_SERIALIZER = ProtocolUtils
.getJsonChatSerializer(ProtocolVersion.MINECRAFT_1_15_2) .getJsonChatSerializer(ProtocolVersion.MINECRAFT_1_15_2)

Datei anzeigen

@ -17,7 +17,7 @@
package com.velocitypowered.proxy.connection; 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.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase; import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
@ -42,13 +42,13 @@ public interface ConnectionType {
BackendConnectionPhase getInitialBackendPhase(); BackendConnectionPhase getInitialBackendPhase();
/** /**
* Adds properties to the {@link GameProfile} if required. If any properties * Adds properties to the {@link JavaPlayerIdentity} if required. If any properties
* are added, the returned {@link GameProfile} will be a copy. * 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} * @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); PlayerInfoForwarding forwardingType);
} }

Datei anzeigen

@ -17,7 +17,8 @@
package com.velocitypowered.proxy.connection.backend; 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.VelocityServer;
import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.config.VelocityConfiguration;
@ -41,6 +42,7 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
@ -78,7 +80,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
.getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) { .getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) {
ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(), ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(),
cleanRemoteAddress(serverConn.player().remoteAddress()), cleanRemoteAddress(serverConn.player().remoteAddress()),
serverConn.player().gameProfile()); serverConn.player().identity());
ServerboundLoginPluginResponsePacket response = new ServerboundLoginPluginResponsePacket( ServerboundLoginPluginResponsePacket response = new ServerboundLoginPluginResponsePacket(
packet.getId(), true, forwardingData); packet.getId(), true, forwardingData);
mc.write(response); mc.write(response);
@ -164,14 +166,18 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
private static ByteBuf createForwardingData(byte[] hmacSecret, String address, private static ByteBuf createForwardingData(byte[] hmacSecret, String address,
GameProfile profile) { PlayerIdentity profile) {
ByteBuf forwarded = Unpooled.buffer(2048); ByteBuf forwarded = Unpooled.buffer(2048);
try { try {
ProtocolUtils.writeVarInt(forwarded, VelocityConstants.FORWARDING_VERSION); ProtocolUtils.writeVarInt(forwarded, VelocityConstants.FORWARDING_VERSION);
ProtocolUtils.writeString(forwarded, address); ProtocolUtils.writeString(forwarded, address);
ProtocolUtils.writeUuid(forwarded, profile.uuid()); ProtocolUtils.writeUuid(forwarded, profile.uuid());
ProtocolUtils.writeString(forwarded, profile.name()); 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"); SecretKey key = new SecretKeySpec(hmacSecret, "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256"); Mac mac = Mac.getInstance("HmacSHA256");

Datei anzeigen

@ -28,8 +28,10 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.connection.ServerConnection; import com.velocitypowered.api.proxy.connection.ServerConnection;
import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.proxy.messages.PluginChannelId;
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; 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.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.VelocityServer;
import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.ConnectionTypes;
@ -131,15 +133,18 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
if (!(playerRemoteAddress instanceof InetSocketAddress)) { if (!(playerRemoteAddress instanceof InetSocketAddress)) {
return playerConnectedHostname(); return playerConnectedHostname();
} }
List<Property> properties = proxyPlayer.identity() instanceof JavaPlayerIdentity
? ((JavaPlayerIdentity) proxyPlayer.identity()).properties()
: List.of();
StringBuilder data = new StringBuilder() StringBuilder data = new StringBuilder()
.append(playerConnectedHostname()) .append(playerConnectedHostname())
.append('\0') .append('\0')
.append(((InetSocketAddress) proxyPlayer.remoteAddress()).getHostString()) .append(((InetSocketAddress) proxyPlayer.remoteAddress()).getHostString())
.append('\0') .append('\0')
.append(proxyPlayer.gameProfile().undashedId()) .append(UuidUtils.toUndashed(proxyPlayer.id()))
.append('\0'); .append('\0');
GENERAL_GSON GENERAL_GSON.toJson(propertiesTransform.apply(properties), data);
.toJson(propertiesTransform.apply(proxyPlayer.gameProfile().properties()), data);
return data.toString(); return data.toString();
} }
@ -234,7 +239,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
@Override @Override
public String toString() { public String toString() {
return "[server connection] " + proxyPlayer.gameProfile().name() + " -> " return "[server connection] " + proxyPlayer.identity().name() + " -> "
+ registeredServer.serverInfo().name(); + registeredServer.serverInfo().name();
} }

Datei anzeigen

@ -44,10 +44,11 @@ import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.connection.ServerConnection; import com.velocitypowered.api.proxy.connection.ServerConnection;
import com.velocitypowered.api.proxy.messages.PluginChannelId; 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.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.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; 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.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { 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 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. * The actual Minecraft connection. This is actually a wrapper object around the Netty channel.
*/ */
private final MinecraftConnection connection; private final MinecraftConnection connection;
private final @Nullable InetSocketAddress virtualHost; private final @Nullable InetSocketAddress virtualHost;
private GameProfile profile; private PlayerIdentity identity;
private PermissionFunction permissionFunction; private PermissionFunction permissionFunction;
private int tryIndex = 0; private int tryIndex = 0;
private long ping = -1; private long ping = -1;
private final boolean onlineMode; private final boolean onlineMode;
private @Nullable VelocityServerConnection connectedServer; private @Nullable VelocityServerConnection connectedServer;
private @Nullable VelocityServerConnection connectionInFlight; private @Nullable VelocityServerConnection connectionInFlight;
private @Nullable ClientSettings settings; private @Nullable JavaClientSettings settings;
private @Nullable ModInfo modInfo; private @Nullable ModInfo modInfo;
private Component playerListHeader = Component.empty(); private Component playerListHeader = Component.empty();
private Component playerListFooter = 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 final CompletableFuture<Void> teardownFuture = new CompletableFuture<>();
private @MonotonicNonNull List<String> serversToTry = null; 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) { @Nullable InetSocketAddress virtualHost, boolean onlineMode) {
this.server = server; this.server = server;
this.profile = profile; this.identity = identity;
this.connection = connection; this.connection = connection;
this.virtualHost = virtualHost; this.virtualHost = virtualHost;
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED; this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
@ -154,19 +155,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
} }
@Override
public @NonNull Identity identity() {
return this.identity;
}
@Override @Override
public String username() { public String username() {
return profile.name(); return identity.name();
} }
@Override @Override
public UUID id() { public UUID id() {
return profile.uuid(); return identity.uuid();
} }
@Override @Override
@ -187,8 +183,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
@Override @Override
public GameProfile gameProfile() { public @NotNull PlayerIdentity identity() {
return profile; return identity;
} }
public MinecraftConnection getConnection() { public MinecraftConnection getConnection() {
@ -210,12 +206,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
@Override @Override
public ClientSettings clientSettings() { public JavaClientSettings clientSettings() {
return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings; return settings == null ? JavaClientSettingsWrapper.DEFAULT : this.settings;
} }
void setPlayerSettings(ServerboundClientSettingsPacket settings) { void setPlayerSettings(ServerboundClientSettingsPacket settings) {
ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); JavaClientSettingsWrapper cs = new JavaClientSettingsWrapper(settings);
this.settings = cs; this.settings = cs;
server.eventManager().fireAndForget(new PlayerClientSettingsChangedEventImpl(this, cs)); server.eventManager().fireAndForget(new PlayerClientSettingsChangedEventImpl(this, cs));
} }
@ -255,7 +251,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
public Component translateMessage(Component message) { 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); return GlobalTranslator.render(message, locale);
} }
@ -377,8 +373,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
@Override @Override
public void setGameProfileProperties(List<GameProfile.Property> properties) { public void setGameProfileProperties(List<JavaPlayerIdentity.Property> properties) {
this.profile = profile.withProperties(properties); if (this.identity instanceof JavaPlayerIdentity) {
this.identity = ((JavaPlayerIdentity) identity).withProperties(properties);
}
} }
@Override @Override
@ -729,7 +727,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
@Override @Override
public String toString() { public String toString() {
return "[connected player] " + profile.name() + " (" + remoteAddress() + ")"; return "[connected player] " + identity.name() + " (" + remoteAddress() + ")";
} }
@Override @Override
@ -840,13 +838,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return minecraftOrFmlMessage || knownChannels.contains(message.getChannel()); 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 class ConnectionRequestBuilderImpl implements ConnectionRequestBuilder {
private final RegisteredServer toConnect; private final RegisteredServer toConnect;

Datei anzeigen

@ -17,28 +17,28 @@
package com.velocitypowered.proxy.connection.client; package com.velocitypowered.proxy.connection.client;
import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.java.JavaClientSettings;
import com.velocitypowered.api.proxy.player.SkinParts; import com.velocitypowered.api.proxy.player.java.SkinParts;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket;
import java.util.Locale; import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable; 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)); new ServerboundClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1));
private final ServerboundClientSettingsPacket settings; private final ServerboundClientSettingsPacket settings;
private final SkinParts parts; private final SkinParts parts;
private @Nullable Locale locale; private @Nullable Locale locale;
ClientSettingsWrapper(ServerboundClientSettingsPacket settings) { JavaClientSettingsWrapper(ServerboundClientSettingsPacket settings) {
this.settings = settings; this.settings = settings;
this.parts = new SkinParts((byte) settings.getSkinParts()); this.parts = new SkinParts((byte) settings.getSkinParts());
} }
@Override @Override
public Locale getLocale() { public Locale locale() {
if (locale == null) { if (locale == null) {
locale = Locale.forLanguageTag(settings.getLocale().replaceAll("_", "-")); locale = Locale.forLanguageTag(settings.getLocale().replaceAll("_", "-"));
} }
@ -46,12 +46,12 @@ public class ClientSettingsWrapper implements ClientSettings {
} }
@Override @Override
public byte getViewDistance() { public byte viewDistance() {
return settings.getViewDistance(); return settings.getViewDistance();
} }
@Override @Override
public ChatMode getChatMode() { public ChatMode chatMode() {
int chat = settings.getChatVisibility(); int chat = settings.getChatVisibility();
if (chat < 0 || chat > 2) { if (chat < 0 || chat > 2) {
return ChatMode.SHOWN; return ChatMode.SHOWN;
@ -65,12 +65,12 @@ public class ClientSettingsWrapper implements ClientSettings {
} }
@Override @Override
public SkinParts getSkinParts() { public SkinParts skinParts() {
return parts; return parts;
} }
@Override @Override
public MainHand getMainHand() { public MainHand mainHand() {
return settings.getMainHand() == 1 ? MainHand.RIGHT : MainHand.LEFT; return settings.getMainHand() == 1 ? MainHand.RIGHT : MainHand.LEFT;
} }

Datei anzeigen

@ -38,8 +38,8 @@ import com.velocitypowered.api.event.player.PostLoginEventImpl;
import com.velocitypowered.api.event.player.PreLoginEvent; import com.velocitypowered.api.event.player.PreLoginEvent;
import com.velocitypowered.api.event.player.PreLoginEventImpl; import com.velocitypowered.api.event.player.PreLoginEventImpl;
import com.velocitypowered.api.permission.PermissionFunction; 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.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.UuidUtils; import com.velocitypowered.api.util.UuidUtils;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.config.PlayerInfoForwarding; import com.velocitypowered.proxy.config.PlayerInfoForwarding;
@ -151,7 +151,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
if (profileResponse.getStatusCode() == 200) { if (profileResponse.getStatusCode() == 200) {
// All went well, initialize the session. // All went well, initialize the session.
initializePlayer(GENERAL_GSON.fromJson(profileResponse.getResponseBody(), initializePlayer(GENERAL_GSON.fromJson(profileResponse.getResponseBody(),
GameProfile.class), true); JavaPlayerIdentity.class), true);
} else if (profileResponse.getStatusCode() == 204) { } else if (profileResponse.getStatusCode() == 204) {
// Apparently an offline-mode user logged onto this online-mode proxy. // Apparently an offline-mode user logged onto this online-mode proxy.
inbound.disconnect(Component.translatable("velocity.error.online-mode-only", 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); this.verify = Arrays.copyOf(request.getVerifyToken(), 4);
mcConnection.write(request); mcConnection.write(request);
} else { } else {
initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false); initializePlayer(JavaPlayerIdentity.forOfflinePlayer(login.getUsername()), false);
} }
}, mcConnection.eventLoop()) }, mcConnection.eventLoop())
.exceptionally((ex) -> { .exceptionally((ex) -> {
@ -225,13 +225,13 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
return request; 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. // Some connection types may need to alter the game profile.
profile = mcConnection.getType().addGameProfileTokensIfRequired(profile, profile = mcConnection.getType().addGameProfileTokensIfRequired(profile,
server.configuration().getPlayerInfoForwardingMode()); server.configuration().getPlayerInfoForwardingMode());
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEventImpl(inbound, profile, GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEventImpl(inbound, profile,
onlineMode); onlineMode);
final GameProfile finalProfile = profile; final JavaPlayerIdentity finalProfile = profile;
server.eventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> { server.eventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> {
if (mcConnection.isClosed()) { if (mcConnection.isClosed()) {

Datei anzeigen

@ -17,7 +17,7 @@
package com.velocitypowered.proxy.connection.forge.legacy; 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.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.ConnectionTypes;
import com.velocitypowered.proxy.connection.util.ConnectionTypeImpl; import com.velocitypowered.proxy.connection.util.ConnectionTypeImpl;
@ -27,8 +27,8 @@ import com.velocitypowered.proxy.connection.util.ConnectionTypeImpl;
*/ */
public class LegacyForgeConnectionType extends ConnectionTypeImpl { public class LegacyForgeConnectionType extends ConnectionTypeImpl {
private static final GameProfile.Property IS_FORGE_CLIENT_PROPERTY = private static final JavaPlayerIdentity.Property IS_FORGE_CLIENT_PROPERTY =
new GameProfile.Property("forgeClient", "true", ""); new JavaPlayerIdentity.Property("forgeClient", "true", "");
public LegacyForgeConnectionType() { public LegacyForgeConnectionType() {
super(LegacyForgeHandshakeClientPhase.NOT_STARTED, super(LegacyForgeHandshakeClientPhase.NOT_STARTED,
@ -36,7 +36,7 @@ public class LegacyForgeConnectionType extends ConnectionTypeImpl {
} }
@Override @Override
public GameProfile addGameProfileTokensIfRequired(GameProfile original, public JavaPlayerIdentity addGameProfileTokensIfRequired(JavaPlayerIdentity original,
PlayerInfoForwarding forwardingType) { PlayerInfoForwarding forwardingType) {
// We can't forward the FML token to the server when we are running in legacy forwarding mode, // 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 // since both use the "hostname" field in the handshake. We add a special property to the

Datei anzeigen

@ -17,7 +17,7 @@
package com.velocitypowered.proxy.connection.util; 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.config.PlayerInfoForwarding;
import com.velocitypowered.proxy.connection.ConnectionType; import com.velocitypowered.proxy.connection.ConnectionType;
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
@ -48,7 +48,7 @@ public class ConnectionTypeImpl implements ConnectionType {
} }
@Override @Override
public GameProfile addGameProfileTokensIfRequired(GameProfile original, public JavaPlayerIdentity addGameProfileTokensIfRequired(JavaPlayerIdentity original,
PlayerInfoForwarding forwardingType) { PlayerInfoForwarding forwardingType) {
return original; return original;
} }

Datei anzeigen

@ -21,7 +21,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.velocitypowered.proxy.network.NettyPreconditions.checkFrame; import static com.velocitypowered.proxy.network.NettyPreconditions.checkFrame;
import com.velocitypowered.api.network.ProtocolVersion; 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.pipeline.MinecraftDecoder;
import com.velocitypowered.proxy.network.serialization.VelocityLegacyHoverEventSerializer; import com.velocitypowered.proxy.network.serialization.VelocityLegacyHoverEventSerializer;
import com.velocitypowered.proxy.util.except.QuietDecoderException; 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 buf the buffer to write to
* @param properties the properties to serialize * @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()); writeVarInt(buf, properties.size());
for (GameProfile.Property property : properties) { for (JavaPlayerIdentity.Property property : properties) {
writeString(buf, property.name()); writeString(buf, property.name());
writeString(buf, property.value()); writeString(buf, property.value());
String signature = property.signature(); 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 * @param buf the buffer to read from
* @return the read properties * @return the read properties
*/ */
public static List<GameProfile.Property> readProperties(ByteBuf buf) { public static List<JavaPlayerIdentity.Property> readProperties(ByteBuf buf) {
List<GameProfile.Property> properties = new ArrayList<>(); List<JavaPlayerIdentity.Property> properties = new ArrayList<>();
int size = readVarInt(buf); int size = readVarInt(buf);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
String name = readString(buf); String name = readString(buf);
@ -420,7 +420,7 @@ public enum ProtocolUtils {
if (hasSignature) { if (hasSignature) {
signature = readString(buf); signature = readString(buf);
} }
properties.add(new GameProfile.Property(name, value, signature)); properties.add(new JavaPlayerIdentity.Property(name, value, signature));
} }
return properties; return properties;
} }

Datei anzeigen

@ -22,7 +22,7 @@ import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.player.TabListEntry; 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.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
@ -193,7 +193,7 @@ public class ClientboundPlayerListItemPacket implements Packet {
private final @Nullable UUID uuid; private final @Nullable UUID uuid;
private String name = ""; private String name = "";
private List<GameProfile.Property> properties = ImmutableList.of(); private List<JavaPlayerIdentity.Property> properties = ImmutableList.of();
private int gameMode; private int gameMode;
private int latency; private int latency;
private @Nullable Component displayName; private @Nullable Component displayName;
@ -228,11 +228,11 @@ public class ClientboundPlayerListItemPacket implements Packet {
return this; return this;
} }
public List<GameProfile.Property> getProperties() { public List<JavaPlayerIdentity.Property> getProperties() {
return properties; return properties;
} }
public Item setProperties(List<GameProfile.Property> properties) { public Item setProperties(List<JavaPlayerIdentity.Property> properties) {
this.properties = properties; this.properties = properties;
return this; return this;
} }

Datei anzeigen

@ -25,31 +25,31 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer; import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import com.velocitypowered.api.util.GameProfile.Property; import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity.Property;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.List;
public final class GameProfileSerializer implements JsonSerializer<GameProfile>, public final class JavaPlayerIdentitySerializer implements JsonSerializer<JavaPlayerIdentity>,
JsonDeserializer<GameProfile> { 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 static final Type propertyList = new TypeToken<List<Property>>() {}.getType();
private GameProfileSerializer() { private JavaPlayerIdentitySerializer() {
} }
@Override @Override
public GameProfile deserialize(JsonElement json, Type typeOfT, public JavaPlayerIdentity deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) { JsonDeserializationContext context) {
JsonObject obj = json.getAsJsonObject(); 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)); context.deserialize(obj.get("properties"), propertyList));
} }
@Override @Override
public JsonElement serialize(GameProfile src, Type typeOfSrc, JsonSerializationContext context) { public JsonElement serialize(JavaPlayerIdentity src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject obj = new JsonObject(); JsonObject obj = new JsonObject();
obj.add("id", new JsonPrimitive(src.undashedId())); obj.add("id", new JsonPrimitive(src.undashedId()));
obj.add("name", new JsonPrimitive(src.name())); obj.add("name", new JsonPrimitive(src.name()));

Datei anzeigen

@ -20,7 +20,7 @@ package com.velocitypowered.proxy.tablist;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry; 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.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
@ -130,7 +130,7 @@ public class VelocityTabList implements TabList {
} }
@Override @Override
public TabListEntry buildEntry(GameProfile profile, public TabListEntry buildEntry(JavaPlayerIdentity profile,
net.kyori.adventure.text.@Nullable Component displayName, int latency, int gameMode) { net.kyori.adventure.text.@Nullable Component displayName, int latency, int gameMode) {
return new VelocityTabListEntry(this, profile, displayName, latency, gameMode); return new VelocityTabListEntry(this, profile, displayName, latency, gameMode);
} }
@ -158,13 +158,13 @@ public class VelocityTabList implements TabList {
case ClientboundPlayerListItemPacket.ADD_PLAYER: { case ClientboundPlayerListItemPacket.ADD_PLAYER: {
// ensure that name and properties are available // ensure that name and properties are available
String name = item.getName(); String name = item.getName();
List<GameProfile.Property> properties = item.getProperties(); List<JavaPlayerIdentity.Property> properties = item.getProperties();
if (name == null || properties == null) { if (name == null || properties == null) {
throw new IllegalStateException("Got null game profile for ADD_PLAYER"); throw new IllegalStateException("Got null game profile for ADD_PLAYER");
} }
entries.put(uuid, (VelocityTabListEntry) TabListEntry.builder() entries.put(uuid, (VelocityTabListEntry) TabListEntry.builder()
.tabList(this) .tabList(this)
.profile(new GameProfile(uuid, name, properties)) .profile(new JavaPlayerIdentity(uuid, name, properties))
.displayName(item.getDisplayName()) .displayName(item.getDisplayName())
.latency(item.getLatency()) .latency(item.getLatency())
.gameMode(item.getGameMode()) .gameMode(item.getGameMode())

Datei anzeigen

@ -19,7 +19,7 @@ package com.velocitypowered.proxy.tablist;
import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry; 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 com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -27,12 +27,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class VelocityTabListEntry implements TabListEntry { public class VelocityTabListEntry implements TabListEntry {
private final VelocityTabList tabList; private final VelocityTabList tabList;
private final GameProfile profile; private final JavaPlayerIdentity profile;
private @Nullable Component displayName; private @Nullable Component displayName;
private int latency; private int latency;
private int gameMode; private int gameMode;
VelocityTabListEntry(VelocityTabList tabList, GameProfile profile, VelocityTabListEntry(VelocityTabList tabList, JavaPlayerIdentity profile,
@Nullable Component displayName, int latency, int gameMode) { @Nullable Component displayName, int latency, int gameMode) {
this.tabList = tabList; this.tabList = tabList;
this.profile = profile; this.profile = profile;
@ -47,7 +47,7 @@ public class VelocityTabListEntry implements TabListEntry {
} }
@Override @Override
public GameProfile gameProfile() { public JavaPlayerIdentity gameProfile() {
return profile; return profile;
} }

Datei anzeigen

@ -18,13 +18,13 @@
package com.velocitypowered.proxy.tablist; package com.velocitypowered.proxy.tablist;
import com.velocitypowered.api.proxy.player.TabListEntry; 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 net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class VelocityTabListEntryLegacy extends VelocityTabListEntry { public class VelocityTabListEntryLegacy extends VelocityTabListEntry {
VelocityTabListEntryLegacy(VelocityTabListLegacy tabList, GameProfile profile, VelocityTabListEntryLegacy(VelocityTabListLegacy tabList, JavaPlayerIdentity profile,
@Nullable Component displayName, int latency, int gameMode) { @Nullable Component displayName, int latency, int gameMode) {
super(tabList, profile, displayName, latency, gameMode); super(tabList, profile, displayName, latency, gameMode);
} }

Datei anzeigen

@ -19,7 +19,7 @@ package com.velocitypowered.proxy.tablist;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.player.TabListEntry; 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.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket.Item; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket.Item;
@ -89,7 +89,7 @@ public class VelocityTabListLegacy extends VelocityTabList {
nameMapping.put(item.getName(), uuid); nameMapping.put(item.getName(), uuid);
entries.put(uuid, (VelocityTabListEntry) TabListEntry.builder() entries.put(uuid, (VelocityTabListEntry) TabListEntry.builder()
.tabList(this) .tabList(this)
.profile(new GameProfile(uuid, item.getName(), ImmutableList.of())) .profile(new JavaPlayerIdentity(uuid, item.getName(), ImmutableList.of()))
.latency(item.getLatency()) .latency(item.getLatency())
.build()); .build());
} }
@ -127,7 +127,7 @@ public class VelocityTabListLegacy extends VelocityTabList {
} }
@Override @Override
public TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, public TabListEntry buildEntry(JavaPlayerIdentity profile, @Nullable Component displayName, int latency,
int gameMode) { int gameMode) {
return new VelocityTabListEntryLegacy(this, profile, displayName, latency, gameMode); return new VelocityTabListEntryLegacy(this, profile, displayName, latency, gameMode);
} }