Initial adjustments for better support of Bedrock

This commit is contained in:
Andrew Steinborn
2021-05-30 16:52:34 -04:00
parent e093c91a26
commit 3772bc1e0b
28 changed files with 240 additions and 181 deletions

View File

@@ -9,7 +9,7 @@ package com.velocitypowered.api.event.player;
import com.velocitypowered.api.event.Event;
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;
/**
@@ -22,7 +22,7 @@ public interface GameProfileRequestEvent extends Event {
String username();
GameProfile initialProfile();
JavaPlayerIdentity initialProfile();
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
* 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.
*
* @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);
}

View File

@@ -9,7 +9,7 @@ package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
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;
/**
@@ -20,17 +20,17 @@ public final class GameProfileRequestEventImpl implements GameProfileRequestEven
private final String username;
private final InboundConnection connection;
private final GameProfile originalProfile;
private final JavaPlayerIdentity originalProfile;
private final boolean onlineMode;
private @Nullable GameProfile gameProfile;
private @Nullable JavaPlayerIdentity javaPlayerIdentity;
/**
* Creates a new instance.
* @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
*/
public GameProfileRequestEventImpl(InboundConnection connection, GameProfile originalProfile,
public GameProfileRequestEventImpl(InboundConnection connection, JavaPlayerIdentity originalProfile,
boolean onlineMode) {
this.connection = Preconditions.checkNotNull(connection, "connection");
this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile");
@@ -49,7 +49,7 @@ public final class GameProfileRequestEventImpl implements GameProfileRequestEven
}
@Override
public GameProfile initialProfile() {
public JavaPlayerIdentity initialProfile() {
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
* Mojang session servers (for online mode) will be returned instead.
*
* @return the user's {@link GameProfile}
* @return the user's {@link JavaPlayerIdentity}
*/
@Override
public GameProfile gameProfile() {
return gameProfile == null ? originalProfile : gameProfile;
public JavaPlayerIdentity gameProfile() {
return javaPlayerIdentity == null ? originalProfile : javaPlayerIdentity;
}
/**
* 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
public void setGameProfile(@Nullable GameProfile gameProfile) {
this.gameProfile = gameProfile;
public void setGameProfile(@Nullable JavaPlayerIdentity javaPlayerIdentity) {
this.javaPlayerIdentity = javaPlayerIdentity;
}
@Override
public String toString() {
return "GameProfileRequestEvent{"
+ "username=" + username
+ ", gameProfile=" + gameProfile
+ ", gameProfile=" + javaPlayerIdentity
+ "}";
}

View File

@@ -9,11 +9,11 @@ package com.velocitypowered.api.event.player;
import com.velocitypowered.api.event.Event;
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 {
Player player();
ClientSettings settings();
JavaClientSettings settings();
}

View File

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

View File

@@ -12,23 +12,26 @@ import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent;
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
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.PlatformActions;
import com.velocitypowered.api.proxy.player.PlayerIdentity;
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.util.GameProfile;
import com.velocitypowered.api.util.ModInfo;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Represents a player who is connected to the proxy.
*/
public interface Player extends CommandSource, Identified, InboundConnection,
ChannelMessageSource, ChannelMessageSink {
ChannelMessageSource, ChannelMessageSink, PlatformActions {
/**
* Returns the player's current username.
@@ -57,7 +60,7 @@ public interface Player extends CommandSource, Identified, InboundConnection,
*
* @return the settings
*/
ClientSettings clientSettings();
JavaClientSettings clientSettings();
/**
* 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
*/
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.

View File

@@ -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 {
}

View File

@@ -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;
}
}

View File

@@ -8,7 +8,7 @@
package com.velocitypowered.api.proxy.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.UUID;
import net.kyori.adventure.text.Component;
@@ -40,7 +40,7 @@ public interface TabList {
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}.
*
* @param uuid of the entry
@@ -74,6 +74,6 @@ public interface TabList {
* @return entry
*/
@Deprecated
TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency,
TabListEntry buildEntry(JavaPlayerIdentity profile, @Nullable Component displayName, int latency,
int gameMode);
}

View File

@@ -7,7 +7,7 @@
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 org.checkerframework.checker.nullness.qual.Nullable;
@@ -24,18 +24,18 @@ public interface TabListEntry {
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
* 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
* 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
*/
@@ -43,7 +43,7 @@ public interface TabListEntry {
/**
* 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
* @return {@code this}, for chaining
@@ -118,7 +118,7 @@ public interface TabListEntry {
class Builder {
private @Nullable TabList tabList;
private @Nullable GameProfile profile;
private @Nullable JavaPlayerIdentity profile;
private @Nullable Component displayName;
private int latency = 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
* @return {@code this}, for chaining
* @see TabListEntry#gameProfile()
*/
public Builder profile(GameProfile profile) {
public Builder profile(JavaPlayerIdentity profile) {
this.profile = profile;
return this;
}

View File

@@ -5,21 +5,21 @@
* 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;
/**
* Represents the client settings for the player.
*/
public interface ClientSettings {
public interface JavaClientSettings {
/**
* Returns the locale of the Minecraft client.
*
* @return the client locale
*/
Locale getLocale();
Locale locale();
/**
* 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
*/
byte getViewDistance();
byte viewDistance();
/**
* Returns the chat setting for the client.
*
* @return the chat setting
*/
ChatMode getChatMode();
ChatMode chatMode();
/**
* Returns whether or not the client has chat colors disabled.
@@ -48,14 +48,14 @@ public interface ClientSettings {
*
* @return the skin parts for the client
*/
SkinParts getSkinParts();
SkinParts skinParts();
/**
* Returns the primary hand of the client.
*
* @return the primary hand of the client
*/
MainHand getMainHand();
MainHand mainHand();
enum ChatMode {
SHOWN,

View File

@@ -5,10 +5,12 @@
* 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.collect.ImmutableList;
import com.velocitypowered.api.proxy.player.PlayerIdentity;
import com.velocitypowered.api.util.UuidUtils;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.identity.Identified;
@@ -17,9 +19,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
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 String undashedId;
@@ -32,7 +34,7 @@ public final class GameProfile implements Identified, Identity {
* @param name the profile's username
* @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),
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 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,
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.undashedId = undashedId;
this.name = name;
@@ -94,8 +96,8 @@ public final class GameProfile implements Identified, Identity {
* @param id the new unique id
* @return the new {@code GameProfile}
*/
public GameProfile withUuid(UUID id) {
return new GameProfile(Preconditions.checkNotNull(id, "id"), UuidUtils.toUndashed(id),
public JavaPlayerIdentity withUuid(UUID id) {
return new JavaPlayerIdentity(Preconditions.checkNotNull(id, "id"), UuidUtils.toUndashed(id),
this.name, this.properties);
}
@@ -105,10 +107,10 @@ public final class GameProfile implements Identified, Identity {
* @param undashedId the new undashed id
* @return the new {@code GameProfile}
*/
public GameProfile withUndashedId(String undashedId) {
return new GameProfile(
UuidUtils.fromUndashed(Preconditions.checkNotNull(undashedId, "undashedId")), undashedId,
this.name, this.properties);
public JavaPlayerIdentity withUndashedId(String undashedId) {
return new JavaPlayerIdentity(
UuidUtils.fromUndashed(Preconditions.checkNotNull(undashedId, "undashedId")),
undashedId, this.name, this.properties);
}
/**
@@ -117,8 +119,9 @@ public final class GameProfile implements Identified, Identity {
* @param name the new name
* @return the new {@code GameProfile}
*/
public GameProfile withName(String name) {
return new GameProfile(this.id, this.undashedId, Preconditions.checkNotNull(name, "name"),
public JavaPlayerIdentity withName(String name) {
return new JavaPlayerIdentity(this.id, this.undashedId,
Preconditions.checkNotNull(name, "name"),
this.properties);
}
@@ -128,8 +131,9 @@ public final class GameProfile implements Identified, Identity {
* @param properties the new properties
* @return the new {@code GameProfile}
*/
public GameProfile withProperties(List<Property> properties) {
return new GameProfile(this.id, this.undashedId, this.name, ImmutableList.copyOf(properties));
public JavaPlayerIdentity withProperties(List<Property> 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
* @return the new {@code GameProfile}
*/
public GameProfile addProperties(Iterable<Property> properties) {
return new GameProfile(this.id, this.undashedId, this.name,
public JavaPlayerIdentity addProperties(Iterable<Property> properties) {
return new JavaPlayerIdentity(this.id, this.undashedId, this.name,
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
* @return the new {@code GameProfile}
*/
public GameProfile addProperty(Property property) {
return new GameProfile(this.id, this.undashedId, this.name,
public JavaPlayerIdentity addProperty(Property property) {
return new JavaPlayerIdentity(this.id, this.undashedId, this.name,
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
* @return the new offline-mode game profile
*/
public static GameProfile forOfflinePlayer(String username) {
public static JavaPlayerIdentity forOfflinePlayer(String username) {
Preconditions.checkNotNull(username, "username");
return new GameProfile(UuidUtils.generateOfflinePlayerUuid(username), username,
return new JavaPlayerIdentity(UuidUtils.generateOfflinePlayerUuid(username), username,
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 {

View File

@@ -5,7 +5,7 @@
* 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 {