diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java index 8609d91bb..3a5b38d9e 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java @@ -7,53 +7,23 @@ 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 org.checkerframework.checker.nullness.qual.Nullable; /** - * This event is fired after the {@link PreLoginEventImpl} in - * order to set up the game profile for the user. This can be used to configure a custom profile for - * a user, i.e. skin replacement. + * This event is fired after the {@link PreLoginEventImpl} in order to set up the game profile for + * the user. This can be used to configure a custom profile for a user, i.e. skin replacement. */ -public final class GameProfileRequestEvent { +public interface GameProfileRequestEvent { - private final String username; - private final InboundConnection connection; - private final GameProfile originalProfile; - private final boolean onlineMode; - private @Nullable GameProfile gameProfile; + InboundConnection getConnection(); - /** - * Creates a new instance. - * @param connection the connection connecting to the proxy - * @param originalProfile the original {@link GameProfile} for the user - * @param onlineMode whether or not the user connected in online or offline mode - */ - public GameProfileRequestEvent(InboundConnection connection, GameProfile originalProfile, - boolean onlineMode) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile"); - this.username = originalProfile.getName(); - this.onlineMode = onlineMode; - } + String getUsername(); - public InboundConnection getConnection() { - return connection; - } + GameProfile getOriginalProfile(); - public String getUsername() { - return username; - } - - public GameProfile getOriginalProfile() { - return originalProfile; - } - - public boolean isOnlineMode() { - return onlineMode; - } + boolean isOnlineMode(); /** * Returns the game profile that will be used to initialize the connection with. Should no profile @@ -62,26 +32,12 @@ public final class GameProfileRequestEvent { * * @return the user's {@link GameProfile} */ - public GameProfile getGameProfile() { - return gameProfile == null ? originalProfile : gameProfile; - } + GameProfile getGameProfile(); /** * Sets the game profile to use for this connection. * * @param gameProfile the profile for this connection, {@code null} uses the original profile */ - public void setGameProfile(@Nullable GameProfile gameProfile) { - this.gameProfile = gameProfile; - } - - @Override - public String toString() { - return "GameProfileRequestEvent{" - + "username=" + username - + ", gameProfile=" + gameProfile - + "}"; - } - - + void setGameProfile(@Nullable GameProfile gameProfile); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java new file mode 100644 index 000000000..b57066874 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java @@ -0,0 +1,92 @@ +/* + * 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.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.InboundConnection; +import com.velocitypowered.api.util.GameProfile; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * This event is fired after the {@link PreLoginEventImpl} in order to set up the game profile for + * the user. This can be used to configure a custom profile for a user, i.e. skin replacement. + */ +public final class GameProfileRequestEventImpl implements GameProfileRequestEvent { + + private final String username; + private final InboundConnection connection; + private final GameProfile originalProfile; + private final boolean onlineMode; + private @Nullable GameProfile gameProfile; + + /** + * Creates a new instance. + * @param connection the connection connecting to the proxy + * @param originalProfile the original {@link GameProfile} for the user + * @param onlineMode whether or not the user connected in online or offline mode + */ + public GameProfileRequestEventImpl(InboundConnection connection, GameProfile originalProfile, + boolean onlineMode) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile"); + this.username = originalProfile.getName(); + this.onlineMode = onlineMode; + } + + @Override + public InboundConnection getConnection() { + return connection; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public GameProfile getOriginalProfile() { + return originalProfile; + } + + @Override + public boolean isOnlineMode() { + return onlineMode; + } + + /** + * Returns the game profile that will be used to initialize the connection with. Should no profile + * 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} + */ + @Override + public GameProfile getGameProfile() { + return gameProfile == null ? originalProfile : gameProfile; + } + + /** + * Sets the game profile to use for this connection. + * + * @param gameProfile the profile for this connection, {@code null} uses the original profile + */ + @Override + public void setGameProfile(@Nullable GameProfile gameProfile) { + this.gameProfile = gameProfile; + } + + @Override + public String toString() { + return "GameProfileRequestEvent{" + + "username=" + username + + ", gameProfile=" + gameProfile + + "}"; + } + + +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 31b1919e7..1edfb613d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -29,6 +29,7 @@ import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; import com.velocitypowered.api.event.player.DisconnectEventImpl; import com.velocitypowered.api.event.player.GameProfileRequestEvent; +import com.velocitypowered.api.event.player.GameProfileRequestEventImpl; import com.velocitypowered.api.event.player.LoginEventImpl; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEventImpl; @@ -225,7 +226,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { // Some connection types may need to alter the game profile. profile = mcConnection.getType().addGameProfileTokensIfRequired(profile, server.getConfiguration().getPlayerInfoForwardingMode()); - GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile, + GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEventImpl(inbound, profile, onlineMode); final GameProfile finalProfile = profile;