From 437c505cd894a8fb5b17cc9e3b379a70774e11bd Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 27 Oct 2023 23:58:13 -0400 Subject: [PATCH] Start tearing out the prefixes --- .../api/command/BrigadierCommand.java | 2 +- .../api/command/CommandManager.java | 10 +- .../api/command/CommandMeta.java | 6 +- .../velocitypowered/api/event/PostOrder.java | 6 +- .../api/event/ResultedEvent.java | 39 ++- .../event/command/CommandExecuteEvent.java | 10 +- .../command/PlayerAvailableCommandsEvent.java | 6 +- .../connection/ConnectionHandshakeEvent.java | 2 +- .../api/event/connection/DisconnectEvent.java | 4 +- .../api/event/connection/LoginEvent.java | 10 +- .../event/connection/PluginMessageEvent.java | 12 +- .../api/event/connection/PostLoginEvent.java | 5 +- .../api/event/connection/PreLoginEvent.java | 26 +- .../permission/PermissionsSetupEvent.java | 4 +- .../event/player/GameProfileRequestEvent.java | 14 +- .../event/player/KickedFromServerEvent.java | 54 ++-- .../player/PlayerChannelRegisterEvent.java | 6 +- .../api/event/player/PlayerChatEvent.java | 21 +- .../PlayerChooseInitialServerEvent.java | 5 +- .../event/player/PlayerClientBrandEvent.java | 5 +- .../api/event/player/PlayerModInfoEvent.java | 7 +- .../api/event/player/PlayerReferentEvent.java | 18 ++ .../player/PlayerResourcePackStatusEvent.java | 24 +- .../player/PlayerSettingsChangedEvent.java | 5 +- .../event/player/ServerConnectedEvent.java | 11 +- .../player/ServerLoginPluginMessageEvent.java | 18 +- .../event/player/ServerPostConnectEvent.java | 10 +- .../event/player/ServerPreConnectEvent.java | 21 +- .../player/ServerResourcePackSendEvent.java | 10 +- .../api/event/player/TabCompleteEvent.java | 8 +- .../api/event/proxy/ListenerBoundEvent.java | 4 +- .../api/event/proxy/ListenerCloseEvent.java | 4 +- .../api/event/proxy/ProxyPingEvent.java | 4 +- .../api/event/query/ProxyQueryEvent.java | 6 +- .../api/permission/PermissionSubject.java | 6 +- .../api/plugin/PluginContainer.java | 6 +- .../api/plugin/PluginDescription.java | 16 +- .../api/plugin/PluginManager.java | 4 +- .../api/plugin/meta/PluginDependency.java | 6 +- .../api/proxy/ConnectionRequestBuilder.java | 11 +- .../api/proxy/InboundConnection.java | 6 +- .../com/velocitypowered/api/proxy/Player.java | 69 ++---- .../api/proxy/ProxyServer.java | 2 +- .../api/proxy/ServerConnection.java | 8 +- .../api/proxy/config/ProxyConfig.java | 3 +- .../api/proxy/crypto/IdentifiedKey.java | 10 +- .../api/proxy/crypto/KeyIdentifiable.java | 2 +- .../api/proxy/crypto/KeySigned.java | 10 +- .../api/proxy/crypto/SignedMessage.java | 4 +- .../api/proxy/messages/ChannelIdentifier.java | 2 +- .../messages/LegacyChannelIdentifier.java | 2 +- .../messages/MinecraftChannelIdentifier.java | 2 +- .../api/proxy/player/ChatSession.java | 2 +- .../api/proxy/player/PlayerSettings.java | 10 +- .../api/proxy/player/ResourcePackInfo.java | 31 ++- .../api/proxy/player/TabList.java | 2 +- .../api/proxy/player/TabListEntry.java | 8 +- .../api/proxy/server/PingOptions.java | 4 +- .../api/proxy/server/QueryResponse.java | 42 ++-- .../api/proxy/server/RegisteredServer.java | 4 +- .../api/proxy/server/ServerInfo.java | 6 +- .../api/proxy/server/ServerPing.java | 31 +-- .../com/velocitypowered/api/util/Favicon.java | 4 +- .../velocitypowered/api/util/GameProfile.java | 14 +- .../com/velocitypowered/api/util/ModInfo.java | 8 +- .../api/util/ProxyVersion.java | 6 +- .../com/velocitypowered/proxy/Metrics.java | 2 +- .../velocitypowered/proxy/VelocityServer.java | 38 +-- .../proxy/command/VelocityCommandManager.java | 20 +- .../proxy/command/VelocityCommandMeta.java | 8 +- .../command/builtin/BuiltinCommandUtil.java | 2 +- .../proxy/command/builtin/GlistCommand.java | 8 +- .../proxy/command/builtin/ServerCommand.java | 16 +- .../command/builtin/VelocityCommand.java | 34 +-- .../registrar/BrigadierCommandRegistrar.java | 4 +- .../registrar/InvocableCommandRegistrar.java | 2 +- .../backend/BackendPlaySessionHandler.java | 56 ++--- .../backend/BungeeCordMessageResponder.java | 44 ++-- .../backend/ConfigSessionHandler.java | 40 +-- .../backend/LoginSessionHandler.java | 30 +-- .../backend/TransitionSessionHandler.java | 30 +-- .../backend/VelocityServerConnection.java | 40 +-- .../connection/client/AuthSessionHandler.java | 45 ++-- .../client/ClientPlaySessionHandler.java | 32 +-- .../client/ClientSettingsWrapper.java | 10 +- .../connection/client/ConnectedPlayer.java | 233 +++++++++--------- .../client/HandshakeSessionHandler.java | 8 +- .../client/InitialConnectSessionHandler.java | 4 +- .../client/InitialInboundConnection.java | 10 +- .../client/InitialLoginSessionHandler.java | 26 +- .../client/LoginInboundConnection.java | 18 +- .../LegacyForgeHandshakeBackendPhase.java | 2 +- .../LegacyForgeHandshakeClientPhase.java | 2 +- .../player/VelocityResourcePackInfo.java | 30 +-- .../util/ConnectionRequestResults.java | 6 +- .../util/ServerListPingHandler.java | 26 +- .../proxy/console/VelocityConsole.java | 6 +- .../proxy/crypto/IdentifiedKeyImpl.java | 20 +- .../proxy/crypto/SignedChatCommand.java | 8 +- .../proxy/event/VelocityEventManager.java | 8 +- .../proxy/network/ConnectionManager.java | 2 +- .../pipeline/query/GameSpyQueryHandler.java | 30 +-- .../proxy/network/protocol/ProtocolUtils.java | 12 +- .../protocol/packet/LegacyDisconnect.java | 10 +- .../protocol/packet/LegacyPlayerListItem.java | 8 +- .../protocol/packet/ResourcePackRequest.java | 6 +- .../network/protocol/packet/ServerData.java | 4 +- .../network/protocol/packet/ServerLogin.java | 4 +- .../protocol/packet/UpsertPlayerInfo.java | 4 +- .../protocol/packet/chat/CommandHandler.java | 2 +- .../packet/chat/RemoteChatSession.java | 4 +- .../packet/chat/keyed/KeyedChatHandler.java | 26 +- .../chat/keyed/KeyedCommandHandler.java | 18 +- .../packet/chat/legacy/LegacyChatBuilder.java | 2 +- .../packet/chat/legacy/LegacyChatHandler.java | 9 +- .../chat/legacy/LegacyCommandHandler.java | 4 +- .../chat/session/SessionChatHandler.java | 6 +- .../chat/session/SessionCommandHandler.java | 14 +- .../protocol/util/FaviconSerializer.java | 2 +- .../protocol/util/GameProfileSerializer.java | 6 +- .../protocol/util/PluginMessageUtil.java | 2 +- .../proxy/plugin/VelocityPluginManager.java | 32 +-- .../loader/VelocityPluginContainer.java | 8 +- .../loader/VelocityPluginDescription.java | 18 +- .../plugin/loader/java/JavaPluginLoader.java | 20 +- .../loader/java/VelocityPluginModule.java | 8 +- .../plugin/util/PluginDependencyUtils.java | 10 +- .../proxy/scheduler/VelocityScheduler.java | 18 +- .../proxy/server/PingSessionHandler.java | 2 +- .../proxy/server/ServerMap.java | 16 +- .../server/VelocityRegisteredServer.java | 22 +- .../proxy/tablist/KeyedVelocityTabList.java | 18 +- .../tablist/KeyedVelocityTabListEntry.java | 2 +- .../proxy/tablist/VelocityTabList.java | 16 +- .../tablist/VelocityTabListEntryLegacy.java | 2 +- .../proxy/tablist/VelocityTabListLegacy.java | 6 +- .../proxy/util/InformationUtils.java | 36 +-- .../proxy/util/VelocityChannelRegistrar.java | 18 +- .../util/bossbar/AdventureBossBarManager.java | 4 +- .../command/CommandGraphInjectorTests.java | 8 +- .../proxy/command/CommandManagerTests.java | 46 ++-- .../proxy/command/CommandTestSuite.java | 2 +- .../proxy/command/MockCommandSource.java | 2 +- .../proxy/command/RawCommandTests.java | 42 ++-- .../proxy/command/SimpleCommandTests.java | 42 ++-- .../command/SuggestionsProviderTests.java | 42 ++-- .../proxy/plugin/MockPluginManager.java | 4 +- .../proxy/testutil/FakePluginManager.java | 10 +- .../util/VelocityChannelRegistrarTest.java | 12 +- 149 files changed, 1112 insertions(+), 1135 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerReferentEvent.java diff --git a/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java b/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java index a8331c5b9..094e4ddf9 100644 --- a/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java +++ b/api/src/main/java/com/velocitypowered/api/command/BrigadierCommand.java @@ -49,7 +49,7 @@ public final class BrigadierCommand implements Command { * * @return the command node */ - public LiteralCommandNode getNode() { + public LiteralCommandNode node() { return node; } } diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java index d97707d9f..f4ef05397 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java @@ -24,7 +24,7 @@ public interface CommandManager { * @param alias the first command alias * @return a {@link CommandMeta} builder */ - CommandMeta.Builder metaBuilder(String alias); + CommandMeta.Builder buildMeta(String alias); /** * Returns a builder to create a {@link CommandMeta} for @@ -33,7 +33,7 @@ public interface CommandManager { * @param command the command * @return a {@link CommandMeta} builder */ - CommandMeta.Builder metaBuilder(BrigadierCommand command); + CommandMeta.Builder buildMeta(BrigadierCommand command); /** * Registers the specified command with the specified aliases. @@ -46,7 +46,7 @@ public interface CommandManager { * @see Command for a list of registrable subinterfaces */ default void register(String alias, Command command, String... otherAliases) { - register(metaBuilder(alias).aliases(otherAliases).build(), command); + register(buildMeta(alias).aliases(otherAliases).build(), command); } /** @@ -88,7 +88,7 @@ public interface CommandManager { * @param alias the command alias to lookup * @return an {@link CommandMeta} of the alias */ - @Nullable CommandMeta getCommandMeta(String alias); + @Nullable CommandMeta commandMeta(String alias); /** * Attempts to asynchronously execute a command from the given {@code cmdLine}. @@ -117,7 +117,7 @@ public interface CommandManager { * * @return the registered aliases */ - Collection getAliases(); + Collection aliases(); /** * Returns whether the given alias is registered on this manager. diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java b/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java index b2612c4b6..23605f328 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java @@ -22,7 +22,7 @@ public interface CommandMeta { * * @return the command aliases */ - Collection getAliases(); + Collection aliases(); /** * Returns an immutable collection containing command nodes that provide @@ -31,7 +31,7 @@ public interface CommandMeta { * * @return the hinting command nodes */ - Collection> getHints(); + Collection> hints(); /** * Returns the plugin who registered the command. @@ -39,7 +39,7 @@ public interface CommandMeta { * * @return the registering plugin */ - @Nullable Object getPlugin(); + @Nullable Object plugin(); /** * Provides a fluent interface to create {@link CommandMeta}s. diff --git a/api/src/main/java/com/velocitypowered/api/event/PostOrder.java b/api/src/main/java/com/velocitypowered/api/event/PostOrder.java index 559899068..62195f70a 100644 --- a/api/src/main/java/com/velocitypowered/api/event/PostOrder.java +++ b/api/src/main/java/com/velocitypowered/api/event/PostOrder.java @@ -12,7 +12,11 @@ package com.velocitypowered.api.event; */ public class PostOrder { - public static final short FIRST = -32768; + private PostOrder() { + + } + + public static final short FIRST = -32767; public static final short EARLY = -16384; public static final short NORMAL = 0; public static final short LATE = 16834; diff --git a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java index 0aafd0583..8e1bfee28 100644 --- a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java @@ -8,7 +8,6 @@ package com.velocitypowered.api.event; import com.google.common.base.Preconditions; -import java.util.Optional; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -23,7 +22,7 @@ public interface ResultedEvent { * * @return the result of this event */ - R getResult(); + R result(); /** * Sets the result of this event. The result must be non-null. @@ -38,12 +37,12 @@ public interface ResultedEvent { interface Result { /** - * Returns whether or not the event is allowed to proceed. Plugins may choose to skip denied + * Returns whether the event is allowed to proceed. Plugins may choose to skip denied * events, and the proxy will respect the result of this method. * - * @return whether or not the event is allowed to proceed + * @return whether the event is allowed to proceed */ - boolean isAllowed(); + boolean allowed(); } /** @@ -61,7 +60,7 @@ public interface ResultedEvent { } @Override - public boolean isAllowed() { + public boolean allowed() { return status; } @@ -70,11 +69,11 @@ public interface ResultedEvent { return status ? "allowed" : "denied"; } - public static GenericResult allowed() { + public static GenericResult allow() { return ALLOWED; } - public static GenericResult denied() { + public static GenericResult deny() { return DENIED; } } @@ -87,20 +86,20 @@ public interface ResultedEvent { private static final ComponentResult ALLOWED = new ComponentResult(true, null); private final boolean status; - private final @Nullable Component reason; + private final @Nullable Component explanation; - protected ComponentResult(boolean status, @Nullable Component reason) { + private ComponentResult(boolean status, @Nullable Component explanation) { this.status = status; - this.reason = reason; + this.explanation = explanation; } @Override - public boolean isAllowed() { + public boolean allowed() { return status; } - public Optional getReasonComponent() { - return Optional.ofNullable(reason); + public @Nullable Component explanation() { + return explanation; } @Override @@ -108,19 +107,19 @@ public interface ResultedEvent { if (status) { return "allowed"; } - if (reason != null) { - return "denied: " + PlainTextComponentSerializer.plainText().serialize(reason); + if (explanation != null) { + return "denied: " + PlainTextComponentSerializer.plainText().serialize(explanation); } return "denied"; } - public static ComponentResult allowed() { + public static ComponentResult allow() { return ALLOWED; } - public static ComponentResult denied(Component reason) { - Preconditions.checkNotNull(reason, "reason"); - return new ComponentResult(false, reason); + public static ComponentResult deny(Component explanation) { + Preconditions.checkNotNull(explanation, "explanation"); + return new ComponentResult(false, explanation); } } } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java index 29288265b..c510bbda0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java @@ -36,7 +36,7 @@ public final class CommandExecuteEvent implements ResultedEvent { public CommandExecuteEvent(CommandSource commandSource, String command) { this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource"); this.command = Preconditions.checkNotNull(command, "command"); - this.result = CommandResult.allowed(); + this.result = CommandResult.allow(); } public CommandSource getCommandSource() { @@ -53,7 +53,7 @@ public final class CommandExecuteEvent implements ResultedEvent { } @Override - public CommandResult getResult() { + public CommandResult result() { return result; } @@ -99,7 +99,7 @@ public final class CommandExecuteEvent implements ResultedEvent { } @Override - public boolean isAllowed() { + public boolean allowed() { return status; } @@ -113,7 +113,7 @@ public final class CommandExecuteEvent implements ResultedEvent { * * @return the allowed result */ - public static CommandResult allowed() { + public static CommandResult allow() { return ALLOWED; } @@ -122,7 +122,7 @@ public final class CommandExecuteEvent implements ResultedEvent { * * @return the denied result */ - public static CommandResult denied() { + public static CommandResult deny() { return DENIED; } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java index 3f9b0298d..d046b77ca 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java @@ -12,6 +12,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.Beta; import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.event.annotation.AwaitingEvent; +import com.velocitypowered.api.event.player.PlayerReferentEvent; import com.velocitypowered.api.proxy.Player; /** @@ -22,7 +23,7 @@ import com.velocitypowered.api.proxy.Player; */ @AwaitingEvent @Beta -public class PlayerAvailableCommandsEvent { +public class PlayerAvailableCommandsEvent implements PlayerReferentEvent { private final Player player; private final RootCommandNode rootNode; @@ -39,7 +40,8 @@ public class PlayerAvailableCommandsEvent { this.rootNode = checkNotNull(rootNode, "rootNode"); } - public Player getPlayer() { + @Override + public Player player() { return player; } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java index 14baac413..76df9f967 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java @@ -23,7 +23,7 @@ public final class ConnectionHandshakeEvent { this.connection = Preconditions.checkNotNull(connection, "connection"); } - public InboundConnection getConnection() { + public InboundConnection connection() { return connection; } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java index bec7b7456..e9ff8693c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java @@ -35,11 +35,11 @@ public final class DisconnectEvent { this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus"); } - public Player getPlayer() { + public Player player() { return player; } - public LoginStatus getLoginStatus() { + public LoginStatus loginStatus() { return loginStatus; } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java index 494088972..997b3e553 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/LoginEvent.java @@ -10,6 +10,7 @@ package com.velocitypowered.api.event.connection; import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.annotation.AwaitingEvent; +import com.velocitypowered.api.event.player.PlayerReferentEvent; import com.velocitypowered.api.proxy.Player; /** @@ -19,22 +20,23 @@ import com.velocitypowered.api.proxy.Player; * process. */ @AwaitingEvent -public final class LoginEvent implements ResultedEvent { +public final class LoginEvent implements ResultedEvent, + PlayerReferentEvent { private final Player player; private ComponentResult result; public LoginEvent(Player player) { this.player = Preconditions.checkNotNull(player, "player"); - this.result = ComponentResult.allowed(); + this.result = ComponentResult.allow(); } - public Player getPlayer() { + public Player player() { return player; } @Override - public ComponentResult getResult() { + public ComponentResult result() { return result; } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java index 668c9fc1d..6d4901c92 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java @@ -52,7 +52,7 @@ public final class PluginMessageEvent implements ResultedEvent getReasonComponent() { - return Optional.ofNullable(reason); + public @Nullable Component explanation() { + return reason; } public boolean isOnlineModeAllowed() { @@ -132,14 +132,14 @@ public final class PreLoginEvent implements ResultedEvent { + ResultedEvent, PlayerReferentEvent { private final Player player; private final RegisteredServer server; - private final net.kyori.adventure.text.@Nullable Component originalReason; + private final @Nullable Component originalReason; private final boolean duringServerConnect; private ServerKickResult result; @@ -43,8 +43,8 @@ public final class KickedFromServerEvent implements * @param result the initial result */ public KickedFromServerEvent(Player player, RegisteredServer server, - net.kyori.adventure.text.@Nullable Component originalReason, - boolean duringServerConnect, ServerKickResult result) { + @Nullable Component originalReason, boolean duringServerConnect, + ServerKickResult result) { this.player = Preconditions.checkNotNull(player, "player"); this.server = Preconditions.checkNotNull(server, "server"); this.originalReason = originalReason; @@ -53,7 +53,7 @@ public final class KickedFromServerEvent implements } @Override - public ServerKickResult getResult() { + public ServerKickResult result() { return result; } @@ -62,16 +62,16 @@ public final class KickedFromServerEvent implements this.result = Preconditions.checkNotNull(result, "result"); } - public Player getPlayer() { + public Player player() { return player; } - public RegisteredServer getServer() { + public RegisteredServer server() { return server; } - public Optional getServerKickReason() { - return Optional.ofNullable(originalReason); + public @Nullable Component kickReason() { + return originalReason; } /** @@ -107,18 +107,18 @@ public final class KickedFromServerEvent implements */ public static final class DisconnectPlayer implements ServerKickResult { - private final net.kyori.adventure.text.Component component; + private final Component component; - private DisconnectPlayer(net.kyori.adventure.text.Component component) { + private DisconnectPlayer(Component component) { this.component = Preconditions.checkNotNull(component, "component"); } @Override - public boolean isAllowed() { + public boolean allowed() { return true; } - public net.kyori.adventure.text.Component getReasonComponent() { + public Component reason() { return component; } @@ -128,7 +128,7 @@ public final class KickedFromServerEvent implements * @param reason the reason to use when disconnecting the player * @return the disconnect result */ - public static DisconnectPlayer create(net.kyori.adventure.text.Component reason) { + public static DisconnectPlayer disconnect(Component reason) { return new DisconnectPlayer(reason); } } @@ -138,17 +138,17 @@ public final class KickedFromServerEvent implements */ public static final class RedirectPlayer implements ServerKickResult { - private final net.kyori.adventure.text.Component message; + private final Component message; private final RegisteredServer server; private RedirectPlayer(RegisteredServer server, - net.kyori.adventure.text.@Nullable Component message) { + @Nullable Component message) { this.server = Preconditions.checkNotNull(server, "server"); this.message = message; } @Override - public boolean isAllowed() { + public boolean allowed() { return false; } @@ -156,7 +156,7 @@ public final class KickedFromServerEvent implements return server; } - public net.kyori.adventure.text.@Nullable Component getMessageComponent() { + public @Nullable Component getMessageComponent() { return message; } @@ -169,8 +169,8 @@ public final class KickedFromServerEvent implements * @param message the message will be sent to the player after redirecting * @return the redirect result */ - public static RedirectPlayer create(RegisteredServer server, - net.kyori.adventure.text.Component message) { + public static RedirectPlayer redirect(RegisteredServer server, + Component message) { return new RedirectPlayer(server, message); } @@ -181,7 +181,7 @@ public final class KickedFromServerEvent implements * @param server the server to send the player to * @return the redirect result */ - public static ServerKickResult create(RegisteredServer server) { + public static ServerKickResult redirect(RegisteredServer server) { return new RedirectPlayer(server, null); } } @@ -193,18 +193,18 @@ public final class KickedFromServerEvent implements */ public static final class Notify implements ServerKickResult { - private final net.kyori.adventure.text.Component message; + private final Component message; - private Notify(net.kyori.adventure.text.Component message) { + private Notify(Component message) { this.message = Preconditions.checkNotNull(message, "message"); } @Override - public boolean isAllowed() { + public boolean allowed() { return false; } - public net.kyori.adventure.text.Component getMessageComponent() { + public Component reason() { return message; } @@ -214,7 +214,7 @@ public final class KickedFromServerEvent implements * @param message the server to send the player to * @return the redirect result */ - public static Notify create(net.kyori.adventure.text.Component message) { + public static Notify notify(Component message) { return new Notify(message); } } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java index f82615855..5e0760adc 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java @@ -16,7 +16,7 @@ import java.util.List; * This event is fired when a client ({@link Player}) sends a plugin message through the * register channel. Velocity will not wait on this event to finish firing. */ -public final class PlayerChannelRegisterEvent { +public final class PlayerChannelRegisterEvent implements PlayerReferentEvent { private final Player player; private final List channels; @@ -26,11 +26,11 @@ public final class PlayerChannelRegisterEvent { this.channels = Preconditions.checkNotNull(channels, "channels"); } - public Player getPlayer() { + public Player player() { return player; } - public List getChannels() { + public List channels() { return channels; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java index 786173972..9aef05e4c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java @@ -20,7 +20,8 @@ import org.checkerframework.checker.nullness.qual.Nullable; * to finish firing before forwarding it to the server, if the result allows it. */ @AwaitingEvent -public final class PlayerChatEvent implements ResultedEvent { +public final class PlayerChatEvent implements ResultedEvent, + PlayerReferentEvent { private final Player player; private final String message; @@ -35,19 +36,19 @@ public final class PlayerChatEvent implements ResultedEvent getMessage() { + public Optional modifiedMessage() { return Optional.ofNullable(message); } @Override - public boolean isAllowed() { + public boolean allowed() { return status; } @@ -100,7 +101,7 @@ public final class PlayerChatEvent implements ResultedEventminecraft:brand plugin message. Velocity will * not wait on the result of this event. */ -public final class PlayerClientBrandEvent { +public final class PlayerClientBrandEvent implements PlayerReferentEvent { private final Player player; private final String brand; @@ -29,7 +29,8 @@ public final class PlayerClientBrandEvent { this.brand = Preconditions.checkNotNull(brand); } - public Player getPlayer() { + @Override + public Player player() { return player; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java index eb0b41336..df11fb16a 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java @@ -16,7 +16,7 @@ import com.velocitypowered.api.util.ModInfo; * This event is fired when a Forge client sends its mods to the proxy while connecting to a server. * Velocity will not wait on this event to finish firing. */ -public final class PlayerModInfoEvent { +public final class PlayerModInfoEvent implements PlayerReferentEvent { private final Player player; private final ModInfo modInfo; @@ -26,11 +26,12 @@ public final class PlayerModInfoEvent { this.modInfo = Preconditions.checkNotNull(modInfo, "modInfo"); } - public Player getPlayer() { + @Override + public Player player() { return player; } - public ModInfo getModInfo() { + public ModInfo modInfo() { return modInfo; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerReferentEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerReferentEvent.java new file mode 100644 index 000000000..7fd65bb84 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerReferentEvent.java @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2023 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.velocitypowered.api.proxy.Player; + +/** + * Defines any event that refers to a player. + */ +public interface PlayerReferentEvent { + + Player player(); +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java index 8e5d6887f..3e589fa1c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java @@ -21,26 +21,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; * the player may be kicked from the server. */ @AwaitingEvent -public class PlayerResourcePackStatusEvent { +public class PlayerResourcePackStatusEvent implements PlayerReferentEvent { private final Player player; private final Status status; private final @MonotonicNonNull ResourcePackInfo packInfo; private boolean overwriteKick; - /** - * Instantiates this event. - * - * @deprecated Use {@link PlayerResourcePackStatusEvent#PlayerResourcePackStatusEvent - * (Player, Status, ResourcePackInfo)} instead. - */ - @Deprecated - public PlayerResourcePackStatusEvent(Player player, Status status) { - this.player = Preconditions.checkNotNull(player, "player"); - this.status = Preconditions.checkNotNull(status, "status"); - this.packInfo = null; - } - /** * Instantiates this event. */ @@ -55,7 +42,8 @@ public class PlayerResourcePackStatusEvent { * * @return the player */ - public Player getPlayer() { + @Override + public Player player() { return player; } @@ -80,7 +68,7 @@ public class PlayerResourcePackStatusEvent { /** * Gets whether or not to override the kick resulting from - * {@link ResourcePackInfo#getShouldForce()} being true. + * {@link ResourcePackInfo#required()} being true. * * @return whether or not to overwrite the result */ @@ -89,7 +77,7 @@ public class PlayerResourcePackStatusEvent { } /** - * Set to true to prevent {@link ResourcePackInfo#getShouldForce()} + * Set to true to prevent {@link ResourcePackInfo#required()} * from kicking the player. * Overwriting this kick is only possible on versions older than 1.17, * as the client or server will enforce this regardless. Cancelling the resulting @@ -99,7 +87,7 @@ public class PlayerResourcePackStatusEvent { * @throws IllegalArgumentException if the player version is 1.17 or newer */ public void setOverwriteKick(boolean overwriteKick) { - Preconditions.checkArgument(player.getProtocolVersion() + Preconditions.checkArgument(player.protocolVersion() .compareTo(ProtocolVersion.MINECRAFT_1_17) < 0, "overwriteKick is not supported on 1.17 or newer"); this.overwriteKick = overwriteKick; diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java index cd1bd01c2..a27e0b628 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java @@ -17,7 +17,7 @@ import com.velocitypowered.api.proxy.player.PlayerSettings; * and typically will be fired multiple times per connection. Velocity will not wait on this event * to finish firing. */ -public final class PlayerSettingsChangedEvent { +public final class PlayerSettingsChangedEvent implements PlayerReferentEvent { private final Player player; private final PlayerSettings playerSettings; @@ -27,7 +27,8 @@ public final class PlayerSettingsChangedEvent { this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings"); } - public Player getPlayer() { + @Override + public Player player() { return player; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index ac4452a0a..87af98dea 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -11,7 +11,6 @@ import com.google.common.base.Preconditions; import com.velocitypowered.api.event.annotation.AwaitingEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; -import java.util.Optional; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -25,7 +24,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; *

*/ @AwaitingEvent -public final class ServerConnectedEvent { +public final class ServerConnectedEvent implements PlayerReferentEvent { private final Player player; private final RegisteredServer server; @@ -45,16 +44,16 @@ public final class ServerConnectedEvent { this.previousServer = previousServer; } - public Player getPlayer() { + public Player player() { return player; } - public RegisteredServer getServer() { + public RegisteredServer newServer() { return server; } - public Optional getPreviousServer() { - return Optional.ofNullable(previousServer); + public @Nullable RegisteredServer previousServer() { + return previousServer; } @Override diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java index 9597e02af..d5866c713 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerLoginPluginMessageEvent.java @@ -54,7 +54,7 @@ public class ServerLoginPluginMessageEvent implements ResultedEvent { + ResultedEvent, PlayerReferentEvent { private final Player player; private final RegisteredServer originalServer; @@ -39,7 +39,7 @@ public final class ServerPreConnectEvent implements */ public ServerPreConnectEvent(Player player, RegisteredServer originalServer) { this(player, originalServer, - player.getCurrentServer().map(ServerConnection::getServer).orElse(null)); + player.connectedServer().map(ServerConnection::server).orElse(null)); } /** @@ -54,7 +54,7 @@ public final class ServerPreConnectEvent implements this.player = Preconditions.checkNotNull(player, "player"); this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer"); this.previousServer = previousServer; - this.result = ServerResult.allowed(originalServer); + this.result = ServerResult.connectTo(originalServer); } /** @@ -62,12 +62,13 @@ public final class ServerPreConnectEvent implements * * @return the player connecting to the server */ - public Player getPlayer() { + @Override + public Player player() { return player; } @Override - public ServerResult getResult() { + public ServerResult result() { return result; } @@ -89,7 +90,7 @@ public final class ServerPreConnectEvent implements /** * Returns the server that the player is currently connected to. Prefer this method over using - * {@link Player#getCurrentServer()} as the current server might get reset after server kicks to + * {@link Player#connectedServer()} as the current server might get reset after server kicks to * prevent connection issues. This is {@code null} if they were not connected to another server * beforehand (for instance, if the player has just joined the proxy). * @@ -122,7 +123,7 @@ public final class ServerPreConnectEvent implements } @Override - public boolean isAllowed() { + public boolean allowed() { return server != null; } @@ -133,7 +134,7 @@ public final class ServerPreConnectEvent implements @Override public String toString() { if (server != null) { - return "allowed: connect to " + server.getServerInfo().getName(); + return "allowed: connect to " + server.serverInfo().name(); } return "denied"; } @@ -145,7 +146,7 @@ public final class ServerPreConnectEvent implements * * @return a result to deny conneections */ - public static ServerResult denied() { + public static ServerResult deny() { return DENIED; } @@ -155,7 +156,7 @@ public final class ServerPreConnectEvent implements * @param server the new server to connect to * @return a result to allow the player to connect to the specified server */ - public static ServerResult allowed(RegisteredServer server) { + public static ServerResult connectTo(RegisteredServer server) { Preconditions.checkNotNull(server, "server"); return new ServerResult(server); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerResourcePackSendEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerResourcePackSendEvent.java index 5c1e925c0..8dc34d8e7 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerResourcePackSendEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerResourcePackSendEvent.java @@ -36,21 +36,21 @@ public class ServerResourcePackSendEvent implements ResultedEvent suggestions; @@ -45,7 +45,7 @@ public class TabCompleteEvent { * * @return the requesting player */ - public Player getPlayer() { + public Player player() { return player; } @@ -54,7 +54,7 @@ public class TabCompleteEvent { * * @return the partial message */ - public String getPartialMessage() { + public String partialMessage() { return partialMessage; } @@ -63,7 +63,7 @@ public class TabCompleteEvent { * * @return the suggestions */ - public List getSuggestions() { + public List suggestions() { return suggestions; } diff --git a/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java index b735bd810..4e3da2aca 100644 --- a/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java @@ -24,11 +24,11 @@ public final class ListenerBoundEvent { this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); } - public SocketAddress getAddress() { + public SocketAddress address() { return address; } - public ListenerType getListenerType() { + public ListenerType listenerType() { return listenerType; } diff --git a/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java index edb01d126..5925d74eb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java @@ -24,11 +24,11 @@ public final class ListenerCloseEvent { this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); } - public SocketAddress getAddress() { + public SocketAddress address() { return address; } - public ListenerType getListenerType() { + public ListenerType listenerType() { return listenerType; } diff --git a/api/src/main/java/com/velocitypowered/api/event/proxy/ProxyPingEvent.java b/api/src/main/java/com/velocitypowered/api/event/proxy/ProxyPingEvent.java index 0e04acfee..0301465fe 100644 --- a/api/src/main/java/com/velocitypowered/api/event/proxy/ProxyPingEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/proxy/ProxyPingEvent.java @@ -30,11 +30,11 @@ public final class ProxyPingEvent { this.ping = Preconditions.checkNotNull(ping, "ping"); } - public InboundConnection getConnection() { + public InboundConnection connection() { return connection; } - public ServerPing getPing() { + public ServerPing ping() { return ping; } diff --git a/api/src/main/java/com/velocitypowered/api/event/query/ProxyQueryEvent.java b/api/src/main/java/com/velocitypowered/api/event/query/ProxyQueryEvent.java index a7145db8b..fd6eafa7b 100644 --- a/api/src/main/java/com/velocitypowered/api/event/query/ProxyQueryEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/query/ProxyQueryEvent.java @@ -41,7 +41,7 @@ public final class ProxyQueryEvent { * * @return query type */ - public QueryType getQueryType() { + public QueryType queryType() { return queryType; } @@ -50,7 +50,7 @@ public final class ProxyQueryEvent { * * @return querier address */ - public InetAddress getQuerierAddress() { + public InetAddress remoteAddress() { return querierAddress; } @@ -59,7 +59,7 @@ public final class ProxyQueryEvent { * * @return the current query response */ - public QueryResponse getResponse() { + public QueryResponse response() { return response; } diff --git a/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java b/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java index de3e96b55..6c07e84f0 100644 --- a/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java +++ b/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java @@ -22,7 +22,7 @@ public interface PermissionSubject { * @return whether or not the subject has the permission */ default boolean hasPermission(String permission) { - return this.getPermissionChecker().test(permission); + return this.permissionChecker().test(permission); } /** @@ -32,7 +32,7 @@ public interface PermissionSubject { * @return the value the permission is set to */ default TriState getPermissionValue(String permission) { - return this.getPermissionChecker().value(permission); + return this.permissionChecker().value(permission); } /** @@ -40,5 +40,5 @@ public interface PermissionSubject { * * @return subject's permission checker */ - PermissionChecker getPermissionChecker(); + PermissionChecker permissionChecker(); } diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java index 2420f5548..66f784d24 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java @@ -20,14 +20,14 @@ public interface PluginContainer { * * @return the plugin's description */ - PluginDescription getDescription(); + PluginDescription description(); /** * Returns the created plugin if it is available. * * @return the instance if available */ - default Optional getInstance() { + default Optional instance() { return Optional.empty(); } @@ -37,5 +37,5 @@ public interface PluginContainer { * * @return an {@link ExecutorService} associated with this plugin */ - ExecutorService getExecutorService(); + ExecutorService executorService(); } diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java index 540b54ea5..3425b41fa 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java @@ -34,7 +34,7 @@ public interface PluginDescription { * @return the plugin ID * @see Plugin#id() */ - String getId(); + String id(); /** * Gets the name of the {@link Plugin} within this container. @@ -42,7 +42,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin name, may be empty * @see Plugin#name() */ - default Optional getName() { + default Optional name() { return Optional.empty(); } @@ -52,7 +52,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin version, may be empty * @see Plugin#version() */ - default Optional getVersion() { + default Optional version() { return Optional.empty(); } @@ -62,7 +62,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin description, may be empty * @see Plugin#description() */ - default Optional getDescription() { + default Optional description() { return Optional.empty(); } @@ -72,7 +72,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin url, may be empty * @see Plugin#url() */ - default Optional getUrl() { + default Optional url() { return Optional.empty(); } @@ -82,7 +82,7 @@ public interface PluginDescription { * @return the plugin authors, may be empty * @see Plugin#authors() */ - default List getAuthors() { + default List authors() { return ImmutableList.of(); } @@ -92,11 +92,11 @@ public interface PluginDescription { * @return the plugin dependencies, can be empty * @see Plugin#dependencies() */ - default Collection getDependencies() { + default Collection dependencies() { return ImmutableSet.of(); } - default Optional getDependency(String id) { + default Optional dependency(String id) { return Optional.empty(); } diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java index 1cd2375bf..e0f2b7c47 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java @@ -32,14 +32,14 @@ public interface PluginManager { * @param id the plugin ID * @return the plugin, if available */ - Optional getPlugin(String id); + Optional plugin(String id); /** * Gets a {@link Collection} of all {@link PluginContainer}s. * * @return the plugins */ - Collection getPlugins(); + Collection plugins(); /** * Checks if a plugin is loaded based on its ID. diff --git a/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java b/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java index 5b5acccd0..813543b44 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/meta/PluginDependency.java @@ -44,7 +44,7 @@ public final class PluginDependency { * * @return the plugin ID */ - public String getId() { + public String id() { return id; } @@ -53,7 +53,7 @@ public final class PluginDependency { * * @return an {@link Optional} with the plugin version, may be empty */ - public Optional getVersion() { + public Optional version() { return Optional.ofNullable(version); } @@ -62,7 +62,7 @@ public final class PluginDependency { * * @return true if dependency is optional */ - public boolean isOptional() { + public boolean optional() { return optional; } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java b/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java index 18e319810..40fad24e7 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java @@ -10,6 +10,7 @@ package com.velocitypowered.api.proxy; import com.velocitypowered.api.proxy.server.RegisteredServer; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import net.kyori.adventure.text.Component; /** * Provides a fluent interface to send a connection request to another server on the proxy. A @@ -22,7 +23,7 @@ public interface ConnectionRequestBuilder { * * @return the server this request will connect to */ - RegisteredServer getServer(); + RegisteredServer server(); /** * Initiates the connection to the remote server and emits a result on the {@link @@ -59,7 +60,7 @@ public interface ConnectionRequestBuilder { * @return whether or not the request succeeded */ default boolean isSuccessful() { - return getStatus() == Status.SUCCESS; + return status() == Status.SUCCESS; } /** @@ -67,21 +68,21 @@ public interface ConnectionRequestBuilder { * * @return the status for this result */ - Status getStatus(); + Status status(); /** * Returns an (optional) textual reason for the failure to connect to the server. * * @return the reason why the user could not connect to the server */ - Optional getReasonComponent(); + Optional reason(); /** * Returns the server we actually tried to connect to. * * @return the server we actually tried to connect to */ - RegisteredServer getAttemptedConnection(); + RegisteredServer attemptedConnectedTo(); } /** diff --git a/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java index 0ef4ee7c3..46dcbf233 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java @@ -22,14 +22,14 @@ public interface InboundConnection { * * @return the player's remote address */ - SocketAddress getRemoteAddress(); + SocketAddress remoteAddress(); /** * Returns the hostname that the user entered into the client, if applicable. * * @return the hostname from the client */ - Optional getVirtualHost(); + Optional virtualHost(); /** * Determine whether or not the player remains online. @@ -43,5 +43,5 @@ public interface InboundConnection { * * @return the protocol version the connection uses */ - ProtocolVersion getProtocolVersion(); + ProtocolVersion protocolVersion(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index 99bf09da0..64c2e5a56 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -47,17 +47,17 @@ public interface Player extends * * @return the username */ - String getUsername(); + String username(); /** * Returns the locale the proxy will use to send messages translated via the Adventure global - * translator. By default, the value of {@link PlayerSettings#getLocale()} is used. + * translator. By default, the value of {@link PlayerSettings#locale()} is used. * *

This can be {@code null} when the client has not yet connected to any server.

* * @return the locale. */ - @Nullable Locale getEffectiveLocale(); + @Nullable Locale effectiveLocale(); /** * Change the locale the proxy will be translating its messages to. @@ -71,21 +71,21 @@ public interface Player extends * * @return the UUID */ - UUID getUniqueId(); + UUID uuid(); /** * Returns the server that the player is currently connected to. * * @return an {@link Optional} the server that the player is connected to, which may be empty */ - Optional getCurrentServer(); + Optional connectedServer(); /** * Returns the player's client settings. * * @return the settings */ - PlayerSettings getPlayerSettings(); + PlayerSettings settings(); /** * Returns whether the player has sent its client settings. @@ -99,14 +99,14 @@ public interface Player extends * * @return an {@link Optional} the mod info. which may be empty */ - Optional getModInfo(); + Optional modInfo(); /** * Gets the player's estimated ping in milliseconds. * * @return the player's ping or -1 if ping information is currently unknown */ - long getPing(); + long ping(); /** * Returns the player's connection status. @@ -130,29 +130,19 @@ public interface Player extends * * @return the player's profile properties */ - List getGameProfileProperties(); + List profileProperties(); /** * Sets the player's profile properties. * * @param properties the properties */ - void setGameProfileProperties(List properties); + void setProfileProperties(List properties); /** * Returns the player's game profile. */ - GameProfile getGameProfile(); - - /** - * Clears the tab list header and footer for the player. - * - * @deprecated Use {@link Player#clearPlayerListHeaderAndFooter()}. - */ - @Deprecated - default void clearHeaderAndFooter() { - clearPlayerListHeaderAndFooter(); - } + GameProfile profile(); /** * Clears the player list header and footer. @@ -178,7 +168,7 @@ public interface Player extends * * @return this player's tab list */ - TabList getTabList(); + TabList tabList(); /** * Disconnects the player with the specified reason. Once this method is called, further calls to @@ -186,7 +176,7 @@ public interface Player extends * * @param reason component with the reason */ - void disconnect(net.kyori.adventure.text.Component reason); + void disconnect(Component reason); /** * Sends chat input onto the players current server as if they typed it into the client chat box. @@ -195,29 +185,6 @@ public interface Player extends */ void spoofChatInput(String input); - /** - * Sends the specified resource pack from {@code url} to the user. If at all possible, send the - * resource pack using {@link #sendResourcePack(String, byte[])}. To monitor the status of the - * sent resource pack, subscribe to {@link PlayerResourcePackStatusEvent}. - * - * @param url the URL for the resource pack - * @deprecated Use {@link #sendResourcePackOffer(ResourcePackInfo)} instead - */ - @Deprecated - void sendResourcePack(String url); - - /** - * Sends the specified resource pack from {@code url} to the user, using the specified 20-byte - * SHA-1 hash. To monitor the status of the sent resource pack, subscribe to - * {@link PlayerResourcePackStatusEvent}. - * - * @param url the URL for the resource pack - * @param hash the SHA-1 hash value for the resource pack - * @deprecated Use {@link #sendResourcePackOffer(ResourcePackInfo)} instead - */ - @Deprecated - void sendResourcePack(String url, byte[] hash); - /** * Queues and sends a new Resource-pack offer to the player. * To monitor the status of the sent resource pack, subscribe to @@ -236,7 +203,7 @@ public interface Player extends * @return the applied resource pack or null if none. */ @Nullable - ResourcePackInfo getAppliedResourcePack(); + ResourcePackInfo appliedResourcePack(); /** * Gets the {@link ResourcePackInfo} of the resource pack @@ -246,14 +213,14 @@ public interface Player extends * @return the pending resource pack or null if none */ @Nullable - ResourcePackInfo getPendingResourcePack(); + ResourcePackInfo pendingResourcePack(); /** * Note that this method does not send a plugin message to the server the player * is connected to. You should only use this method if you are trying to communicate * with a mod that is installed on the player's client. To send a plugin message to the server * from the player, you should use the equivalent method on the instance returned by - * {@link #getCurrentServer()}. + * {@link #connectedServer()}. * * @inheritDoc */ @@ -268,8 +235,8 @@ public interface Player extends @Override default @NotNull HoverEvent asHoverEvent( @NotNull UnaryOperator op) { - return HoverEvent.showEntity(op.apply(HoverEvent.ShowEntity.of(this, getUniqueId(), - Component.text(getUsername())))); + return HoverEvent.showEntity(op.apply(HoverEvent.ShowEntity.showEntity(this, uuid(), + Component.text(username())))); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java index fdd6d0a11..406cf5744 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -214,7 +214,7 @@ public interface ProxyServer extends Audience { * *

Do also make sure that the resource pack is in the correct format for the version * of the client. It is also highly recommended to always provide the resource-pack SHA-1 hash - * of the resource pack with {@link ResourcePackInfo.Builder#setHash(byte[])} + * of the resource pack with {@link ResourcePackInfo.Builder#hash(byte[])} * whenever possible to save bandwidth. If a hash is present the client will first check * if it already has a resource pack by that hash cached.

* diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ServerConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/ServerConnection.java index c408e8305..816b0f58d 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ServerConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ServerConnection.java @@ -23,7 +23,7 @@ public interface ServerConnection extends ChannelMessageSource, ChannelMessageSi * * @return the server this connection is connected to */ - RegisteredServer getServer(); + RegisteredServer server(); /** * Returns the server that the player associated with this connection was connected to before @@ -31,19 +31,19 @@ public interface ServerConnection extends ChannelMessageSource, ChannelMessageSi * * @return the server the player was connected to. */ - Optional getPreviousServer(); + Optional previousServer(); /** * Returns the server info for this connection. * * @return the server info for this connection */ - ServerInfo getServerInfo(); + ServerInfo serverInfo(); /** * Returns the player that this connection is associated with. * * @return the player for this connection */ - Player getPlayer(); + Player player(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java index 831e55af2..462f1310d 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java @@ -12,6 +12,7 @@ import com.velocitypowered.api.util.Favicon; import java.util.List; import java.util.Map; import java.util.Optional; +import net.kyori.adventure.text.Component; /** * Exposes certain proxy configuration information that plugins may use. @@ -51,7 +52,7 @@ public interface ProxyConfig { * * @return the motd component */ - net.kyori.adventure.text.Component getMotd(); + Component getMotd(); /** * Get the maximum players shown in the tab list. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java b/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java index adf5b07ee..19bb61211 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/crypto/IdentifiedKey.java @@ -25,7 +25,7 @@ public interface IdentifiedKey extends KeySigned { * * @return the RSA public key in question */ - PublicKey getSignedPublicKey(); + PublicKey publicKey(); /** @@ -45,14 +45,14 @@ public interface IdentifiedKey extends KeySigned { * @return the holder UUID or null if not present */ @Nullable - UUID getSignatureHolder(); + UUID signatureHolder(); /** * Retrieves the key revision. * * @return the key revision */ - Revision getKeyRevision(); + Revision revision(); /** * The different versions of player keys, per Minecraft version. @@ -69,11 +69,11 @@ public interface IdentifiedKey extends KeySigned { this.applicableTo = applicableTo; } - public Set getBackwardsCompatibleTo() { + public Set backwardsCompatibleTo() { return backwardsCompatibleTo; } - public Set getApplicableTo() { + public Set applicableTo() { return applicableTo; } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeyIdentifiable.java b/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeyIdentifiable.java index 80c14b189..bd4f2ed17 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeyIdentifiable.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeyIdentifiable.java @@ -20,5 +20,5 @@ public interface KeyIdentifiable { * * @return the key or null if not available */ - @Nullable IdentifiedKey getIdentifiedKey(); + @Nullable IdentifiedKey identifiedKey(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeySigned.java b/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeySigned.java index 8ad64c181..7f5ee6b60 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeySigned.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/crypto/KeySigned.java @@ -22,7 +22,7 @@ public interface KeySigned { * * @return the key */ - PublicKey getSigner(); + PublicKey signer(); /** * Returns the expiry time point of the key. @@ -32,7 +32,7 @@ public interface KeySigned { * * @return the expiry time point */ - Instant getExpiryTemporal(); + Instant signatureExpiry(); /** @@ -41,7 +41,7 @@ public interface KeySigned { * @return true if proxy time is after expiry time */ default boolean hasExpired() { - return Instant.now().isAfter(getExpiryTemporal()); + return Instant.now().isAfter(signatureExpiry()); } /** @@ -50,7 +50,7 @@ public interface KeySigned { * @return an RSA signature */ @Nullable - byte[] getSignature(); + byte[] signature(); /** * Validates the signature, expiry temporal and key against the @@ -71,7 +71,7 @@ public interface KeySigned { * * @return signature salt or null */ - default byte[] getSalt() { + default byte[] salt() { return null; } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/crypto/SignedMessage.java b/api/src/main/java/com/velocitypowered/api/proxy/crypto/SignedMessage.java index 6d833e27b..19ac8ac3f 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/crypto/SignedMessage.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/crypto/SignedMessage.java @@ -19,14 +19,14 @@ public interface SignedMessage extends KeySigned { * * @return the message */ - String getMessage(); + String message(); /** * Returns the signers UUID. * * @return the uuid */ - UUID getSignerUuid(); + UUID signerUuid(); /** * If true the signature of this message applies to a stylized component instead. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java index 8a21c6fb3..f5bc406b6 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java @@ -17,5 +17,5 @@ public interface ChannelIdentifier { * * @return the textual representation of the identifier */ - String getId(); + String id(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java index 9da9a7b4a..6e45efb48 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java @@ -58,7 +58,7 @@ public final class LegacyChannelIdentifier implements ChannelIdentifier { } @Override - public String getId() { + public String id() { return this.getName(); } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java index 98967cfd3..b003d1b20 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java @@ -128,7 +128,7 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier { } @Override - public String getId() { + public String id() { return namespace + ":" + name; } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java b/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java index 9c090b78e..8a9da8f22 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/ChatSession.java @@ -19,5 +19,5 @@ public interface ChatSession extends KeyIdentifiable { * * @return the session UUID */ - UUID getSessionId(); + UUID sessionId(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/PlayerSettings.java b/api/src/main/java/com/velocitypowered/api/proxy/player/PlayerSettings.java index 4745eea17..ce97ceb7e 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/PlayerSettings.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/PlayerSettings.java @@ -19,7 +19,7 @@ public interface PlayerSettings { * * @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 PlayerSettings { * * @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 PlayerSettings { * * @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(); /** * Returns whether the client explicitly allows listing on the diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java b/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java index c0023310c..1cb0a9ac2 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/ResourcePackInfo.java @@ -20,7 +20,7 @@ public interface ResourcePackInfo { * * @return the location of the resource-pack */ - String getUrl(); + String url(); /** * Gets the {@link Component} that is displayed on the resource-pack prompt. @@ -29,31 +29,31 @@ public interface ResourcePackInfo { * @return the prompt if present or null otherwise */ @Nullable - Component getPrompt(); + Component prompt(); /** * Gets whether or not the acceptance of the resource-pack is enforced. - * See {@link Builder#setShouldForce(boolean)} for more information. + * See {@link Builder#required(boolean)} for more information. * * @return whether or not to force usage of this resource-pack */ - boolean getShouldForce(); + boolean required(); /** * Gets the SHA-1 hash of the resource-pack - * See {@link Builder#setHash(byte[])} for more information. + * See {@link Builder#hash(byte[])} for more information. * * @return the hash if present or null otherwise */ @Nullable - byte[] getHash(); + byte[] hash(); /** * Gets the {@link Origin} of this resource-pack. * * @return the origin of the resource pack */ - Origin getOrigin(); + Origin origin(); /** * Gets the original {@link Origin} of the resource-pack. @@ -62,16 +62,15 @@ public interface ResourcePackInfo { * * @return the origin of the resource pack */ - Origin getOriginalOrigin(); + Origin originalOrigin(); /** * Returns a copy of this {@link ResourcePackInfo} instance as a builder so that it can * be modified. * It is not guaranteed that * {@code resourcePackInfo.asBuilder().build().equals(resourcePackInfo)} is true. That is due to - * the transient {@link ResourcePackInfo#getOrigin()} and - * {@link ResourcePackInfo#getOriginalOrigin()} fields. - * + * the transient {@link ResourcePackInfo#origin()} and + * {@link ResourcePackInfo#originalOrigin()} fields. * * @return a content-copy of this instance as a {@link ResourcePackInfo.Builder} */ @@ -82,8 +81,8 @@ public interface ResourcePackInfo { *

* It is not guaranteed that * {@code resourcePackInfo.asBuilder(resourcePackInfo.getUrl()).build().equals(resourcePackInfo)} - * is true, because the {@link ResourcePackInfo#getOrigin()} and - * {@link ResourcePackInfo#getOriginalOrigin()} fields are transient. + * is true, because the {@link ResourcePackInfo#origin()} and + * {@link ResourcePackInfo#originalOrigin()} fields are transient. * * @param newUrl The new URL to use in the updated builder. * @@ -114,7 +113,7 @@ public interface ResourcePackInfo { * * @param shouldForce whether or not to force the client to accept the resource pack */ - Builder setShouldForce(boolean shouldForce); + Builder required(boolean shouldForce); /** * Sets the SHA-1 hash of the provided resource pack. @@ -126,7 +125,7 @@ public interface ResourcePackInfo { * * @param hash the SHA-1 hash of the resource-pack */ - Builder setHash(@Nullable byte[] hash); + Builder hash(@Nullable byte[] hash); /** * Sets a {@link Component} to display on the download prompt. @@ -134,7 +133,7 @@ public interface ResourcePackInfo { * * @param prompt the component to display */ - Builder setPrompt(@Nullable Component prompt); + Builder prompt(@Nullable Component prompt); /** * Builds the {@link ResourcePackInfo} from the provided info for use with diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java b/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java index 4d03d3a87..59177a848 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java @@ -97,7 +97,7 @@ public interface TabList { * * @return immutable {@link Collection} of tab list entries */ - Collection getEntries(); + Collection entries(); /** * Clears all entries from the tab list. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java index 401d6a8da..e3171137d 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java @@ -26,12 +26,12 @@ public interface TabListEntry extends KeyIdentifiable { @Nullable ChatSession getChatSession(); @Override - default IdentifiedKey getIdentifiedKey() { + default IdentifiedKey identifiedKey() { ChatSession session = getChatSession(); if (session == null) { return null; } - return getChatSession().getIdentifiedKey(); + return getChatSession().identifiedKey(); } /** @@ -53,7 +53,7 @@ public interface TabListEntry extends KeyIdentifiable { /** * Returns {@link Optional} text {@link net.kyori.adventure.text.Component}, which if present is * the text displayed for {@code this} entry in the {@link TabList}, otherwise - * {@link GameProfile#getName()} is shown. + * {@link GameProfile#name()} is shown. * * @return {@link Optional} text {@link net.kyori.adventure.text.Component} of name displayed in * the tab list @@ -62,7 +62,7 @@ public interface TabListEntry extends KeyIdentifiable { /** * Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}. If - * {@code null}, {@link GameProfile#getName()} will be shown. + * {@code null}, {@link GameProfile#name()} will be shown. * * @param displayName to show in the {@link TabList} for {@code this} entry * @return {@code this}, for chaining diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/PingOptions.java b/api/src/main/java/com/velocitypowered/api/proxy/server/PingOptions.java index 51be358e4..388afb4d2 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/PingOptions.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/PingOptions.java @@ -41,7 +41,7 @@ public final class PingOptions { * * @return the emulated Minecraft version */ - public ProtocolVersion getProtocolVersion() { + public ProtocolVersion protocolVersion() { return this.protocolVersion; } @@ -50,7 +50,7 @@ public final class PingOptions { * * @return the server ping timeout in milliseconds */ - public long getTimeout() { + public long timeout() { return this.timeout; } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java b/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java index 6c794bf4c..e829fa16a 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java @@ -60,7 +60,7 @@ public final class QueryResponse { * * @return hostname */ - public String getHostname() { + public String hostname() { return hostname; } @@ -70,7 +70,7 @@ public final class QueryResponse { * * @return game version */ - public String getGameVersion() { + public String gameVersion() { return gameVersion; } @@ -80,7 +80,7 @@ public final class QueryResponse { * * @return map name */ - public String getMap() { + public String map() { return map; } @@ -89,7 +89,7 @@ public final class QueryResponse { * * @return online player count */ - public int getCurrentPlayers() { + public int currentPlayers() { return currentPlayers; } @@ -98,7 +98,7 @@ public final class QueryResponse { * * @return max player count */ - public int getMaxPlayers() { + public int maxPlayers() { return maxPlayers; } @@ -107,7 +107,7 @@ public final class QueryResponse { * * @return proxy hostname */ - public String getProxyHost() { + public String proxyHost() { return proxyHost; } @@ -116,7 +116,7 @@ public final class QueryResponse { * * @return proxy port */ - public int getProxyPort() { + public int proxyPort() { return proxyPort; } @@ -125,7 +125,7 @@ public final class QueryResponse { * * @return collection of players */ - public Collection getPlayers() { + public Collection players() { return players; } @@ -134,7 +134,7 @@ public final class QueryResponse { * * @return server software */ - public String getProxyVersion() { + public String proxyVersion() { return proxyVersion; } @@ -143,7 +143,7 @@ public final class QueryResponse { * * @return collection of plugins */ - public Collection getPlugins() { + public Collection plugins() { return plugins; } @@ -158,16 +158,16 @@ public final class QueryResponse { */ public Builder toBuilder() { return QueryResponse.builder() - .hostname(getHostname()) - .gameVersion(getGameVersion()) - .map(getMap()) - .currentPlayers(getCurrentPlayers()) - .maxPlayers(getMaxPlayers()) - .proxyHost(getProxyHost()) - .proxyPort(getProxyPort()) - .players(getPlayers()) - .proxyVersion(getProxyVersion()) - .plugins(getPlugins()); + .hostname(hostname()) + .gameVersion(gameVersion()) + .map(map()) + .currentPlayers(currentPlayers()) + .maxPlayers(maxPlayers()) + .proxyHost(proxyHost()) + .proxyPort(proxyPort()) + .players(players()) + .proxyVersion(proxyVersion()) + .plugins(plugins()); } /** @@ -347,7 +347,7 @@ public final class QueryResponse { } /** - * Removes all players from the builder. This does not affect {@link #getCurrentPlayers()}. + * Removes all players from the builder. This does not affect {@link #currentPlayers()}. * * @return this builder, for chaining */ diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java b/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java index 1766833ec..64f5390db 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java @@ -25,14 +25,14 @@ public interface RegisteredServer extends ChannelMessageSink, Audience { * * @return the server info */ - ServerInfo getServerInfo(); + ServerInfo serverInfo(); /** * Returns a list of all the players currently connected to this server on this proxy. * * @return the players on this proxy */ - Collection getPlayersConnected(); + Collection players(); /** * Attempts to ping the remote server and return the server list ping result. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java index fa8c7c857..d7ce0f2c1 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java @@ -32,11 +32,11 @@ public final class ServerInfo implements Comparable { this.address = Preconditions.checkNotNull(address, "address"); } - public final String getName() { + public String name() { return name; } - public final SocketAddress getAddress() { + public SocketAddress address() { return address; } @@ -68,6 +68,6 @@ public final class ServerInfo implements Comparable { @Override public int compareTo(ServerInfo o) { - return this.name.compareTo(o.getName()); + return this.name.compareTo(o.name()); } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java index a7d9518f0..0503cb9f4 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -27,12 +28,12 @@ public final class ServerPing { private final Version version; private final @Nullable Players players; - private final net.kyori.adventure.text.Component description; + private final Component description; private final @Nullable Favicon favicon; private final @Nullable ModInfo modinfo; public ServerPing(Version version, @Nullable Players players, - net.kyori.adventure.text.Component description, @Nullable Favicon favicon) { + Component description, @Nullable Favicon favicon) { this(version, players, description, favicon, ModInfo.DEFAULT); } @@ -46,7 +47,7 @@ public final class ServerPing { * @param modinfo the mods this server runs */ public ServerPing(Version version, @Nullable Players players, - net.kyori.adventure.text.Component description, @Nullable Favicon favicon, + Component description, @Nullable Favicon favicon, @Nullable ModInfo modinfo) { this.version = Preconditions.checkNotNull(version, "version"); this.players = players; @@ -55,23 +56,23 @@ public final class ServerPing { this.modinfo = modinfo; } - public Version getVersion() { + public Version version() { return version; } - public Optional getPlayers() { + public Optional players() { return Optional.ofNullable(players); } - public net.kyori.adventure.text.Component getDescriptionComponent() { + public Component description() { return description; } - public Optional getFavicon() { + public Optional favicon() { return Optional.ofNullable(favicon); } - public Optional getModinfo() { + public Optional modInfo() { return Optional.ofNullable(modinfo); } @@ -129,8 +130,8 @@ public final class ServerPing { builder.favicon = favicon; builder.nullOutModinfo = modinfo == null; if (modinfo != null) { - builder.modType = modinfo.getType(); - builder.mods.addAll(modinfo.getMods()); + builder.modType = modinfo.type(); + builder.mods.addAll(modinfo.mods()); } return builder; } @@ -150,7 +151,7 @@ public final class ServerPing { private final List samplePlayers = new ArrayList<>(); private String modType = "FML"; private final List mods = new ArrayList<>(); - private net.kyori.adventure.text.Component description; + private Component description; private @Nullable Favicon favicon; private boolean nullOutPlayers; private boolean nullOutModinfo; @@ -197,9 +198,9 @@ public final class ServerPing { */ public Builder mods(ModInfo mods) { Preconditions.checkNotNull(mods, "mods"); - this.modType = mods.getType(); + this.modType = mods.type(); this.mods.clear(); - this.mods.addAll(mods.getMods()); + this.mods.addAll(mods.mods()); return this; } @@ -223,7 +224,7 @@ public final class ServerPing { return this; } - public Builder description(net.kyori.adventure.text.Component description) { + public Builder description(Component description) { this.description = Preconditions.checkNotNull(description, "description"); return this; } @@ -272,7 +273,7 @@ public final class ServerPing { return samplePlayers; } - public Optional getDescriptionComponent() { + public Optional getDescriptionComponent() { return Optional.ofNullable(description); } diff --git a/api/src/main/java/com/velocitypowered/api/util/Favicon.java b/api/src/main/java/com/velocitypowered/api/util/Favicon.java index 4b2e74193..e6d6039bf 100644 --- a/api/src/main/java/com/velocitypowered/api/util/Favicon.java +++ b/api/src/main/java/com/velocitypowered/api/util/Favicon.java @@ -39,11 +39,11 @@ public final class Favicon { } /** - * Returns the Base64-encoded URI for this image. + * Returns the Base64-encoded URL for this image. * * @return a URL representing this favicon */ - public String getBase64Url() { + public String url() { return base64Url; } diff --git a/api/src/main/java/com/velocitypowered/api/util/GameProfile.java b/api/src/main/java/com/velocitypowered/api/util/GameProfile.java index 27c421380..f3bae8d9f 100644 --- a/api/src/main/java/com/velocitypowered/api/util/GameProfile.java +++ b/api/src/main/java/com/velocitypowered/api/util/GameProfile.java @@ -58,7 +58,7 @@ public final class GameProfile { * * @return the undashed UUID */ - public String getUndashedId() { + public String undashedId() { return undashedId; } @@ -67,7 +67,7 @@ public final class GameProfile { * * @return the UUID */ - public UUID getId() { + public UUID uuid() { return id; } @@ -76,7 +76,7 @@ public final class GameProfile { * * @return the username */ - public String getName() { + public String name() { return name; } @@ -85,7 +85,7 @@ public final class GameProfile { * * @return the properties associated with this profile */ - public List getProperties() { + public List properties() { return properties; } @@ -200,15 +200,15 @@ public final class GameProfile { this.signature = Preconditions.checkNotNull(signature, "signature"); } - public String getName() { + public String name() { return name; } - public String getValue() { + public String value() { return value; } - public String getSignature() { + public String signature() { return signature; } diff --git a/api/src/main/java/com/velocitypowered/api/util/ModInfo.java b/api/src/main/java/com/velocitypowered/api/util/ModInfo.java index 8a51f3221..945246178 100644 --- a/api/src/main/java/com/velocitypowered/api/util/ModInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/ModInfo.java @@ -34,11 +34,11 @@ public final class ModInfo { this.modList = ImmutableList.copyOf(modList); } - public String getType() { + public String type() { return type; } - public List getMods() { + public List mods() { return modList; } @@ -81,11 +81,11 @@ public final class ModInfo { this.version = Preconditions.checkNotNull(version, "version"); } - public String getId() { + public String id() { return id; } - public String getVersion() { + public String version() { return version; } diff --git a/api/src/main/java/com/velocitypowered/api/util/ProxyVersion.java b/api/src/main/java/com/velocitypowered/api/util/ProxyVersion.java index abc3a14aa..5b5157307 100644 --- a/api/src/main/java/com/velocitypowered/api/util/ProxyVersion.java +++ b/api/src/main/java/com/velocitypowered/api/util/ProxyVersion.java @@ -33,15 +33,15 @@ public final class ProxyVersion { this.version = Preconditions.checkNotNull(version, "version"); } - public String getName() { + public String name() { return name; } - public String getVendor() { + public String vendor() { return vendor; } - public String getVersion() { + public String version() { return version; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java index 89f63b56f..50108f8ee 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java @@ -116,7 +116,7 @@ public class Metrics { () -> server.getConfiguration().isOnlineMode() ? "online" : "offline") ); metrics.addCustomChart(new SimplePie("velocity_version", - () -> server.getVersion().getVersion())); + () -> server.getVersion().version())); metrics.addCustomChart(new DrilldownPie("java_version", () -> { Map> map = new HashMap<>(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index f4ccf65b5..5ac236f43 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -200,7 +200,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { @EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler", "console", "cm", "configuration"}) void start() { - logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion()); + logger.info("Booting up {} {}...", getVersion().name(), getVersion().version()); console.setupStreams(); registerTranslations(); @@ -350,19 +350,19 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } // Register the plugin main classes so that we can fire the proxy initialize event - for (PluginContainer plugin : pluginManager.getPlugins()) { - Optional instance = plugin.getInstance(); + for (PluginContainer plugin : pluginManager.plugins()) { + Optional instance = plugin.instance(); if (instance.isPresent()) { try { eventManager.registerInternally(plugin, instance.get()); } catch (Exception e) { logger.error("Unable to register plugin listener for {}", - plugin.getDescription().getName().orElse(plugin.getDescription().getId()), e); + plugin.description().name().orElse(plugin.description().id()), e); } } } - logger.info("Loaded {} plugins", pluginManager.getPlugins().size()); + logger.info("Loaded {} plugins", pluginManager.plugins().size()); } public Bootstrap createBootstrap(@Nullable EventLoopGroup group, SocketAddress target) { @@ -404,15 +404,15 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { Optional rs = servers.getServer(entry.getKey()); if (!rs.isPresent()) { servers.register(newInfo); - } else if (!rs.get().getServerInfo().equals(newInfo)) { - for (Player player : rs.get().getPlayersConnected()) { + } else if (!rs.get().serverInfo().equals(newInfo)) { + for (Player player : rs.get().players()) { if (!(player instanceof ConnectedPlayer)) { throw new IllegalStateException("ConnectedPlayer not found for player " + player - + " in server " + rs.get().getServerInfo().getName()); + + " in server " + rs.get().serverInfo().name()); } evacuate.add((ConnectedPlayer) player); } - servers.unregister(rs.get().getServerInfo()); + servers.unregister(rs.get().serverInfo()); servers.register(newInfo); } } @@ -591,9 +591,9 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { if (configuration.isOnlineMode() && configuration.isOnlineModeKickExistingPlayers()) { return true; } - String lowerName = connection.getUsername().toLowerCase(Locale.US); + String lowerName = connection.username().toLowerCase(Locale.US); return !(connectionsByName.containsKey(lowerName) - || connectionsByUuid.containsKey(connection.getUniqueId())); + || connectionsByUuid.containsKey(connection.uuid())); } /** @@ -603,25 +603,25 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { * @return {@code true} if we registered the connection, {@code false} if not */ public boolean registerConnection(ConnectedPlayer connection) { - String lowerName = connection.getUsername().toLowerCase(Locale.US); + String lowerName = connection.username().toLowerCase(Locale.US); if (!this.configuration.isOnlineModeKickExistingPlayers()) { if (connectionsByName.putIfAbsent(lowerName, connection) != null) { return false; } - if (connectionsByUuid.putIfAbsent(connection.getUniqueId(), connection) != null) { + if (connectionsByUuid.putIfAbsent(connection.uuid(), connection) != null) { connectionsByName.remove(lowerName, connection); return false; } } else { - ConnectedPlayer existing = connectionsByUuid.get(connection.getUniqueId()); + ConnectedPlayer existing = connectionsByUuid.get(connection.uuid()); if (existing != null) { existing.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login")); } // We can now replace the entries as needed. connectionsByName.put(lowerName, connection); - connectionsByUuid.put(connection.getUniqueId(), connection); + connectionsByUuid.put(connection.uuid(), connection); } return true; } @@ -632,8 +632,8 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { * @param connection the connection to unregister */ public void unregisterConnection(ConnectedPlayer connection) { - connectionsByName.remove(connection.getUsername().toLowerCase(Locale.US), connection); - connectionsByUuid.remove(connection.getUniqueId(), connection); + connectionsByName.remove(connection.username().toLowerCase(Locale.US), connection); + connectionsByUuid.remove(connection.uuid(), connection); bossBarManager.onDisconnect(connection); } @@ -653,7 +653,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { public Collection matchPlayer(String partialName) { Objects.requireNonNull(partialName); - return getAllPlayers().stream().filter(p -> p.getUsername() + return getAllPlayers().stream().filter(p -> p.username() .regionMatches(true, 0, partialName, 0, partialName.length())) .collect(Collectors.toList()); } @@ -662,7 +662,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { public Collection matchServer(String partialName) { Objects.requireNonNull(partialName); - return getAllServers().stream().filter(s -> s.getServerInfo().getName() + return getAllServers().stream().filter(s -> s.serverInfo().name() .regionMatches(true, 0, partialName, 0, partialName.length())) .collect(Collectors.toList()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 7b5176124..0b743371c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -97,21 +97,21 @@ public class VelocityCommandManager implements CommandManager { } @Override - public CommandMeta.Builder metaBuilder(final String alias) { + public CommandMeta.Builder buildMeta(final String alias) { Preconditions.checkNotNull(alias, "alias"); return new VelocityCommandMeta.Builder(alias); } @Override - public CommandMeta.Builder metaBuilder(final BrigadierCommand command) { + public CommandMeta.Builder buildMeta(final BrigadierCommand command) { Preconditions.checkNotNull(command, "command"); - return new VelocityCommandMeta.Builder(command.getNode().getName()); + return new VelocityCommandMeta.Builder(command.node().getName()); } @Override public void register(final BrigadierCommand command) { Preconditions.checkNotNull(command, "command"); - register(metaBuilder(command).build(), command); + register(buildMeta(command).build(), command); } @Override @@ -151,7 +151,7 @@ public class VelocityCommandManager implements CommandManager { final Command command, final CommandMeta meta) { final Class superInterface = registrar.registrableSuperInterface(); registrar.register(meta, superInterface.cast(command)); - for (String alias : meta.getAliases()) { + for (String alias : meta.aliases()) { commandMetas.put(alias, meta); } } @@ -188,7 +188,7 @@ public class VelocityCommandManager implements CommandManager { try { // The literals of secondary aliases will preserve the children of // the removed literal in the graph. - for (String alias : meta.getAliases()) { + for (String alias : meta.aliases()) { final String lowercased = alias.toLowerCase(Locale.ENGLISH); if (commandMetas.remove(lowercased, meta)) { dispatcher.getRoot().removeChildByName(lowercased); @@ -200,7 +200,7 @@ public class VelocityCommandManager implements CommandManager { } @Override - public @Nullable CommandMeta getCommandMeta(String alias) { + public @Nullable CommandMeta commandMeta(String alias) { Preconditions.checkNotNull(alias, "alias"); return commandMetas.get(alias); } @@ -250,8 +250,8 @@ public class VelocityCommandManager implements CommandManager { Preconditions.checkNotNull(cmdLine, "cmdLine"); return callCommandEvent(source, cmdLine).thenApplyAsync(event -> { - CommandResult commandResult = event.getResult(); - if (commandResult.isForwardToServer() || !commandResult.isAllowed()) { + CommandResult commandResult = event.result(); + if (commandResult.isForwardToServer() || !commandResult.allowed()) { return false; } return executeImmediately0(source, commandResult.getCommand().orElse(event.getCommand())); @@ -321,7 +321,7 @@ public class VelocityCommandManager implements CommandManager { } @Override - public Collection getAliases() { + public Collection aliases() { lock.readLock().lock(); try { // A RootCommandNode may only contain LiteralCommandNode children instances diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java index 39b243999..cc7f2de66 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java @@ -120,7 +120,7 @@ public final class VelocityCommandMeta implements CommandMeta { */ // This is a static method because most methods take a CommandMeta. public static Stream> copyHints(final CommandMeta meta) { - return meta.getHints().stream().map(VelocityCommandMeta::copyForHinting); + return meta.hints().stream().map(VelocityCommandMeta::copyForHinting); } private final Set aliases; @@ -138,17 +138,17 @@ public final class VelocityCommandMeta implements CommandMeta { } @Override - public Collection getAliases() { + public Collection aliases() { return this.aliases; } @Override - public Collection> getHints() { + public Collection> hints() { return this.hints; } @Override - public @Nullable Object getPlugin() { + public @Nullable Object plugin() { return plugin; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java index 9f28e4fba..e956881f4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java @@ -32,7 +32,7 @@ class BuiltinCommandUtil { static List sortedServerList(ProxyServer proxy) { List servers = new ArrayList<>(proxy.getAllServers()); - servers.sort(Comparator.comparing(RegisteredServer::getServerInfo)); + servers.sort(Comparator.comparing(RegisteredServer::serverInfo)); return Collections.unmodifiableList(servers); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java index 5ad86511c..de5b0a9fe 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java @@ -67,7 +67,7 @@ public class GlistCommand { .argument(SERVER_ARG, StringArgumentType.string()) .suggests((context, builder) -> { for (RegisteredServer server : server.getAllServers()) { - builder.suggest(server.getServerInfo().getName()); + builder.suggest(server.serverInfo().name()); } builder.suggest("all"); return builder.buildFuture(); @@ -116,13 +116,13 @@ public class GlistCommand { } private void sendServerPlayers(CommandSource target, RegisteredServer server, boolean fromAll) { - List onServer = ImmutableList.copyOf(server.getPlayersConnected()); + List onServer = ImmutableList.copyOf(server.players()); if (onServer.isEmpty() && fromAll) { return; } TextComponent.Builder builder = Component.text() - .append(Component.text("[" + server.getServerInfo().getName() + "] ", + .append(Component.text("[" + server.serverInfo().name() + "] ", NamedTextColor.DARK_AQUA)) .append(Component.text("(" + onServer.size() + ")", NamedTextColor.GRAY)) .append(Component.text(": ")) @@ -130,7 +130,7 @@ public class GlistCommand { for (int i = 0; i < onServer.size(); i++) { Player player = onServer.get(i); - builder.append(Component.text(player.getUsername())); + builder.append(Component.text(player.username())); if (i + 1 < onServer.size()) { builder.append(Component.text(", ")); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java index a1bb1e20f..948db41e2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java @@ -77,8 +77,8 @@ public class ServerCommand implements SimpleCommand { } private void outputServerInformation(Player executor) { - String currentServer = executor.getCurrentServer().map(ServerConnection::getServerInfo) - .map(ServerInfo::getName).orElse(""); + String currentServer = executor.connectedServer().map(ServerConnection::serverInfo) + .map(ServerInfo::name).orElse(""); executor.sendMessage(Component.translatable( "velocity.command.server-current-server", NamedTextColor.YELLOW, @@ -108,10 +108,10 @@ public class ServerCommand implements SimpleCommand { } private TextComponent formatServerComponent(String currentPlayerServer, RegisteredServer server) { - ServerInfo serverInfo = server.getServerInfo(); - TextComponent serverTextComponent = Component.text(serverInfo.getName()); + ServerInfo serverInfo = server.serverInfo(); + TextComponent serverTextComponent = Component.text(serverInfo.name()); - int connectedPlayers = server.getPlayersConnected().size(); + int connectedPlayers = server.players().size(); TranslatableComponent playersTextComponent; if (connectedPlayers == 1) { playersTextComponent = Component.translatable( @@ -121,7 +121,7 @@ public class ServerCommand implements SimpleCommand { "velocity.command.server-tooltip-players-online"); } playersTextComponent = playersTextComponent.args(Component.text(connectedPlayers)); - if (serverInfo.getName().equals(currentPlayerServer)) { + if (serverInfo.name().equals(currentPlayerServer)) { serverTextComponent = serverTextComponent.color(NamedTextColor.GREEN) .hoverEvent( showText( @@ -131,7 +131,7 @@ public class ServerCommand implements SimpleCommand { ); } else { serverTextComponent = serverTextComponent.color(NamedTextColor.GRAY) - .clickEvent(ClickEvent.runCommand("/server " + serverInfo.getName())) + .clickEvent(ClickEvent.runCommand("/server " + serverInfo.name())) .hoverEvent( showText( Component.translatable("velocity.command.server-tooltip-offer-connect-server") @@ -146,7 +146,7 @@ public class ServerCommand implements SimpleCommand { public List suggest(final SimpleCommand.Invocation invocation) { final String[] currentArgs = invocation.arguments(); Stream possibilities = server.getAllServers().stream() - .map(rs -> rs.getServerInfo().getName()); + .map(rs -> rs.serverInfo().name()); if (currentArgs.length == 0) { return possibilities.collect(Collectors.toList()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index 2228f3d7e..47fd58393 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -222,19 +222,19 @@ public class VelocityCommand implements SimpleCommand { ProxyVersion version = server.getVersion(); - Component velocity = Component.text().content(version.getName() + " ") + Component velocity = Component.text().content(version.name() + " ") .decoration(TextDecoration.BOLD, true) .color(VELOCITY_COLOR) - .append(Component.text(version.getVersion()).decoration(TextDecoration.BOLD, false)) + .append(Component.text(version.version()).decoration(TextDecoration.BOLD, false)) .build(); Component copyright = Component .translatable("velocity.command.version-copyright", - Component.text(version.getVendor()), - Component.text(version.getName())); + Component.text(version.vendor()), + Component.text(version.name())); source.sendMessage(velocity); source.sendMessage(copyright); - if (version.getName().equals("Velocity")) { + if (version.name().equals("Velocity")) { TextComponent embellishment = Component.text() .append(Component.text().content("velocitypowered.com") .color(NamedTextColor.GREEN) @@ -274,7 +274,7 @@ public class VelocityCommand implements SimpleCommand { return; } - List plugins = ImmutableList.copyOf(server.getPluginManager().getPlugins()); + List plugins = ImmutableList.copyOf(server.getPluginManager().plugins()); int pluginCount = plugins.size(); if (pluginCount == 0) { @@ -286,7 +286,7 @@ public class VelocityCommand implements SimpleCommand { TextComponent.Builder listBuilder = Component.text(); for (int i = 0; i < pluginCount; i++) { PluginContainer plugin = plugins.get(i); - listBuilder.append(componentForPlugin(plugin.getDescription())); + listBuilder.append(componentForPlugin(plugin.description())); if (i + 1 < pluginCount) { listBuilder.append(Component.text(", ")); } @@ -300,37 +300,37 @@ public class VelocityCommand implements SimpleCommand { } private TextComponent componentForPlugin(PluginDescription description) { - String pluginInfo = description.getName().orElse(description.getId()) - + description.getVersion().map(v -> " " + v).orElse(""); + String pluginInfo = description.name().orElse(description.id()) + + description.version().map(v -> " " + v).orElse(""); TextComponent.Builder hoverText = Component.text().content(pluginInfo); - description.getUrl().ifPresent(url -> { + description.url().ifPresent(url -> { hoverText.append(Component.newline()); hoverText.append(Component.translatable( "velocity.command.plugin-tooltip-website", Component.text(url))); }); - if (!description.getAuthors().isEmpty()) { + if (!description.authors().isEmpty()) { hoverText.append(Component.newline()); - if (description.getAuthors().size() == 1) { + if (description.authors().size() == 1) { hoverText.append(Component.translatable("velocity.command.plugin-tooltip-author", - Component.text(description.getAuthors().get(0)))); + Component.text(description.authors().get(0)))); } else { hoverText.append( Component.translatable("velocity.command.plugin-tooltip-author", - Component.text(String.join(", ", description.getAuthors())) + Component.text(String.join(", ", description.authors())) ) ); } } - description.getDescription().ifPresent(pdesc -> { + description.description().ifPresent(pdesc -> { hoverText.append(Component.newline()); hoverText.append(Component.newline()); hoverText.append(Component.text(pdesc)); }); - return Component.text(description.getId(), NamedTextColor.GRAY) + return Component.text(description.id(), NamedTextColor.GRAY) .hoverEvent(HoverEvent.showText(hoverText.build())); } @@ -359,7 +359,7 @@ public class VelocityCommand implements SimpleCommand { Collection allServers = ImmutableSet.copyOf(server.getAllServers()); JsonObject servers = new JsonObject(); for (RegisteredServer iter : allServers) { - servers.add(iter.getServerInfo().getName(), + servers.add(iter.serverInfo().name(), InformationUtils.collectServerInfo(iter)); } JsonArray connectOrder = new JsonArray(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/BrigadierCommandRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/BrigadierCommandRegistrar.java index bc8d02de4..28feaf69f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/BrigadierCommandRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/BrigadierCommandRegistrar.java @@ -39,14 +39,14 @@ public final class BrigadierCommandRegistrar extends AbstractCommandRegistrar
literal = command.getNode(); + final LiteralCommandNode literal = command.node(); final String primaryAlias = literal.getName(); if (VelocityCommands.isValidAlias(primaryAlias)) { // Register directly without copying this.register(literal); } - for (final String alias : meta.getAliases()) { + for (final String alias : meta.aliases()) { if (primaryAlias.equals(alias)) { continue; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/InvocableCommandRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/InvocableCommandRegistrar.java index a526fe3de..569db0176 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/InvocableCommandRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/registrar/InvocableCommandRegistrar.java @@ -57,7 +57,7 @@ abstract class InvocableCommandRegistrar, @Override public void register(final CommandMeta meta, final T command) { - final Iterator aliases = meta.getAliases().iterator(); + final Iterator aliases = meta.aliases().iterator(); final String primaryAlias = aliases.next(); final LiteralCommandNode literal = diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index 6c050755a..90efef5c1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -88,7 +88,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { this.server = server; this.serverConn = serverConn; - this.playerConnection = serverConn.getPlayer().getConnection(); + this.playerConnection = serverConn.player().getConnection(); MinecraftSessionHandler psh = playerConnection.getActiveSessionHandler(); if (!(psh instanceof ClientPlaySessionHandler)) { @@ -98,12 +98,12 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { this.playerSessionHandler = (ClientPlaySessionHandler) psh; this.bungeecordMessageResponder = new BungeeCordMessageResponder(server, - serverConn.getPlayer()); + serverConn.player()); } @Override public void activated() { - serverConn.getServer().addPlayer(serverConn.getPlayer()); + serverConn.server().addPlayer(serverConn.player()); MinecraftConnection serverMc = serverConn.ensureConnected(); if (server.getConfiguration().isBungeePluginChannelEnabled()) { @@ -130,7 +130,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { smc.setAutoReading(false); // Even when not auto reading messages are still decoded. Decode them with the correct state smc.getChannel().pipeline().get(MinecraftDecoder.class).setState(StateRegistry.CONFIG); - serverConn.getPlayer().switchToConfigState(); + serverConn.player().switchToConfigState(); return true; } @@ -149,7 +149,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(Disconnect packet) { serverConn.disconnect(); - serverConn.getPlayer().handleConnectionException(serverConn.getServer(), packet, true); + serverConn.player().handleConnectionException(serverConn.server(), packet, true); return true; } @@ -167,14 +167,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { public boolean handle(ResourcePackRequest packet) { ResourcePackInfo.Builder builder = new VelocityResourcePackInfo.BuilderImpl( Preconditions.checkNotNull(packet.getUrl())) - .setPrompt(packet.getPrompt()) - .setShouldForce(packet.isRequired()) + .prompt(packet.getPrompt()) + .required(packet.isRequired()) .setOrigin(ResourcePackInfo.Origin.DOWNSTREAM_SERVER); String hash = packet.getHash(); if (hash != null && !hash.isEmpty()) { if (PLAUSIBLE_SHA1_HASH.matcher(hash).matches()) { - builder.setHash(ByteBufUtil.decodeHexDump(hash)); + builder.hash(ByteBufUtil.decodeHexDump(hash)); } } @@ -185,14 +185,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { if (playerConnection.isClosed()) { return; } - if (serverResourcePackSendEvent.getResult().isAllowed()) { - ResourcePackInfo toSend = serverResourcePackSendEvent.getProvidedResourcePack(); - if (toSend != serverResourcePackSendEvent.getReceivedResourcePack()) { + if (serverResourcePackSendEvent.result().allowed()) { + ResourcePackInfo toSend = serverResourcePackSendEvent.providedResourcePack(); + if (toSend != serverResourcePackSendEvent.receivedResourcePack()) { ((VelocityResourcePackInfo) toSend) .setOriginalOrigin(ResourcePackInfo.Origin.DOWNSTREAM_SERVER); } - serverConn.getPlayer().queueResourcePack(toSend); + serverConn.player().queueResourcePack(toSend); } else if (serverConn.getConnection() != null) { serverConn.getConnection().write(new ResourcePackResponse( packet.getHash(), @@ -231,7 +231,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { return true; } - if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) { + if (serverConn.getPhase().handle(serverConn, serverConn.player(), packet)) { // Handled. return true; } @@ -242,9 +242,9 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } byte[] copy = ByteBufUtil.getBytes(packet.content()); - PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id, copy); + PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.player(), id, copy); server.getEventManager().fire(event).thenAcceptAsync(pme -> { - if (pme.getResult().isAllowed() && !playerConnection.isClosed()) { + if (pme.result().allowed() && !playerConnection.isClosed()) { PluginMessage copied = new PluginMessage(packet.getChannel(), Unpooled.wrappedBuffer(copy)); playerConnection.write(copied); } @@ -263,19 +263,19 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(LegacyPlayerListItem packet) { - serverConn.getPlayer().getTabList().processLegacy(packet); + serverConn.player().tabList().processLegacy(packet); return false; } @Override public boolean handle(UpsertPlayerInfo packet) { - serverConn.getPlayer().getTabList().processUpdate(packet); + serverConn.player().tabList().processUpdate(packet); return false; } @Override public boolean handle(RemovePlayerInfo packet) { - serverConn.getPlayer().getTabList().processRemove(packet); + serverConn.player().tabList().processRemove(packet); return false; } @@ -285,11 +285,11 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { if (server.getConfiguration().isAnnounceProxyCommands()) { // Inject commands from the proxy. final CommandGraphInjector injector = server.getCommandManager().getInjector(); - injector.inject(rootNode, serverConn.getPlayer()); + injector.inject(rootNode, serverConn.player()); } server.getEventManager().fire( - new PlayerAvailableCommandsEvent(serverConn.getPlayer(), rootNode)) + new PlayerAvailableCommandsEvent(serverConn.player(), rootNode)) .thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop()) .exceptionally((ex) -> { logger.error("Exception while handling available commands for {}", playerConnection, ex); @@ -300,12 +300,12 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ServerData packet) { - server.getServerListPingHandler().getInitialPing(this.serverConn.getPlayer()).thenComposeAsync( + server.getServerListPingHandler().getInitialPing(this.serverConn.player()).thenComposeAsync( ping -> server.getEventManager() - .fire(new ProxyPingEvent(this.serverConn.getPlayer(), ping)), + .fire(new ProxyPingEvent(this.serverConn.player(), ping)), playerConnection.eventLoop()).thenAcceptAsync(pingEvent -> this.playerConnection.write( - new ServerData(pingEvent.getPing().getDescriptionComponent(), - pingEvent.getPing().getFavicon().orElse(null), packet.isSecureChatEnforced())), + new ServerData(pingEvent.ping().description(), + pingEvent.ping().favicon().orElse(null), packet.isSecureChatEnforced())), playerConnection.eventLoop()); return true; } @@ -340,7 +340,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public void exception(Throwable throwable) { exceptionTriggered = true; - serverConn.getPlayer().handleConnectionException(serverConn.getServer(), throwable, + serverConn.player().handleConnectionException(serverConn.server(), throwable, !(throwable instanceof ReadTimeoutException)); } @@ -350,14 +350,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public void disconnected() { - serverConn.getServer().removePlayer(serverConn.getPlayer()); + serverConn.server().removePlayer(serverConn.player()); if (!serverConn.isGracefulDisconnect() && !exceptionTriggered) { if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) { - serverConn.getPlayer().handleConnectionException(serverConn.getServer(), + serverConn.player().handleConnectionException(serverConn.server(), Disconnect.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, ProtocolVersion.MINECRAFT_1_16), true); } else { - serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); + serverConn.player().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java index 831fe0581..0d9cc5b1e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java @@ -72,7 +72,7 @@ public class BungeeCordMessageResponder { } public static boolean isBungeeCordMessage(PluginMessage message) { - return MODERN_CHANNEL.getId().equals(message.getChannel()) || LEGACY_CHANNEL.getId() + return MODERN_CHANNEL.id().equals(message.getChannel()) || LEGACY_CHANNEL.id() .equals(message.getChannel()); } @@ -98,7 +98,7 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("IP"); - SocketAddress address = player.getRemoteAddress(); + SocketAddress address = player.remoteAddress(); if (address instanceof InetSocketAddress) { InetSocketAddress serverInetAddr = (InetSocketAddress) address; out.writeUTF(serverInetAddr.getHostString()); @@ -121,9 +121,9 @@ public class BungeeCordMessageResponder { out.writeInt(proxy.getPlayerCount()); } else { proxy.getServer(target).ifPresent(rs -> { - int playersOnServer = rs.getPlayersConnected().size(); + int playersOnServer = rs.players().size(); out.writeUTF("PlayerCount"); - out.writeUTF(rs.getServerInfo().getName()); + out.writeUTF(rs.serverInfo().name()); out.writeInt(playersOnServer); }); } @@ -146,17 +146,17 @@ public class BungeeCordMessageResponder { StringJoiner joiner = new StringJoiner(", "); for (Player online : proxy.getAllPlayers()) { - joiner.add(online.getUsername()); + joiner.add(online.username()); } out.writeUTF(joiner.toString()); } else { proxy.getServer(target).ifPresent(info -> { out.writeUTF("PlayerList"); - out.writeUTF(info.getServerInfo().getName()); + out.writeUTF(info.serverInfo().name()); StringJoiner joiner = new StringJoiner(", "); - for (Player online : info.getPlayersConnected()) { - joiner.add(online.getUsername()); + for (Player online : info.players()) { + joiner.add(online.username()); } out.writeUTF(joiner.toString()); }); @@ -172,7 +172,7 @@ public class BungeeCordMessageResponder { private void processGetServers() { StringJoiner joiner = new StringJoiner(", "); for (RegisteredServer server : proxy.getAllServers()) { - joiner.add(server.getServerInfo().getName()); + joiner.add(server.serverInfo().name()); } ByteBuf buf = Unpooled.buffer(); @@ -210,7 +210,7 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("GetServer"); - out.writeUTF(player.ensureAndGetCurrentServer().getServerInfo().getName()); + out.writeUTF(player.ensureAndGetCurrentServer().serverInfo().name()); sendResponseOnConnection(buf); } @@ -220,7 +220,7 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("UUID"); - out.writeUTF(UuidUtils.toUndashed(player.getUniqueId())); + out.writeUTF(UuidUtils.toUndashed(player.uuid())); sendResponseOnConnection(buf); } @@ -231,8 +231,8 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("UUIDOther"); - out.writeUTF(player.getUsername()); - out.writeUTF(UuidUtils.toUndashed(player.getUniqueId())); + out.writeUTF(player.username()); + out.writeUTF(UuidUtils.toUndashed(player.uuid())); sendResponseOnConnection(buf); }); @@ -244,8 +244,8 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("IPOther"); - out.writeUTF(player.getUsername()); - SocketAddress address = player.getRemoteAddress(); + out.writeUTF(player.username()); + SocketAddress address = player.remoteAddress(); if (address instanceof InetSocketAddress) { InetSocketAddress serverInetAddr = (InetSocketAddress) address; out.writeUTF(serverInetAddr.getHostString()); @@ -265,8 +265,8 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("ServerIP"); - out.writeUTF(info.getServerInfo().getName()); - SocketAddress address = info.getServerInfo().getAddress(); + out.writeUTF(info.serverInfo().name()); + SocketAddress address = info.serverInfo().address(); if (address instanceof InetSocketAddress) { InetSocketAddress serverInetAddr = (InetSocketAddress) address; out.writeUTF(serverInetAddr.getHostString()); @@ -298,12 +298,12 @@ public class BungeeCordMessageResponder { private void processForwardToServer(ByteBufDataInput in) { String target = in.readUTF(); ByteBuf toForward = in.unwrap().copy(); - final ServerInfo currentUserServer = player.getCurrentServer() - .map(ServerConnection::getServerInfo).orElse(null); + final ServerInfo currentUserServer = player.connectedServer() + .map(ServerConnection::serverInfo).orElse(null); if (target.equals("ALL") || target.equals("ONLINE")) { try { for (RegisteredServer rs : proxy.getAllServers()) { - if (!rs.getServerInfo().equals(currentUserServer)) { + if (!rs.serverInfo().equals(currentUserServer)) { ((VelocityRegisteredServer) rs).sendPluginMessage(LEGACY_CHANNEL, toForward.retainedSlice()); } @@ -322,8 +322,8 @@ public class BungeeCordMessageResponder { } static String getBungeeCordChannel(ProtocolVersion version) { - return version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? MODERN_CHANNEL.getId() - : LEGACY_CHANNEL.getId(); + return version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? MODERN_CHANNEL.id() + : LEGACY_CHANNEL.id(); } // Note: this method will always release the buffer! diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/ConfigSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/ConfigSessionHandler.java index e2baa63ff..96a35a4f7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/ConfigSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/ConfigSessionHandler.java @@ -81,8 +81,8 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { @Override public void activated() { - resourcePackToApply = serverConn.getPlayer().getAppliedResourcePack(); - serverConn.getPlayer().clearAppliedResourcePack(); + resourcePackToApply = serverConn.player().appliedResourcePack(); + serverConn.player().clearAppliedResourcePack(); } @Override @@ -103,7 +103,7 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(TagsUpdate packet) { - serverConn.getPlayer().getConnection().write(packet); + serverConn.player().getConnection().write(packet); return true; } @@ -115,7 +115,7 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ResourcePackRequest packet) { - final MinecraftConnection playerConnection = serverConn.getPlayer().getConnection(); + final MinecraftConnection playerConnection = serverConn.player().getConnection(); ServerResourcePackSendEvent event = new ServerResourcePackSendEvent(packet.toServerPromptedPack(), this.serverConn); @@ -124,15 +124,15 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { if (playerConnection.isClosed()) { return; } - if (serverResourcePackSendEvent.getResult().isAllowed()) { - ResourcePackInfo toSend = serverResourcePackSendEvent.getProvidedResourcePack(); - if (toSend != serverResourcePackSendEvent.getReceivedResourcePack()) { + if (serverResourcePackSendEvent.result().allowed()) { + ResourcePackInfo toSend = serverResourcePackSendEvent.providedResourcePack(); + if (toSend != serverResourcePackSendEvent.receivedResourcePack()) { ((VelocityResourcePackInfo) toSend).setOriginalOrigin( ResourcePackInfo.Origin.DOWNSTREAM_SERVER); } resourcePackToApply = null; - serverConn.getPlayer().queueResourcePack(toSend); + serverConn.player().queueResourcePack(toSend); } else if (serverConn.getConnection() != null) { serverConn.getConnection().write(new ResourcePackResponse(packet.getHash(), PlayerResourcePackStatusEvent.Status.DECLINED)); @@ -152,7 +152,7 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(FinishedUpdate packet) { MinecraftConnection smc = serverConn.ensureConnected(); - ConnectedPlayer player = serverConn.getPlayer(); + ConnectedPlayer player = serverConn.player(); ClientConfigSessionHandler configHandler = (ClientConfigSessionHandler) player.getConnection().getActiveSessionHandler(); @@ -165,12 +165,12 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { player.sendPlayerListHeaderAndFooter( player.getPlayerListHeader(), player.getPlayerListFooter()); // The client cleared the tab list. TODO: Restore changes done via TabList API - player.getTabList().clearAllSilent(); + player.tabList().clearAllSilent(); } else { smc.setActiveSessionHandler(StateRegistry.PLAY, new TransitionSessionHandler(server, serverConn, resultFuture)); } - if (player.getAppliedResourcePack() == null && resourcePackToApply != null) { + if (player.appliedResourcePack() == null && resourcePackToApply != null) { player.queueResourcePack(resourcePackToApply); } smc.setAutoReading(true); @@ -181,25 +181,25 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(Disconnect packet) { serverConn.disconnect(); - resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); + resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.server())); return true; } @Override public boolean handle(PluginMessage packet) { if (PluginMessageUtil.isMcBrand(packet)) { - serverConn.getPlayer().getConnection().write( + serverConn.player().getConnection().write( PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion(), - serverConn.getPlayer().getProtocolVersion())); + serverConn.player().protocolVersion())); } else { - serverConn.getPlayer().getConnection().write(packet.retain()); + serverConn.player().getConnection().write(packet.retain()); } return true; } @Override public boolean handle(RegistrySync packet) { - serverConn.getPlayer().getConnection().write(packet.retain()); + serverConn.player().getConnection().write(packet.retain()); return true; } @@ -211,13 +211,13 @@ public class ConfigSessionHandler implements MinecraftSessionHandler { @Override public void handleGeneric(MinecraftPacket packet) { - serverConn.getPlayer().getConnection().write(packet); + serverConn.player().getConnection().write(packet); } private void switchFailure(Throwable cause) { - logger.error("Unable to switch to new server {} for {}", serverConn.getServerInfo().getName(), - serverConn.getPlayer().getUsername(), cause); - serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); + logger.error("Unable to switch to new server {} for {}", serverConn.serverInfo().name(), + serverConn.player().username(), cause); + serverConn.player().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); resultFuture.completeExceptionally(cause); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index c3418baf9..e22ba1080 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -94,7 +94,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { requestedForwardingVersion = packet.content().readByte(); } ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(), - serverConn.getPlayerRemoteAddressAsString(), serverConn.getPlayer(), + serverConn.getPlayerRemoteAddressAsString(), serverConn.player(), requestedForwardingVersion); LoginPluginResponse response = new LoginPluginResponse(packet.getId(), true, forwardingData); @@ -113,9 +113,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler { this.server.getEventManager().fire(new ServerLoginPluginMessageEvent(serverConn, identifier, contents, packet.getId())) .thenAcceptAsync(event -> { - if (event.getResult().isAllowed()) { + if (event.result().allowed()) { mc.write(new LoginPluginResponse(packet.getId(), true, Unpooled - .wrappedBuffer(event.getResult().getResponse()))); + .wrappedBuffer(event.result().response()))); } else { mc.write(new LoginPluginResponse(packet.getId(), false, Unpooled.EMPTY_BUFFER)); } @@ -126,7 +126,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(Disconnect packet) { - resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); + resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.server())); serverConn.disconnect(); return true; } @@ -142,7 +142,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) { resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE, - serverConn.getServer())); + serverConn.server())); serverConn.disconnect(); return true; } @@ -159,7 +159,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { smc.write(new LoginAcknowledged()); smc.setActiveSessionHandler(StateRegistry.CONFIG, new ConfigSessionHandler(server, serverConn, resultFuture)); - ConnectedPlayer player = serverConn.getPlayer(); + ConnectedPlayer player = serverConn.player(); if (player.getClientSettingsPacket() != null) { smc.write(player.getClientSettingsPacket()); } @@ -200,14 +200,14 @@ public class LoginSessionHandler implements MinecraftSessionHandler { // Ensure we are in range requested = Math.min(requested, VelocityConstants.MODERN_FORWARDING_MAX_VERSION); if (requested > VelocityConstants.MODERN_FORWARDING_DEFAULT) { - if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { + if (player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { return requested >= VelocityConstants.MODERN_LAZY_SESSION ? VelocityConstants.MODERN_LAZY_SESSION : VelocityConstants.MODERN_FORWARDING_DEFAULT; } - if (player.getIdentifiedKey() != null) { + if (player.identifiedKey() != null) { // No enhanced switch on java 11 - switch (player.getIdentifiedKey().getKeyRevision()) { + switch (player.identifiedKey().revision()) { case GENERIC_V1: return VelocityConstants.MODERN_FORWARDING_WITH_KEY; // Since V2 is not backwards compatible we have to throw the key if v2 and requested is v1 @@ -233,15 +233,15 @@ public class LoginSessionHandler implements MinecraftSessionHandler { ProtocolUtils.writeVarInt(forwarded, actualVersion); ProtocolUtils.writeString(forwarded, address); - ProtocolUtils.writeUuid(forwarded, player.getGameProfile().getId()); - ProtocolUtils.writeString(forwarded, player.getGameProfile().getName()); - ProtocolUtils.writeProperties(forwarded, player.getGameProfile().getProperties()); + ProtocolUtils.writeUuid(forwarded, player.profile().uuid()); + ProtocolUtils.writeString(forwarded, player.profile().name()); + ProtocolUtils.writeProperties(forwarded, player.profile().properties()); // This serves as additional redundancy. The key normally is stored in the // login start to the server, but some setups require this. if (actualVersion >= VelocityConstants.MODERN_FORWARDING_WITH_KEY && actualVersion < VelocityConstants.MODERN_LAZY_SESSION) { - IdentifiedKey key = player.getIdentifiedKey(); + IdentifiedKey key = player.identifiedKey(); assert key != null; ProtocolUtils.writePlayerKey(forwarded, key); @@ -249,9 +249,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler { // assigned UUID. Doing that breaks the signatures anyway but the server // should be able to verify the key independently. if (actualVersion >= VelocityConstants.MODERN_FORWARDING_WITH_KEY_V2) { - if (key.getSignatureHolder() != null) { + if (key.signatureHolder() != null) { forwarded.writeBoolean(true); - ProtocolUtils.writeUuid(forwarded, key.getSignatureHolder()); + ProtocolUtils.writeUuid(forwarded, key.signatureHolder()); } else { // Should only not be provided if the player was connected // as offline-mode and the signer UUID was not backfilled diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 9b2d79cb7..4239572a5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -69,7 +69,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { this.serverConn = serverConn; this.resultFuture = resultFuture; this.bungeecordMessageResponder = new BungeeCordMessageResponder(server, - serverConn.getPlayer()); + serverConn.player()); } @Override @@ -91,10 +91,10 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(JoinGame packet) { MinecraftConnection smc = serverConn.ensureConnected(); - RegisteredServer previousServer = serverConn.getPreviousServer().orElse(null); - VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); + RegisteredServer previousServer = serverConn.previousServer().orElse(null); + VelocityServerConnection existingConnection = serverConn.player().getConnectedServer(); - final ConnectedPlayer player = serverConn.getPlayer(); + final ConnectedPlayer player = serverConn.player(); if (existingConnection != null) { // Shut down the existing server connection. @@ -111,7 +111,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { // The goods are in hand! We got JoinGame. Let's transition completely to the new state. smc.setAutoReading(false); server.getEventManager() - .fire(new ServerConnectedEvent(player, serverConn.getServer(), previousServer)) + .fire(new ServerConnectedEvent(player, serverConn.server(), previousServer)) .thenRunAsync(() -> { // Make sure we can still transition (player might have disconnected here). if (!serverConn.isActive()) { @@ -142,7 +142,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { smc.setAutoReading(true); // Now set the connected server. - serverConn.getPlayer().setConnectedServer(serverConn); + serverConn.player().setConnectedServer(serverConn); // Send client settings. In 1.20.2+ this is done in the config state. if (smc.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0 @@ -153,11 +153,11 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { // We're done! :) server.getEventManager().fireAndForget(new ServerPostConnectEvent(player, previousServer)); - resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer())); + resultFuture.complete(ConnectionRequestResults.successful(serverConn.server())); }, smc.eventLoop()).exceptionally(exc -> { logger.error("Unable to switch to new server {} for {}", - serverConn.getServerInfo().getName(), - player.getUsername(), exc); + serverConn.serverInfo().name(), + player.username(), exc); player.disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); resultFuture.completeExceptionally(exc); return null; @@ -176,9 +176,9 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { if (connection.getType() == ConnectionTypes.LEGACY_FORGE && !serverConn.getPhase().consideredComplete()) { resultFuture.complete(ConnectionRequestResults.forUnsafeDisconnect(packet, - serverConn.getServer())); + serverConn.server())); } else { - resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); + resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.server())); } return true; @@ -191,23 +191,23 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { } // We always need to handle plugin messages, for Forge compatibility. - if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) { + if (serverConn.getPhase().handle(serverConn, serverConn.player(), packet)) { // Handled, but check the server connection phase. if (serverConn.getPhase() == HELLO) { - VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); + VelocityServerConnection existingConnection = serverConn.player().getConnectedServer(); if (existingConnection != null && existingConnection.getPhase() != IN_TRANSITION) { // Indicate that this connection is "in transition" existingConnection.setConnectionPhase(IN_TRANSITION); // Tell the player that we're leaving and we just aren't coming back. existingConnection.getPhase().onDepartForNewServer(existingConnection, - serverConn.getPlayer()); + serverConn.player()); } } return true; } - serverConn.getPlayer().getConnection().write(packet.retain()); + serverConn.player().getConnection().write(packet.retain()); return true; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 2dec36127..465367058 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -102,7 +102,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, CompletableFuture result = new CompletableFuture<>(); // Note: we use the event loop for the connection the player is on. This reduces context // switches. - SocketAddress destinationAddress = registeredServer.getServerInfo().getAddress(); + SocketAddress destinationAddress = registeredServer.serverInfo().address(); server.createBootstrap(proxyPlayer.getConnection().eventLoop(), destinationAddress) .handler(server.getBackendChannelInitializer()) .connect(destinationAddress) @@ -135,7 +135,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } String getPlayerRemoteAddressAsString() { - final SocketAddress address = proxyPlayer.getRemoteAddress(); + final SocketAddress address = proxyPlayer.remoteAddress(); if (!(address instanceof InetSocketAddress)) { return address.toString(); } @@ -148,9 +148,9 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } private String getHandshakeRemoteAddress() { - return proxyPlayer.getVirtualHost() + return proxyPlayer.virtualHost() .map(InetSocketAddress::getHostString) - .or(() -> Optional.of(registeredServer.getServerInfo().getAddress()) + .or(() -> Optional.of(registeredServer.serverInfo().address()) .filter(addr -> addr instanceof InetSocketAddress) .map(addr -> ((InetSocketAddress) addr).getHostString())) .orElse(""); @@ -160,7 +160,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, // BungeeCord IP forwarding is simply a special injection after the "address" in the handshake, // separated by \0 (the null byte). In order, you send the original host, the player's IP, their // UUID (undashed), and if you are in online-mode, their login properties (from Mojang). - SocketAddress playerRemoteAddress = proxyPlayer.getRemoteAddress(); + SocketAddress playerRemoteAddress = proxyPlayer.remoteAddress(); if (!(playerRemoteAddress instanceof InetSocketAddress)) { return getHandshakeRemoteAddress(); } @@ -169,10 +169,10 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, .append('\0') .append(getPlayerRemoteAddressAsString()) .append('\0') - .append(proxyPlayer.getGameProfile().getUndashedId()) + .append(proxyPlayer.profile().undashedId()) .append('\0'); GENERAL_GSON - .toJson(propertiesTransform.apply(proxyPlayer.getGameProfile().getProperties()), data); + .toJson(propertiesTransform.apply(proxyPlayer.profile().properties()), data); return data.toString(); } @@ -208,7 +208,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, handshake.setServerAddress(getHandshakeRemoteAddress()); } - SocketAddress destinationAddr = registeredServer.getServerInfo().getAddress(); + SocketAddress destinationAddr = registeredServer.serverInfo().address(); if (destinationAddr instanceof InetSocketAddress) { handshake.setPort(((InetSocketAddress) destinationAddr).getPort()); } @@ -216,11 +216,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, mc.setProtocolVersion(protocolVersion); mc.setActiveSessionHandler(StateRegistry.LOGIN); - if (proxyPlayer.getIdentifiedKey() == null - && proxyPlayer.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { - mc.delayedWrite(new ServerLogin(proxyPlayer.getUsername(), proxyPlayer.getUniqueId())); + if (proxyPlayer.identifiedKey() == null + && proxyPlayer.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { + mc.delayedWrite(new ServerLogin(proxyPlayer.username(), proxyPlayer.uuid())); } else { - mc.delayedWrite(new ServerLogin(proxyPlayer.getUsername(), proxyPlayer.getIdentifiedKey())); + mc.delayedWrite(new ServerLogin(proxyPlayer.username(), proxyPlayer.identifiedKey())); } mc.flush(); } @@ -243,22 +243,22 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } @Override - public VelocityRegisteredServer getServer() { + public VelocityRegisteredServer server() { return registeredServer; } @Override - public Optional getPreviousServer() { + public Optional previousServer() { return Optional.ofNullable(this.previousServer); } @Override - public ServerInfo getServerInfo() { - return registeredServer.getServerInfo(); + public ServerInfo serverInfo() { + return registeredServer.serverInfo(); } @Override - public ConnectedPlayer getPlayer() { + public ConnectedPlayer player() { return proxyPlayer; } @@ -275,8 +275,8 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, @Override public String toString() { - return "[server connection] " + proxyPlayer.getGameProfile().getName() + " -> " - + registeredServer.getServerInfo().getName(); + return "[server connection] " + proxyPlayer.profile().name() + " -> " + + registeredServer.serverInfo().name(); } @Override @@ -297,7 +297,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, MinecraftConnection mc = ensureConnected(); - PluginMessage message = new PluginMessage(identifier.getId(), data); + PluginMessage message = new PluginMessage(identifier.id(), data); mc.write(message); return true; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java index 5351a67cb..934f7852e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/AuthSessionHandler.java @@ -52,6 +52,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A session handler that is activated to complete the login phase. @@ -93,9 +94,9 @@ public class AuthSessionHandler implements MinecraftSessionHandler { } // Initiate a regular connection and move over to it. - ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), - mcConnection, inbound.getVirtualHost().orElse(null), onlineMode, - inbound.getIdentifiedKey()); + ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.profileToUse(), + mcConnection, inbound.virtualHost().orElse(null), onlineMode, + inbound.identifiedKey()); this.connectedPlayer = player; if (!server.canRegisterConnection(player)) { player.disconnect0( @@ -117,8 +118,8 @@ public class AuthSessionHandler implements MinecraftSessionHandler { "A plugin permission provider {} provided an invalid permission function" + " for player {}. This is a bug in the plugin, not in Velocity. Falling" + " back to the default permission function.", - event.getProvider().getClass().getName(), - player.getUsername()); + event.provider().getClass().getName(), + player.username()); } else { player.setPermissionChecker(checker); } @@ -138,32 +139,32 @@ public class AuthSessionHandler implements MinecraftSessionHandler { mcConnection.setCompressionThreshold(threshold); } VelocityConfiguration configuration = server.getConfiguration(); - UUID playerUniqueId = player.getUniqueId(); + UUID playerUniqueId = player.uuid(); if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) { - playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername()); + playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.username()); } - if (player.getIdentifiedKey() != null) { - IdentifiedKey playerKey = player.getIdentifiedKey(); - if (playerKey.getSignatureHolder() == null) { + if (player.identifiedKey() != null) { + IdentifiedKey playerKey = player.identifiedKey(); + if (playerKey.signatureHolder() == null) { if (playerKey instanceof IdentifiedKeyImpl) { IdentifiedKeyImpl unlinkedKey = (IdentifiedKeyImpl) playerKey; // Failsafe - if (!unlinkedKey.internalAddHolder(player.getUniqueId())) { + if (!unlinkedKey.internalAddHolder(player.uuid())) { if (onlineMode) { inbound.disconnect( Component.translatable("multiplayer.disconnect.invalid_public_key")); return; } else { - logger.warn("Key for player " + player.getUsername() + " could not be verified!"); + logger.warn("Key for player " + player.username() + " could not be verified!"); } } } else { - logger.warn("A custom key type has been set for player " + player.getUsername()); + logger.warn("A custom key type has been set for player " + player.username()); } } else { - if (!Objects.equals(playerKey.getSignatureHolder(), playerUniqueId)) { - logger.warn("UUID for Player " + player.getUsername() + " mismatches! " + if (!Objects.equals(playerKey.signatureHolder(), playerUniqueId)) { + logger.warn("UUID for Player " + player.username() + " mismatches! " + "Chat/Commands signatures will not work correctly for this player!"); } } @@ -201,9 +202,9 @@ public class AuthSessionHandler implements MinecraftSessionHandler { return; } - Optional reason = event.getResult().getReasonComponent(); - if (reason.isPresent()) { - player.disconnect0(reason.get(), true); + @Nullable Component explanation = event.result().explanation(); + if (explanation != null) { + player.disconnect0(explanation, true); } else { if (!server.registerConnection(player)) { player.disconnect0(Component.translatable("velocity.error.already-connected-proxy"), @@ -212,13 +213,13 @@ public class AuthSessionHandler implements MinecraftSessionHandler { } ServerLoginSuccess success = new ServerLoginSuccess(); - success.setUsername(player.getUsername()); - success.setProperties(player.getGameProfileProperties()); - success.setUuid(player.getUniqueId()); + success.setUsername(player.username()); + success.setProperties(player.profileProperties()); + success.setUuid(player.uuid()); mcConnection.write(success); loginState = State.SUCCESS_SENT; - if (inbound.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { + if (inbound.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { loginState = State.ACKNOWLEDGED; mcConnection.setActiveSessionHandler(StateRegistry.PLAY, new InitialConnectSessionHandler(player, server)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 1e2c9d3ed..a0c786cfc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -116,10 +116,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { this.player = player; this.server = server; - if (this.player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { + if (this.player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { this.chatHandler = new SessionChatHandler(this.player, this.server); this.commandHandler = new SessionCommandHandler(this.player, this.server); - } else if (this.player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { + } else if (this.player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { this.chatHandler = new KeyedChatHandler(this.server, this.player); this.commandHandler = new KeyedCommandHandler(this.player, this.server); } else { @@ -154,9 +154,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { public void activated() { configSwitchFuture = new CompletableFuture<>(); Collection channels = - server.getChannelRegistrar().getChannelsForProtocol(player.getProtocolVersion()); + server.getChannelRegistrar().getChannelsForProtocol(player.protocolVersion()); if (!channels.isEmpty()) { - PluginMessage register = constructChannelsPacket(player.getProtocolVersion(), channels); + PluginMessage register = constructChannelsPacket(player.protocolVersion(), channels); player.getConnection().write(register); } } @@ -320,7 +320,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.setClientBrand(brand); backendConn.write( PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion(), - player.getProtocolVersion())); + player.protocolVersion())); } else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) { return true; } else { @@ -355,7 +355,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { byte[] copy = ByteBufUtil.getBytes(packet.content()); PluginMessageEvent event = new PluginMessageEvent(player, serverConn, id, copy); server.getEventManager().fire(event).thenAcceptAsync(pme -> { - if (pme.getResult().isAllowed()) { + if (pme.result().allowed()) { PluginMessage message = new PluginMessage(packet.getChannel(), Unpooled.wrappedBuffer(copy)); if (!player.getPhase().consideredComplete() || !serverConn.getPhase() @@ -486,7 +486,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { spawned = false; serverBossBars.clear(); player.clearPlayerListHeaderAndFooterSilent(); - player.getTabList().clearAllSilent(); + player.tabList().clearAllSilent(); } player.switchToConfigState(); @@ -513,7 +513,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.getPhase().onFirstJoin(player); } else { // Clear tab list to avoid duplicate entries - player.getTabList().clearAll(); + player.tabList().clearAll(); // The player is switching from a server already, so we need to tell the client to change // entity IDs and send new dimension information. @@ -551,10 +551,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } // Clear any title from the previous server. - if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { player.getConnection().delayedWrite( GenericTitlePacket.constructTitlePacket(GenericTitlePacket.ActionType.RESET, - player.getProtocolVersion())); + player.protocolVersion())); } // Flush everything @@ -574,7 +574,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // improving compatibility with mods. final Respawn respawn = Respawn.fromJoinGame(joinGame); - if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { + if (player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { // Before Minecraft 1.16, we could not switch to the same dimension without sending an // additional respawn. On older versions of Minecraft this forces the client to perform // garbage collection which adds additional latency. @@ -616,7 +616,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { String commandLabel = command.substring(0, commandEndPosition); if (!server.getCommandManager().hasCommand(commandLabel)) { - if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { + if (player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { // Outstanding tab completes are recorded for use with 1.12 clients and below to provide // additional tab completion support. outstandingTabComplete = packet; @@ -658,7 +658,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } private boolean handleRegularTabComplete(TabCompleteRequest packet) { - if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { + if (player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { // Outstanding tab completes are recorded for use with 1.12 clients and below to provide // additional tab completion support. outstandingTabComplete = packet; @@ -690,7 +690,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { server.getCommandManager().offerBrigadierSuggestions(player, command) .thenAcceptAsync(offers -> { boolean legacy = - player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0; + player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0; try { for (Suggestion suggestion : offers.getList()) { String offer = suggestion.getText(); @@ -709,7 +709,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.getConnection().write(response); } catch (Exception e) { logger.error("Unable to provide tab list completions for {} for command '{}'", - player.getUsername(), command, + player.username(), command, e); } }, player.getConnection().eventLoop()).exceptionally((ex) -> { @@ -729,7 +729,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { server.getEventManager().fire(new TabCompleteEvent(player, request.getCommand(), offers)) .thenAcceptAsync(e -> { response.getOffers().clear(); - for (String s : e.getSuggestions()) { + for (String s : e.suggestions()) { response.getOffers().add(new Offer(s)); } player.getConnection().write(response); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java index ddcef5fff..29f7f05d3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java @@ -42,7 +42,7 @@ public class ClientSettingsWrapper implements PlayerSettings { } @Override - public Locale getLocale() { + public Locale locale() { if (locale == null) { locale = Locale.forLanguageTag(settings.getLocale().replaceAll("_", "-")); } @@ -50,12 +50,12 @@ public class ClientSettingsWrapper implements PlayerSettings { } @Override - public byte getViewDistance() { + public byte viewDistance() { return settings.getViewDistance(); } @Override - public ChatMode getChatMode() { + public ChatMode chatMode() { int chat = settings.getChatVisibility(); if (chat < 0 || chat > 2) { return ChatMode.SHOWN; @@ -69,12 +69,12 @@ public class ClientSettingsWrapper implements PlayerSettings { } @Override - public SkinParts getSkinParts() { + public SkinParts skinParts() { return parts; } @Override - public MainHand getMainHand() { + public MainHand mainHand() { return settings.getMainHand() == 1 ? MainHand.RIGHT : MainHand.LEFT; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 14888e54b..91ab9e576 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -51,7 +51,6 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; -import com.velocitypowered.proxy.connection.player.VelocityResourcePackInfo; import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.VelocityInboundConnection; @@ -162,10 +161,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, private @Nullable ResourcePackInfo pendingResourcePack; private @Nullable ResourcePackInfo appliedResourcePack; private final @NotNull Pointers pointers = Player.super.pointers().toBuilder() - .withDynamic(Identity.UUID, this::getUniqueId) - .withDynamic(Identity.NAME, this::getUsername) - .withDynamic(Identity.DISPLAY_NAME, () -> Component.text(this.getUsername())) - .withDynamic(Identity.LOCALE, this::getEffectiveLocale) + .withDynamic(Identity.UUID, this::uuid) + .withDynamic(Identity.NAME, this::username) + .withDynamic(Identity.DISPLAY_NAME, () -> Component.text(this.username())) + .withDynamic(Identity.LOCALE, this::effectiveLocale) .withDynamic(PermissionChecker.POINTER, () -> this.permissionChecker) .withStatic(FacetPointers.TYPE, Type.PLAYER) .build(); @@ -196,7 +195,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } this.playerKey = playerKey; this.chatQueue = new ChatQueue(this); - this.chatBuilderFactory = new ChatBuilderFactory(this.getProtocolVersion()); + this.chatBuilderFactory = new ChatBuilderFactory(this.protocolVersion()); } public ChatBuilderFactory getChatBuilderFactory() { @@ -213,14 +212,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public String getUsername() { - return profile.getName(); + public String username() { + return profile.name(); } @Override - public Locale getEffectiveLocale() { + public Locale effectiveLocale() { if (effectiveLocale == null && settings != null) { - return settings.getLocale(); + return settings.locale(); } return effectiveLocale; } @@ -231,12 +230,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public UUID getUniqueId() { - return profile.getId(); + public UUID uuid() { + return profile.uuid(); } @Override - public Optional getCurrentServer() { + public Optional connectedServer() { return Optional.ofNullable(connectedServer); } @@ -254,7 +253,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public GameProfile getGameProfile() { + public GameProfile profile() { return profile; } @@ -263,7 +262,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public long getPing() { + public long ping() { return this.ping; } @@ -277,7 +276,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public PlayerSettings getPlayerSettings() { + public PlayerSettings settings() { return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings; } @@ -301,7 +300,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public Optional getModInfo() { + public Optional modInfo() { return Optional.ofNullable(modInfo); } @@ -316,12 +315,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public SocketAddress getRemoteAddress() { + public SocketAddress remoteAddress() { return connection.getRemoteAddress(); } @Override - public Optional getVirtualHost() { + public Optional virtualHost() { return Optional.ofNullable(virtualHost); } @@ -335,7 +334,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public ProtocolVersion getProtocolVersion() { + public ProtocolVersion protocolVersion() { return connection.getProtocolVersion(); } @@ -347,7 +346,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, */ public Component translateMessage(Component message) { Locale locale = ClosestLocaleMatcher.INSTANCE - .lookupClosest(getEffectiveLocale() == null ? Locale.getDefault() : getEffectiveLocale()); + .lookupClosest(effectiveLocale() == null ? Locale.getDefault() : effectiveLocale()); return GlobalTranslator.render(message, locale); } @@ -377,7 +376,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, public void sendActionBar(net.kyori.adventure.text.@NonNull Component message) { Component translated = translateMessage(message); - ProtocolVersion playerVersion = getProtocolVersion(); + ProtocolVersion playerVersion = protocolVersion(); if (playerVersion.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) { // Use the title packet instead. GenericTitlePacket pkt = GenericTitlePacket.constructTitlePacket( @@ -424,18 +423,18 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, Component translatedFooter = translateMessage(footer); this.playerListHeader = translatedHeader; this.playerListFooter = translatedFooter; - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { - this.connection.write(HeaderAndFooter.create(header, footer, this.getProtocolVersion())); + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + this.connection.write(HeaderAndFooter.create(header, footer, this.protocolVersion())); } } @Override public void showTitle(net.kyori.adventure.title.@NonNull Title title) { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this - .getProtocolVersion()); + .protocolVersion()); GenericTitlePacket timesPkt = GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.SET_TIMES, this.getProtocolVersion()); + GenericTitlePacket.ActionType.SET_TIMES, this.protocolVersion()); net.kyori.adventure.title.Title.Times times = title.times(); if (times != null) { timesPkt.setFadeIn((int) DurationUtils.toTicks(times.fadeIn())); @@ -445,12 +444,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, connection.delayedWrite(timesPkt); GenericTitlePacket subtitlePkt = GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.SET_SUBTITLE, this.getProtocolVersion()); + GenericTitlePacket.ActionType.SET_SUBTITLE, this.protocolVersion()); subtitlePkt.setComponent(serializer.serialize(translateMessage(title.subtitle()))); connection.delayedWrite(subtitlePkt); GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.SET_TITLE, this.getProtocolVersion()); + GenericTitlePacket.ActionType.SET_TITLE, this.protocolVersion()); titlePkt.setComponent(serializer.serialize(translateMessage(title.title()))); connection.delayedWrite(titlePkt); @@ -467,27 +466,27 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, throw new NullPointerException("value"); } - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) < 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) < 0) { return; } GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this - .getProtocolVersion()); + .protocolVersion()); if (part == TitlePart.TITLE) { GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.SET_TITLE, this.getProtocolVersion()); + GenericTitlePacket.ActionType.SET_TITLE, this.protocolVersion()); titlePkt.setComponent(serializer.serialize(translateMessage((Component) value))); connection.write(titlePkt); } else if (part == TitlePart.SUBTITLE) { GenericTitlePacket titlePkt = GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.SET_SUBTITLE, this.getProtocolVersion()); + GenericTitlePacket.ActionType.SET_SUBTITLE, this.protocolVersion()); titlePkt.setComponent(serializer.serialize(translateMessage((Component) value))); connection.write(titlePkt); } else if (part == TitlePart.TIMES) { Times times = (Times) value; GenericTitlePacket timesPkt = GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.SET_TIMES, this.getProtocolVersion()); + GenericTitlePacket.ActionType.SET_TIMES, this.protocolVersion()); timesPkt.setFadeIn((int) DurationUtils.toTicks(times.fadeIn())); timesPkt.setStay((int) DurationUtils.toTicks(times.stay())); timesPkt.setFadeOut((int) DurationUtils.toTicks(times.fadeOut())); @@ -499,30 +498,30 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, @Override public void clearTitle() { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { connection.write(GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.HIDE, this.getProtocolVersion())); + GenericTitlePacket.ActionType.HIDE, this.protocolVersion())); } } @Override public void resetTitle() { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { connection.write(GenericTitlePacket.constructTitlePacket( - GenericTitlePacket.ActionType.RESET, this.getProtocolVersion())); + GenericTitlePacket.ActionType.RESET, this.protocolVersion())); } } @Override public void hideBossBar(@NonNull BossBar bar) { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { this.server.getBossBarManager().removeBossBar(this, bar); } } @Override public void showBossBar(@NonNull BossBar bar) { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { this.server.getBossBarManager().addBossBar(this, bar); } } @@ -538,19 +537,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public List getGameProfileProperties() { - return this.profile.getProperties(); + public List profileProperties() { + return this.profile.properties(); } @Override - public void setGameProfileProperties(List properties) { + public void setProfileProperties(List properties) { this.profile = profile.withProperties(Preconditions.checkNotNull(properties)); } @Override public void clearPlayerListHeaderAndFooter() { clearPlayerListHeaderAndFooterSilent(); - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { this.connection.write(HeaderAndFooter.reset()); } } @@ -561,7 +560,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public InternalTabList getTabList() { + public InternalTabList tabList() { return tabList; } @@ -587,7 +586,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(translated)); } - connection.closeWith(Disconnect.create(translated, this.getProtocolVersion())); + connection.closeWith(Disconnect.create(translated, this.protocolVersion())); } public @Nullable VelocityServerConnection getConnectedServer() { @@ -629,14 +628,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } Component friendlyError; - if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) { + if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) { friendlyError = Component.translatable("velocity.error.connected-server-error", - Component.text(server.getServerInfo().getName())); + Component.text(server.serverInfo().name())); } else { - logger.error("{}: unable to connect to server {}", this, server.getServerInfo().getName(), + logger.error("{}: unable to connect to server {}", this, server.serverInfo().name(), wrapped); friendlyError = Component.translatable("velocity.error.connecting-server-error", - Component.text(server.getServerInfo().getName())); + Component.text(server.serverInfo().name())); } handleConnectionException(server, null, friendlyError.color(NamedTextColor.RED), safe); } @@ -657,19 +656,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, Component disconnectReason = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason); - if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) { - logger.info("{}: kicked from server {}: {}", this, server.getServerInfo().getName(), + if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) { + logger.info("{}: kicked from server {}: {}", this, server.serverInfo().name(), plainTextReason); handleConnectionException(server, disconnectReason, Component.translatable("velocity.error.moved-to-new-server", NamedTextColor.RED, - Component.text(server.getServerInfo().getName()), + Component.text(server.serverInfo().name()), disconnectReason), safe); } else { logger.error("{}: disconnected while connecting to {}: {}", this, - server.getServerInfo().getName(), plainTextReason); + server.serverInfo().name(), plainTextReason); handleConnectionException(server, disconnectReason, Component.translatable("velocity.error.cant-connect", NamedTextColor.RED, - Component.text(server.getServerInfo().getName()), + Component.text(server.serverInfo().name()), disconnectReason), safe); } } @@ -689,18 +688,18 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, return; } - boolean kickedFromCurrent = connectedServer == null || connectedServer.getServer().equals(rs); + boolean kickedFromCurrent = connectedServer == null || connectedServer.server().equals(rs); ServerKickResult result; if (kickedFromCurrent) { Optional next = getNextServerToTry(rs); - result = - next.map(RedirectPlayer::create).orElseGet(() -> DisconnectPlayer.create(friendlyReason)); + result = next.map(RedirectPlayer::redirect) + .orElseGet(() -> DisconnectPlayer.disconnect(friendlyReason)); } else { // If we were kicked by going to another server, the connection should not be in flight - if (connectionInFlight != null && connectionInFlight.getServer().equals(rs)) { + if (connectionInFlight != null && connectionInFlight.server().equals(rs)) { resetInFlightConnection(); } - result = Notify.create(friendlyReason); + result = Notify.notify(friendlyReason); } KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason, !kickedFromCurrent, result); @@ -724,25 +723,25 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, return; } - if (event.getResult() instanceof DisconnectPlayer) { - DisconnectPlayer res = (DisconnectPlayer) event.getResult(); - disconnect(res.getReasonComponent()); - } else if (event.getResult() instanceof RedirectPlayer) { - RedirectPlayer res = (RedirectPlayer) event.getResult(); + if (event.result() instanceof DisconnectPlayer) { + DisconnectPlayer res = (DisconnectPlayer) event.result(); + disconnect(res.reason()); + } else if (event.result() instanceof RedirectPlayer) { + RedirectPlayer res = (RedirectPlayer) event.result(); createConnectionRequest(res.getServer(), previousConnection).connect() .whenCompleteAsync((status, throwable) -> { if (throwable != null) { handleConnectionException( - status != null ? status.getAttemptedConnection() : res.getServer(), throwable, + status != null ? status.attemptedConnectedTo() : res.getServer(), throwable, true); return; } - switch (status.getStatus()) { + switch (status.status()) { // Impossible/nonsensical cases case ALREADY_CONNECTED: logger.error("{}: already connected to {}", this, - status.getAttemptedConnection().getServerInfo().getName()); + status.attemptedConnectedTo().serverInfo().name()); break; case CONNECTION_IN_PROGRESS: // Fatal case @@ -751,13 +750,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, if (fallbackMsg == null) { fallbackMsg = friendlyReason; } - disconnect(status.getReasonComponent().orElse(fallbackMsg)); + disconnect(status.reason().orElse(fallbackMsg)); break; case SERVER_DISCONNECTED: - Component reason = status.getReasonComponent() + Component reason = status.reason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); handleConnectionException(res.getServer(), - Disconnect.create(reason, getProtocolVersion()), ((Impl) status).isSafe()); + Disconnect.create(reason, protocolVersion()), ((Impl) status).isSafe()); break; case SUCCESS: Component requestedMessage = res.getMessageComponent(); @@ -773,12 +772,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, break; } }, connection.eventLoop()); - } else if (event.getResult() instanceof Notify) { - Notify res = (Notify) event.getResult(); + } else if (event.result() instanceof Notify) { + Notify res = (Notify) event.result(); if (event.kickedDuringServerConnect() && previousConnection != null) { - sendMessage(Identity.nil(), res.getMessageComponent()); + sendMessage(Identity.nil(), res.reason()); } else { - disconnect(res.getMessageComponent()); + disconnect(res.reason()); } } else { // In case someone gets creative, assume we want to disconnect the player. @@ -806,7 +805,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, */ private Optional getNextServerToTry(@Nullable RegisteredServer current) { if (serversToTry == null) { - String virtualHostStr = getVirtualHost().map(InetSocketAddress::getHostString) + String virtualHostStr = virtualHost().map(InetSocketAddress::getHostString) .orElse("") .toLowerCase(Locale.ROOT); serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(virtualHostStr, @@ -824,8 +823,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, for (int i = tryIndex; i < serversToTry.size(); i++) { String toTryName = serversToTry.get(i); - if ((connectedServer != null && hasSameName(connectedServer.getServer(), toTryName)) - || (connectionInFlight != null && hasSameName(connectionInFlight.getServer(), toTryName)) + if ((connectedServer != null && hasSameName(connectedServer.server(), toTryName)) + || (connectionInFlight != null && hasSameName(connectionInFlight.server(), toTryName)) || (current != null && hasSameName(current, toTryName))) { continue; } @@ -837,7 +836,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } private static boolean hasSameName(RegisteredServer server, String name) { - return server.getServerInfo().getName().equalsIgnoreCase(name); + return server.serverInfo().name().equalsIgnoreCase(name); } /** @@ -880,12 +879,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, connectedServer.disconnect(); } - Optional connectedPlayer = server.getPlayer(this.getUniqueId()); + Optional connectedPlayer = server.getPlayer(this.uuid()); server.unregisterConnection(this); DisconnectEvent.LoginStatus status; if (connectedPlayer.isPresent()) { - if (!connectedPlayer.get().getCurrentServer().isPresent()) { + if (!connectedPlayer.get().connectedServer().isPresent()) { status = LoginStatus.PRE_SERVER_JOIN; } else { status = connectedPlayer.get() == this ? LoginStatus.SUCCESSFUL_LOGIN @@ -915,12 +914,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, boolean isPlayerAddressLoggingEnabled = server.getConfiguration() .isPlayerAddressLoggingEnabled(); String playerIp = - isPlayerAddressLoggingEnabled ? getRemoteAddress().toString() : ""; - return "[connected player] " + profile.getName() + " (" + playerIp + ")"; + isPlayerAddressLoggingEnabled ? remoteAddress().toString() : ""; + return "[connected player] " + profile.name() + " (" + playerIp + ")"; } @Override - public PermissionChecker getPermissionChecker() { + public PermissionChecker permissionChecker() { return this.permissionChecker; } @@ -928,7 +927,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { Preconditions.checkNotNull(identifier, "identifier"); Preconditions.checkNotNull(data, "data"); - PluginMessage message = new PluginMessage(identifier.getId(), Unpooled.wrappedBuffer(data)); + PluginMessage message = new PluginMessage(identifier.id(), Unpooled.wrappedBuffer(data)); connection.write(message); return true; } @@ -947,7 +946,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, Preconditions.checkArgument(input.length() <= LegacyChat.MAX_SERVERBOUND_MESSAGE_LENGTH, "input cannot be greater than " + LegacyChat.MAX_SERVERBOUND_MESSAGE_LENGTH + " characters in length"); - if (getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { + if (protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { this.chatQueue.hijack(getChatBuilderFactory().builder().asPlayer(this).message(input), (instant, item) -> { item.setTimestamp(instant); @@ -959,21 +958,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } } - @Override - @Deprecated - public void sendResourcePack(String url) { - sendResourcePackOffer(new VelocityResourcePackInfo.BuilderImpl(url).build()); - } - - @Override - @Deprecated - public void sendResourcePack(String url, byte[] hash) { - sendResourcePackOffer(new VelocityResourcePackInfo.BuilderImpl(url).setHash(hash).build()); - } - @Override public void sendResourcePackOffer(ResourcePackInfo packInfo) { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { Preconditions.checkNotNull(packInfo, "packInfo"); queueResourcePack(packInfo); } @@ -1000,7 +987,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, // Unless its 1.17+ and forced it will come back denied anyway while (!outstandingResourcePacks.isEmpty()) { queued = outstandingResourcePacks.peek(); - if (queued.getShouldForce() && getProtocolVersion() + if (queued.required() && protocolVersion() .compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) { break; } @@ -1014,26 +1001,26 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } ResourcePackRequest request = new ResourcePackRequest(); - request.setUrl(queued.getUrl()); - if (queued.getHash() != null) { - request.setHash(ByteBufUtil.hexDump(queued.getHash())); + request.setUrl(queued.url()); + if (queued.hash() != null) { + request.setHash(ByteBufUtil.hexDump(queued.hash())); } else { request.setHash(""); } - request.setRequired(queued.getShouldForce()); - request.setPrompt(queued.getPrompt()); + request.setRequired(queued.required()); + request.setPrompt(queued.prompt()); connection.write(request); } } @Override - public @Nullable ResourcePackInfo getAppliedResourcePack() { + public @Nullable ResourcePackInfo appliedResourcePack() { return appliedResourcePack; } @Override - public @Nullable ResourcePackInfo getPendingResourcePack() { + public @Nullable ResourcePackInfo pendingResourcePack() { return pendingResourcePack; } @@ -1055,11 +1042,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, server.getEventManager().fire(new PlayerResourcePackStatusEvent(this, status, queued)) .thenAcceptAsync(event -> { if (event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED - && event.getPackInfo() != null && event.getPackInfo().getShouldForce() - && (!event.isOverwriteKick() || event.getPlayer() - .getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) + && event.getPackInfo() != null && event.getPackInfo().required() + && (!event.isOverwriteKick() || event.player() + .protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) ) { - event.getPlayer().disconnect(Component + event.player().disconnect(Component .translatable("multiplayer.requiredTexturePrompt.disconnect")); } }); @@ -1088,7 +1075,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } return queued != null - && queued.getOriginalOrigin() != ResourcePackInfo.Origin.DOWNSTREAM_SERVER; + && queued.originalOrigin() != ResourcePackInfo.Origin.DOWNSTREAM_SERVER; } /** @@ -1147,7 +1134,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, } @Override - public @Nullable IdentifiedKey getIdentifiedKey() { + public @Nullable IdentifiedKey identifiedKey() { return playerKey; } @@ -1155,7 +1142,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, @Override public @NonNull UUID uuid() { - return ConnectedPlayer.this.getUniqueId(); + return ConnectedPlayer.this.uuid(); } } @@ -1167,11 +1154,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, ConnectionRequestBuilderImpl(RegisteredServer toConnect, @Nullable VelocityServerConnection previousConnection) { this.toConnect = Preconditions.checkNotNull(toConnect, "info"); - this.previousServer = previousConnection == null ? null : previousConnection.getServer(); + this.previousServer = previousConnection == null ? null : previousConnection.server(); } @Override - public RegisteredServer getServer() { + public RegisteredServer server() { return toConnect; } @@ -1183,7 +1170,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS); } if (connectedServer != null - && connectedServer.getServer().getServerInfo().equals(server.getServerInfo())) { + && connectedServer.server().serverInfo().equals(server.serverInfo())) { return Optional.of(ALREADY_CONNECTED); } return Optional.empty(); @@ -1202,7 +1189,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, ServerPreConnectEvent event = new ServerPreConnectEvent(ConnectedPlayer.this, toConnect, previousServer); return server.getEventManager().fire(event).thenComposeAsync(newEvent -> { - Optional newDest = newEvent.getResult().getServer(); + Optional newDest = newEvent.result().getServer(); if (!newDest.isPresent()) { return completedFuture( plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED, toConnect)); @@ -1235,7 +1222,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, return this.internalConnect().whenCompleteAsync((status, throwable) -> { if (status != null && !status.isSuccessful()) { if (!status.isSafe()) { - handleConnectionException(status.getAttemptedConnection(), throwable, false); + handleConnectionException(status.attemptedConnectedTo(), throwable, false); } } }, connection.eventLoop()).thenApply(x -> x); @@ -1246,12 +1233,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, return internalConnect().whenCompleteAsync((status, throwable) -> { if (throwable != null) { // TODO: The exception handling from this is not very good. Find a better way. - handleConnectionException(status != null ? status.getAttemptedConnection() : toConnect, + handleConnectionException(status != null ? status.attemptedConnectedTo() : toConnect, throwable, true); return; } - switch (status.getStatus()) { + switch (status.status()) { case ALREADY_CONNECTED: sendMessage(Identity.nil(), ConnectionMessages.ALREADY_CONNECTED); break; @@ -1262,9 +1249,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, // Ignored; the plugin probably already handled this. break; case SERVER_DISCONNECTED: - Component reason = status.getReasonComponent() + Component reason = status.reason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); - handleConnectionException(toConnect, Disconnect.create(reason, getProtocolVersion()), + handleConnectionException(toConnect, Disconnect.create(reason, protocolVersion()), status.isSafe()); break; default: diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index eb345f67f..5f2a7913b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -215,12 +215,12 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public InetSocketAddress getRemoteAddress() { + public InetSocketAddress remoteAddress() { return (InetSocketAddress) connection.getRemoteAddress(); } @Override - public Optional getVirtualHost() { + public Optional virtualHost() { return Optional.ofNullable(ping.getVhost()); } @@ -230,13 +230,13 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public ProtocolVersion getProtocolVersion() { + public ProtocolVersion protocolVersion() { return ProtocolVersion.LEGACY; } @Override public String toString() { - return "[legacy connection] " + this.getRemoteAddress().toString(); + return "[legacy connection] " + this.remoteAddress().toString(); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java index 22dd2e56c..c691956c5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialConnectSessionHandler.java @@ -65,11 +65,11 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler { } byte[] copy = ByteBufUtil.getBytes(packet.content()); - PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id, + PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.player(), id, copy); server.getEventManager().fire(event) .thenAcceptAsync(pme -> { - if (pme.getResult().isAllowed() && serverConn.isActive()) { + if (pme.result().allowed() && serverConn.isActive()) { PluginMessage copied = new PluginMessage(packet.getChannel(), Unpooled.wrappedBuffer(copy)); serverConn.ensureConnected().write(copied); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index 7b79a731a..7c656afee 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -54,12 +54,12 @@ public final class InitialInboundConnection implements VelocityInboundConnection } @Override - public InetSocketAddress getRemoteAddress() { + public InetSocketAddress remoteAddress() { return (InetSocketAddress) connection.getRemoteAddress(); } @Override - public Optional getVirtualHost() { + public Optional virtualHost() { return Optional.of(InetSocketAddress.createUnresolved(cleanedAddress, handshake.getPort())); } @@ -69,7 +69,7 @@ public final class InitialInboundConnection implements VelocityInboundConnection } @Override - public ProtocolVersion getProtocolVersion() { + public ProtocolVersion protocolVersion() { return connection.getProtocolVersion(); } @@ -95,7 +95,7 @@ public final class InitialInboundConnection implements VelocityInboundConnection logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(translated)); } - connection.closeWith(Disconnect.create(translated, getProtocolVersion())); + connection.closeWith(Disconnect.create(translated, protocolVersion())); } /** @@ -106,6 +106,6 @@ public final class InitialInboundConnection implements VelocityInboundConnection public void disconnectQuietly(Component reason) { Component translated = GlobalTranslator.render(reason, ClosestLocaleMatcher.INSTANCE .lookupClosest(Locale.getDefault())); - connection.closeWith(Disconnect.create(translated, getProtocolVersion())); + connection.closeWith(Disconnect.create(translated, protocolVersion())); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java index 032f01ffb..b36c98ef4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialLoginSessionHandler.java @@ -46,7 +46,6 @@ import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.MessageDigest; import java.util.Arrays; -import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadLocalRandom; import net.kyori.adventure.text.Component; @@ -56,6 +55,7 @@ import org.apache.logging.log4j.Logger; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.Response; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Handles authenticating the player to Mojang's servers. @@ -99,7 +99,7 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler { } boolean isKeyValid; - if (playerKey.getKeyRevision() == IdentifiedKey.Revision.LINKED_V2 + if (playerKey.revision() == IdentifiedKey.Revision.LINKED_V2 && playerKey instanceof IdentifiedKeyImpl) { IdentifiedKeyImpl keyImpl = (IdentifiedKeyImpl) playerKey; isKeyValid = keyImpl.internalAddHolder(packet.getHolderUuid()); @@ -127,11 +127,11 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler { return; } - PreLoginComponentResult result = event.getResult(); - Optional disconnectReason = result.getReasonComponent(); - if (disconnectReason.isPresent()) { + PreLoginComponentResult result = event.result(); + @Nullable Component disconnectReason = result.explanation(); + if (disconnectReason != null) { // The component is guaranteed to be provided if the connection was denied. - inbound.disconnect(disconnectReason.get()); + inbound.disconnect(disconnectReason); return; } @@ -185,8 +185,8 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler { try { KeyPair serverKeyPair = server.getServerKeyPair(); - if (inbound.getIdentifiedKey() != null) { - IdentifiedKey playerKey = inbound.getIdentifiedKey(); + if (inbound.identifiedKey() != null) { + IdentifiedKey playerKey = inbound.identifiedKey(); if (!playerKey.verifyDataSignature(packet.getVerifyToken(), verify, Longs.toByteArray(packet.getSalt()))) { throw new IllegalStateException("Invalid client public signature."); @@ -235,11 +235,11 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler { final GameProfile profile = GENERAL_GSON.fromJson(profileResponse.getResponseBody(), GameProfile.class); // Not so fast, now we verify the public key for 1.19.1+ - if (inbound.getIdentifiedKey() != null - && inbound.getIdentifiedKey().getKeyRevision() == IdentifiedKey.Revision.LINKED_V2 - && inbound.getIdentifiedKey() instanceof IdentifiedKeyImpl) { - IdentifiedKeyImpl key = (IdentifiedKeyImpl) inbound.getIdentifiedKey(); - if (!key.internalAddHolder(profile.getId())) { + if (inbound.identifiedKey() != null + && inbound.identifiedKey().revision() == IdentifiedKey.Revision.LINKED_V2 + && inbound.identifiedKey() instanceof IdentifiedKeyImpl) { + IdentifiedKeyImpl key = (IdentifiedKeyImpl) inbound.identifiedKey(); + if (!key.internalAddHolder(profile.uuid())) { inbound.disconnect( Component.translatable("multiplayer.disconnect.invalid_public_key")); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java index 92a3a4c3f..894ccc9d8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginInboundConnection.java @@ -61,13 +61,13 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi } @Override - public InetSocketAddress getRemoteAddress() { - return delegate.getRemoteAddress(); + public InetSocketAddress remoteAddress() { + return delegate.remoteAddress(); } @Override - public Optional getVirtualHost() { - return delegate.getVirtualHost(); + public Optional virtualHost() { + return delegate.virtualHost(); } @Override @@ -76,8 +76,8 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi } @Override - public ProtocolVersion getProtocolVersion() { - return delegate.getProtocolVersion(); + public ProtocolVersion protocolVersion() { + return delegate.protocolVersion(); } @Override @@ -92,7 +92,7 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi if (consumer == null) { throw new NullPointerException("consumer"); } - if (delegate.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { + if (delegate.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { throw new IllegalStateException("Login plugin messages can only be sent to clients running " + "Minecraft 1.13 and above"); } @@ -100,7 +100,7 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi final int id = SEQUENCE_UPDATER.incrementAndGet(this); this.outstandingResponses.put(id, consumer); - final LoginPluginMessage message = new LoginPluginMessage(id, identifier.getId(), + final LoginPluginMessage message = new LoginPluginMessage(id, identifier.id(), Unpooled.wrappedBuffer(contents)); if (!this.loginEventFired) { this.loginMessagesToSend.add(message); @@ -163,7 +163,7 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi } @Override - public IdentifiedKey getIdentifiedKey() { + public IdentifiedKey identifiedKey() { return playerKey; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java index 07a977df5..90dd38e1c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java @@ -59,7 +59,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase { if (mc != null) { mc.setType(ConnectionTypes.LEGACY_FORGE); } - connection.getPlayer().sendLegacyForgeHandshakeResetPacket(); + connection.player().sendLegacyForgeHandshakeResetPacket(); } }, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java index 3d8eb2420..6cf2e7a33 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java @@ -91,7 +91,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { PluginMessage message, MinecraftConnection backendConn) { // Read the mod list if we haven't already. - if (!player.getModInfo().isPresent()) { + if (!player.modInfo().isPresent()) { List mods = LegacyForgeUtil.readModList(message); if (!mods.isEmpty()) { player.setModInfo(new ModInfo("FML", mods)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/player/VelocityResourcePackInfo.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/player/VelocityResourcePackInfo.java index 134aee180..2e1da9752 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/player/VelocityResourcePackInfo.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/player/VelocityResourcePackInfo.java @@ -45,27 +45,27 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo { } @Override - public String getUrl() { + public String url() { return url; } @Override - public @Nullable Component getPrompt() { + public @Nullable Component prompt() { return prompt; } @Override - public boolean getShouldForce() { + public boolean required() { return shouldForce; } @Override - public @Nullable byte[] getHash() { + public @Nullable byte[] hash() { return hash == null ? null : hash.clone(); // Thanks spotbugs, very helpful. } @Override - public Origin getOrigin() { + public Origin origin() { return origin; } @@ -74,24 +74,24 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo { } @Override - public Origin getOriginalOrigin() { + public Origin originalOrigin() { return originalOrigin; } @Override public Builder asBuilder() { return new BuilderImpl(url) - .setShouldForce(shouldForce) - .setHash(hash) - .setPrompt(prompt); + .required(shouldForce) + .hash(hash) + .prompt(prompt); } @Override public Builder asBuilder(String newUrl) { return new BuilderImpl(newUrl) - .setShouldForce(shouldForce) - .setHash(hash) - .setPrompt(prompt); + .required(shouldForce) + .hash(hash) + .prompt(prompt); } /** @@ -110,13 +110,13 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo { } @Override - public BuilderImpl setShouldForce(boolean shouldForce) { + public BuilderImpl required(boolean shouldForce) { this.shouldForce = shouldForce; return this; } @Override - public BuilderImpl setHash(@Nullable byte[] hash) { + public BuilderImpl hash(@Nullable byte[] hash) { if (hash != null) { Preconditions.checkArgument(hash.length == 20, "Hash length is not 20"); this.hash = hash.clone(); // Thanks spotbugs, very helpful. @@ -127,7 +127,7 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo { } @Override - public BuilderImpl setPrompt(@Nullable Component prompt) { + public BuilderImpl prompt(@Nullable Component prompt) { this.prompt = prompt; return this; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java index 5d668f294..1dece89bd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java @@ -92,17 +92,17 @@ public class ConnectionRequestResults { } @Override - public Status getStatus() { + public Status status() { return status; } @Override - public Optional getReasonComponent() { + public Optional reason() { return Optional.ofNullable(component); } @Override - public RegisteredServer getAttemptedConnection() { + public RegisteredServer attemptedConnectedTo() { return attemptedConnection; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java index 81d9edcfd..55ca85bab 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ServerListPingHandler.java @@ -66,7 +66,7 @@ public class ServerListPingHandler { private CompletableFuture attemptPingPassthrough(VelocityInboundConnection connection, PingPassthroughMode mode, List servers, ProtocolVersion responseProtocolVersion) { - ServerPing fallback = constructLocalPing(connection.getProtocolVersion()); + ServerPing fallback = constructLocalPing(connection.protocolVersion()); List> pings = new ArrayList<>(); for (String s : servers) { Optional rs = server.getServer(s); @@ -102,7 +102,7 @@ public class ServerListPingHandler { if (response == fallback) { continue; } - Optional modInfo = response.getModinfo(); + Optional modInfo = response.modInfo(); if (modInfo.isPresent()) { return fallback.asBuilder().mods(modInfo.get()).build(); } @@ -117,16 +117,16 @@ public class ServerListPingHandler { continue; } - if (response.getDescriptionComponent() == null) { + if (response.description() == null) { continue; } return new ServerPing( - fallback.getVersion(), - fallback.getPlayers().orElse(null), - response.getDescriptionComponent(), - fallback.getFavicon().orElse(null), - response.getModinfo().orElse(null) + fallback.version(), + fallback.players().orElse(null), + response.description(), + fallback.favicon().orElse(null), + response.modInfo().orElse(null) ); } return fallback; @@ -145,14 +145,14 @@ public class ServerListPingHandler { */ public CompletableFuture getInitialPing(VelocityInboundConnection connection) { VelocityConfiguration configuration = server.getConfiguration(); - ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion()) - ? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION; + ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.protocolVersion()) + ? connection.protocolVersion() : ProtocolVersion.MAXIMUM_VERSION; PingPassthroughMode passthroughMode = configuration.getPingPassthrough(); if (passthroughMode == PingPassthroughMode.DISABLED) { return CompletableFuture.completedFuture(constructLocalPing(shownVersion)); } else { - String virtualHostStr = connection.getVirtualHost().map(InetSocketAddress::getHostString) + String virtualHostStr = connection.virtualHost().map(InetSocketAddress::getHostString) .map(str -> str.toLowerCase(Locale.ROOT)) .orElse(""); List serversToTry = server.getConfiguration().getForcedHosts().getOrDefault( @@ -172,7 +172,7 @@ public class ServerListPingHandler { public CompletableFuture getPing(VelocityInboundConnection connection) { return this.getInitialPing(connection) .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(connection, ping))) - .thenApply(ProxyPingEvent::getPing); + .thenApply(ProxyPingEvent::ping); } /** @@ -187,7 +187,7 @@ public class ServerListPingHandler { return this.getInitialPing(connection) .thenApply(ping -> { StringBuilder json = new StringBuilder(); - VelocityServer.getPingGsonInstance(connection.getProtocolVersion()) + VelocityServer.getPingGsonInstance(connection.protocolVersion()) .toJson(ping, json); return new StatusResponse(json); }); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index 66a518d31..0dc0c9cae 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -57,7 +57,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons private final VelocityServer server; private PermissionChecker permissionChecker = PermissionChecker.always(TriState.TRUE); private final @NotNull Pointers pointers = ConsoleCommandSource.super.pointers().toBuilder() - .withDynamic(PermissionChecker.POINTER, this::getPermissionChecker) + .withDynamic(PermissionChecker.POINTER, this::permissionChecker) .withDynamic(Identity.LOCALE, () -> ClosestLocaleMatcher.INSTANCE .lookupClosest(Locale.getDefault())) .withStatic(FacetPointers.TYPE, Type.CONSOLE) @@ -74,7 +74,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons } @Override - public PermissionChecker getPermissionChecker() { + public PermissionChecker permissionChecker() { return this.permissionChecker; } @@ -99,7 +99,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons "A plugin permission provider {} provided an invalid permission function" + " for the console. This is a bug in the plugin, not in Velocity. Falling" + " back to the default permission function.", - event.getProvider().getClass().getName()); + event.provider().getClass().getName()); this.permissionChecker = PermissionChecker.always(TriState.TRUE); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/crypto/IdentifiedKeyImpl.java b/proxy/src/main/java/com/velocitypowered/proxy/crypto/IdentifiedKeyImpl.java index d164d2f19..172d09e27 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/crypto/IdentifiedKeyImpl.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/crypto/IdentifiedKeyImpl.java @@ -59,32 +59,32 @@ public class IdentifiedKeyImpl implements IdentifiedKey { } @Override - public PublicKey getSignedPublicKey() { + public PublicKey publicKey() { return publicKey; } @Override - public PublicKey getSigner() { + public PublicKey signer() { return EncryptionUtils.getYggdrasilSessionKey(); } @Override - public Instant getExpiryTemporal() { + public Instant signatureExpiry() { return expiryTemporal; } @Override - public byte[] getSignature() { + public byte[] signature() { return signature.clone(); } @Override - public @Nullable UUID getSignatureHolder() { + public @Nullable UUID signatureHolder() { return holder; } @Override - public Revision getKeyRevision() { + public Revision revision() { return revision; } @@ -172,9 +172,9 @@ public class IdentifiedKeyImpl implements IdentifiedKey { IdentifiedKey that = (IdentifiedKey) o; - return Objects.equal(this.getSignedPublicKey(), that.getSignedPublicKey()) - && Objects.equal(this.getExpiryTemporal(), that.getExpiryTemporal()) - && Arrays.equals(this.getSignature(), that.getSignature()) - && Objects.equal(this.getSigner(), that.getSigner()); + return Objects.equal(this.publicKey(), that.publicKey()) + && Objects.equal(this.signatureExpiry(), that.signatureExpiry()) + && Arrays.equals(this.signature(), that.signature()) + && Objects.equal(this.signer(), that.signer()); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/crypto/SignedChatCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/crypto/SignedChatCommand.java index eb3b11667..ba776774f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/crypto/SignedChatCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/crypto/SignedChatCommand.java @@ -63,22 +63,22 @@ public class SignedChatCommand implements KeySigned { } @Override - public PublicKey getSigner() { + public PublicKey signer() { return signer; } @Override - public Instant getExpiryTemporal() { + public Instant signatureExpiry() { return expiry; } @Override - public @Nullable byte[] getSignature() { + public @Nullable byte[] signature() { return null; } @Override - public byte[] getSalt() { + public byte[] salt() { return salt; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java index a55147570..8d53ce315 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java @@ -494,7 +494,7 @@ public class VelocityEventManager implements EventManager { final E event, final HandlersCache handlersCache) { final HandlerRegistration registration = handlersCache.handlers[0]; if (registration.asyncType == AsyncType.ALWAYS) { - registration.plugin.getExecutorService().execute( + registration.plugin.executorService().execute( () -> fire(future, event, 0, true, handlersCache.handlers)); } else { fire(future, event, 0, false, handlersCache.handlers); @@ -613,7 +613,7 @@ public class VelocityEventManager implements EventManager { if (currentThread == firedOnThread && next.asyncType != AsyncType.ALWAYS) { fire(future, event, index + 1, currentlyAsync, registrations); } else { - next.plugin.getExecutorService().execute(() -> + next.plugin.executorService().execute(() -> fire(future, event, index + 1, true, registrations)); } } @@ -641,7 +641,7 @@ public class VelocityEventManager implements EventManager { continue; } } else { - registration.plugin.getExecutorService().execute(continuationTask); + registration.plugin.executorService().execute(continuationTask); } // fire will continue in another thread once the async task is // executed and the continuation is resumed @@ -658,6 +658,6 @@ public class VelocityEventManager implements EventManager { private static void logHandlerException( final HandlerRegistration registration, final Throwable t) { logger.error("Couldn't pass {} to {}", registration.eventType.getSimpleName(), - registration.plugin.getDescription().getId(), t); + registration.plugin.description().id(), t); } } \ No newline at end of file diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index b770ea5de..08ecdc1ad 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -94,7 +94,7 @@ public final class ConnectionManager { this.resolver = new SeparatePoolInetNameResolver(GlobalEventExecutor.INSTANCE); this.httpClient = asyncHttpClient(config() .setEventLoopGroup(this.workerGroup) - .setUserAgent(server.getVersion().getName() + "/" + server.getVersion().getVersion()) + .setUserAgent(server.getVersion().name() + "/" + server.getVersion().version()) .addRequestFilter(new RequestFilter() { @Override public FilterContext filter(FilterContext ctx) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/query/GameSpyQueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/query/GameSpyQueryHandler.java index 13ae699ad..0969ed27e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/query/GameSpyQueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/query/GameSpyQueryHandler.java @@ -95,7 +95,7 @@ public class GameSpyQueryHandler extends SimpleChannelInboundHandler getRealPluginInformation() { List result = new ArrayList<>(); - for (PluginContainer plugin : server.getPluginManager().getPlugins()) { - PluginDescription description = plugin.getDescription(); - result.add(QueryResponse.PluginInformation.of(description.getName() - .orElse(description.getId()), description.getVersion().orElse(null))); + for (PluginContainer plugin : server.getPluginManager().plugins()) { + PluginDescription description = plugin.description(); + result.add(QueryResponse.PluginInformation.of(description.name() + .orElse(description.id()), description.version().orElse(null))); } return result; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/ProtocolUtils.java index 878d811d0..3da14801a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/ProtocolUtils.java @@ -462,9 +462,9 @@ public enum ProtocolUtils { public static void writeProperties(ByteBuf buf, List properties) { writeVarInt(buf, properties.size()); for (GameProfile.Property property : properties) { - writeString(buf, property.getName()); - writeString(buf, property.getValue()); - String signature = property.getSignature(); + writeString(buf, property.name()); + writeString(buf, property.value()); + String signature = property.signature(); if (signature != null && !signature.isEmpty()) { buf.writeBoolean(true); writeString(buf, signature); @@ -650,9 +650,9 @@ public enum ProtocolUtils { * @param playerKey the key to write */ public static void writePlayerKey(ByteBuf buf, IdentifiedKey playerKey) { - buf.writeLong(playerKey.getExpiryTemporal().toEpochMilli()); - ProtocolUtils.writeByteArray(buf, playerKey.getSignedPublicKey().getEncoded()); - ProtocolUtils.writeByteArray(buf, playerKey.getSignature()); + buf.writeLong(playerKey.signatureExpiry().toEpochMilli()); + ProtocolUtils.writeByteArray(buf, playerKey.publicKey().getEncoded()); + ProtocolUtils.writeByteArray(buf, playerKey.signature()); } /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyDisconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyDisconnect.java index 8265ea6d9..c57934518 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyDisconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyDisconnect.java @@ -47,7 +47,7 @@ public class LegacyDisconnect { */ public static LegacyDisconnect fromServerPing(ServerPing response, LegacyMinecraftPingVersion version) { - Players players = response.getPlayers().orElse(FAKE_PLAYERS); + Players players = response.players().orElse(FAKE_PLAYERS); switch (version) { case MINECRAFT_1_3: @@ -56,7 +56,7 @@ public class LegacyDisconnect { // MOTD. return new LegacyDisconnect(String.join(LEGACY_COLOR_CODE, cleanSectionSymbol(getFirstLine(PlainTextComponentSerializer.plainText().serialize( - response.getDescriptionComponent()))), + response.description()))), Integer.toString(players.getOnline()), Integer.toString(players.getMax()))); case MINECRAFT_1_4: @@ -64,10 +64,10 @@ public class LegacyDisconnect { // Minecraft 1.4-1.6 provide support for more fields, and additionally support color codes. return new LegacyDisconnect(String.join("\0", LEGACY_COLOR_CODE + "1", - Integer.toString(response.getVersion().getProtocol()), - response.getVersion().getName(), + Integer.toString(response.version().getProtocol()), + response.version().getName(), getFirstLine(LegacyComponentSerializer.legacySection().serialize(response - .getDescriptionComponent())), + .description())), Integer.toString(players.getOnline()), Integer.toString(players.getMax()) )); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyPlayerListItem.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyPlayerListItem.java index 9934d2662..1729f6f4b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyPlayerListItem.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/LegacyPlayerListItem.java @@ -207,12 +207,12 @@ public class LegacyPlayerListItem implements MinecraftPacket { } public static Item from(TabListEntry entry) { - return new Item(entry.getProfile().getId()) - .setName(entry.getProfile().getName()) - .setProperties(entry.getProfile().getProperties()) + return new Item(entry.getProfile().uuid()) + .setName(entry.getProfile().name()) + .setProperties(entry.getProfile().properties()) .setLatency(entry.getLatency()) .setGameMode(entry.getGameMode()) - .setPlayerKey(entry.getIdentifiedKey()) + .setPlayerKey(entry.identifiedKey()) .setDisplayName(entry.getDisplayNameComponent().orElse(null)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ResourcePackRequest.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ResourcePackRequest.java index 765961589..389de9f82 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ResourcePackRequest.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ResourcePackRequest.java @@ -108,12 +108,12 @@ public class ResourcePackRequest implements MinecraftPacket { public VelocityResourcePackInfo toServerPromptedPack() { ResourcePackInfo.Builder builder = - new VelocityResourcePackInfo.BuilderImpl(Preconditions.checkNotNull(url)).setPrompt(prompt) - .setShouldForce(isRequired).setOrigin(ResourcePackInfo.Origin.DOWNSTREAM_SERVER); + new VelocityResourcePackInfo.BuilderImpl(Preconditions.checkNotNull(url)).prompt(prompt) + .required(isRequired).setOrigin(ResourcePackInfo.Origin.DOWNSTREAM_SERVER); if (hash != null && !hash.isEmpty()) { if (PLAUSIBLE_SHA1_HASH.matcher(hash).matches()) { - builder.setHash(ByteBufUtil.decodeHexDump(hash)); + builder.hash(ByteBufUtil.decodeHexDump(hash)); } } return (VelocityResourcePackInfo) builder.build(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerData.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerData.java index 6758e37e3..fafde1751 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerData.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerData.java @@ -89,12 +89,12 @@ public class ServerData implements MinecraftPacket { buf.writeBoolean(hasFavicon); if (hasFavicon) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0) { - String cutIconBase64 = favicon.getBase64Url().substring("data:image/png;base64,".length()); + String cutIconBase64 = favicon.url().substring("data:image/png;base64,".length()); byte[] iconBytes = Base64.getDecoder() .decode(cutIconBase64.getBytes(StandardCharsets.UTF_8)); ProtocolUtils.writeByteArray(buf, iconBytes); } else { - ProtocolUtils.writeString(buf, favicon.getBase64Url()); + ProtocolUtils.writeString(buf, favicon.url()); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerLogin.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerLogin.java index b43ebb22c..28188887b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerLogin.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/ServerLogin.java @@ -132,9 +132,9 @@ public class ServerLogin implements MinecraftPacket { } if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { - if (playerKey != null && playerKey.getSignatureHolder() != null) { + if (playerKey != null && playerKey.signatureHolder() != null) { buf.writeBoolean(true); - ProtocolUtils.writeUuid(buf, playerKey.getSignatureHolder()); + ProtocolUtils.writeUuid(buf, playerKey.signatureHolder()); } else if (this.holderUuid != null) { buf.writeBoolean(true); ProtocolUtils.writeUuid(buf, this.holderUuid); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/UpsertPlayerInfo.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/UpsertPlayerInfo.java index 27fe3051c..c51488a11 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/UpsertPlayerInfo.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/UpsertPlayerInfo.java @@ -148,8 +148,8 @@ public class UpsertPlayerInfo implements MinecraftPacket { ProtocolUtils.readProperties(buf) ); }, (ignored, buf, info) -> { // write - ProtocolUtils.writeString(buf, info.profile.getName()); - ProtocolUtils.writeProperties(buf, info.profile.getProperties()); + ProtocolUtils.writeString(buf, info.profile.name()); + ProtocolUtils.writeProperties(buf, info.profile.properties()); }), INITIALIZE_CHAT((version, buf, info) -> { // read if (buf.readBoolean()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/CommandHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/CommandHandler.java index 045b2ee57..2b214e93b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/CommandHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/CommandHandler.java @@ -65,7 +65,7 @@ public interface CommandHandler { return pkt; }).exceptionally(e -> { logger.info( - "Exception occurred while running command for {}", player.getUsername(), e); + "Exception occurred while running command for {}", player.username(), e); player.sendMessage( Component.translatable("velocity.command.generic-error", NamedTextColor.RED)); return null; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/RemoteChatSession.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/RemoteChatSession.java index ba55d80df..8e903536f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/RemoteChatSession.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/RemoteChatSession.java @@ -41,11 +41,11 @@ public class RemoteChatSession implements ChatSession { this.identifiedKey = identifiedKey; } - public IdentifiedKey getIdentifiedKey() { + public IdentifiedKey identifiedKey() { return identifiedKey; } - public @Nullable UUID getSessionId() { + public @Nullable UUID sessionId() { return sessionId; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedChatHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedChatHandler.java index 1d706c8b8..d410ceb6b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedChatHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedChatHandler.java @@ -52,7 +52,7 @@ public class KeyedChatHandler implements public static void invalidCancel(Logger logger, ConnectedPlayer player) { logger.fatal("A plugin tried to cancel a signed chat message." + " This is no longer possible in 1.19.1 and newer. " - + "Disconnecting player " + player.getUsername()); + + "Disconnecting player " + player.username()); player.disconnect(Component.text("A proxy plugin caused an illegal protocol state. " + "Contact your network administrator.")); } @@ -60,7 +60,7 @@ public class KeyedChatHandler implements public static void invalidChange(Logger logger, ConnectedPlayer player) { logger.fatal("A plugin tried to change a signed chat message. " + "This is no longer possible in 1.19.1 and newer. " - + "Disconnecting player " + player.getUsername()); + + "Disconnecting player " + player.username()); player.disconnect(Component.text("A proxy plugin caused an illegal protocol state. " + "Contact your network administrator.")); } @@ -73,7 +73,7 @@ public class KeyedChatHandler implements CompletableFuture future = eventManager.fire(toSend); CompletableFuture chatFuture; - IdentifiedKey playerKey = this.player.getIdentifiedKey(); + IdentifiedKey playerKey = this.player.identifiedKey(); if (playerKey != null && !packet.isUnsigned()) { // 1.19->1.19.2 signed version @@ -81,13 +81,13 @@ public class KeyedChatHandler implements } else { // 1.19->1.19.2 unsigned version chatFuture = future.thenApply(pme -> { - PlayerChatEvent.ChatResult chatResult = pme.getResult(); - if (!chatResult.isAllowed()) { + PlayerChatEvent.ChatResult chatResult = pme.result(); + if (!chatResult.allowed()) { return null; } return player.getChatBuilderFactory().builder() - .message(chatResult.getMessage().orElse(packet.getMessage())) + .message(chatResult.modifiedMessage().orElse(packet.getMessage())) .setTimestamp(packet.getExpiry()).toServer(); }); } @@ -101,26 +101,26 @@ public class KeyedChatHandler implements } private Function handleOldSignedChat(KeyedPlayerChat packet) { - IdentifiedKey playerKey = this.player.getIdentifiedKey(); + IdentifiedKey playerKey = this.player.identifiedKey(); assert playerKey != null; return pme -> { - PlayerChatEvent.ChatResult chatResult = pme.getResult(); - if (!chatResult.isAllowed()) { - if (playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { + PlayerChatEvent.ChatResult chatResult = pme.result(); + if (!chatResult.allowed()) { + if (playerKey.revision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { // Bad, very bad. invalidCancel(logger, player); } return null; } - if (chatResult.getMessage().map(str -> !str.equals(packet.getMessage())).orElse(false)) { - if (playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { + if (chatResult.modifiedMessage().map(str -> !str.equals(packet.getMessage())).orElse(false)) { + if (playerKey.revision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { // Bad, very bad. invalidChange(logger, player); } else { logger.warn("A plugin changed a signed chat message. The server may not accept it."); return player.getChatBuilderFactory().builder() - .message(chatResult.getMessage().get() /* always present at this point */) + .message(chatResult.modifiedMessage().get() /* always present at this point */) .setTimestamp(packet.getExpiry()) .toServer(); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedCommandHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedCommandHandler.java index 92aab1add..59dce11bd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedCommandHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/keyed/KeyedCommandHandler.java @@ -44,15 +44,15 @@ public class KeyedCommandHandler implements CommandHandler { @Override public void handlePlayerCommandInternal(KeyedPlayerCommand packet) { queueCommandResult(this.server, this.player, event -> { - CommandExecuteEvent.CommandResult result = event.getResult(); - IdentifiedKey playerKey = player.getIdentifiedKey(); - if (result == CommandExecuteEvent.CommandResult.denied()) { + CommandExecuteEvent.CommandResult result = event.result(); + IdentifiedKey playerKey = player.identifiedKey(); + if (result == CommandExecuteEvent.CommandResult.deny()) { if (playerKey != null) { if (!packet.isUnsigned() - && playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { + && playerKey.revision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { logger.fatal("A plugin tried to deny a command with signable component(s). " + "This is not supported. " - + "Disconnecting player " + player.getUsername() + ". Command packet: " + packet); + + "Disconnecting player " + player.username() + ". Command packet: " + packet); player.disconnect(Component.text( "A proxy plugin caused an illegal protocol state. " + "Contact your network administrator.")); @@ -72,10 +72,10 @@ public class KeyedCommandHandler implements CommandHandler { return CompletableFuture.completedFuture(packet); } else { if (!packet.isUnsigned() && playerKey != null - && playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { + && playerKey.revision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { logger.fatal("A plugin tried to change a command with signed component(s). " + "This is not supported. " - + "Disconnecting player " + player.getUsername() + ". Command packet: " + packet); + + "Disconnecting player " + player.username() + ". Command packet: " + packet); player.disconnect(Component.text( "A proxy plugin caused an illegal protocol state. " + "Contact your network administrator.")); @@ -92,10 +92,10 @@ public class KeyedCommandHandler implements CommandHandler { } if (!packet.isUnsigned() && playerKey != null - && playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { + && playerKey.revision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { logger.fatal("A plugin tried to change a command with signed component(s). " + "This is not supported. " - + "Disconnecting player " + player.getUsername() + ". Command packet: " + packet); + + "Disconnecting player " + player.username() + ". Command packet: " + packet); player.disconnect(Component.text( "A proxy plugin caused an illegal protocol state. " + "Contact your network administrator.")); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatBuilder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatBuilder.java index 89fdd17a1..e417c5b8f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatBuilder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatBuilder.java @@ -35,7 +35,7 @@ public class LegacyChatBuilder extends ChatBuilderV2 { public MinecraftPacket toClient() { // This is temporary UUID identity = sender == null ? (senderIdentity == null ? Identity.nil().uuid() - : senderIdentity.uuid()) : sender.getUniqueId(); + : senderIdentity.uuid()) : sender.uuid(); Component msg = component == null ? Component.text(message) : component; return new LegacyChat(ProtocolUtils.getJsonChatSerializer(version).serialize(msg), type.getId(), diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatHandler.java index 62fd26d60..9e2da187b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyChatHandler.java @@ -46,12 +46,15 @@ public class LegacyChatHandler implements ChatHandler { } this.server.getEventManager().fire(new PlayerChatEvent(this.player, packet.getMessage())) .whenComplete((chatEvent, throwable) -> { - if (!chatEvent.getResult().isAllowed()) { + if (!chatEvent.result().allowed()) { return; } - serverConnection.write(this.player.getChatBuilderFactory().builder() - .message(chatEvent.getResult().getMessage().orElse(packet.getMessage())).toServer()); + serverConnection.write( + this.player.getChatBuilderFactory().builder() + .message(chatEvent.result().modifiedMessage().orElse(packet.getMessage())) + .toServer() + ); }); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyCommandHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyCommandHandler.java index c45d4998e..7d8498a41 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyCommandHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/legacy/LegacyCommandHandler.java @@ -43,8 +43,8 @@ public class LegacyCommandHandler implements CommandHandler { public void handlePlayerCommandInternal(LegacyChat packet) { String command = packet.getMessage().substring(1); queueCommandResult(this.server, this.player, event -> { - CommandExecuteEvent.CommandResult result = event.getResult(); - if (result == CommandExecuteEvent.CommandResult.denied()) { + CommandExecuteEvent.CommandResult result = event.result(); + if (result == CommandExecuteEvent.CommandResult.deny()) { return CompletableFuture.completedFuture(null); } String commandToRun = result.getCommand().orElse(command); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionChatHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionChatHandler.java index 441ebdbdb..d774c604c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionChatHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionChatHandler.java @@ -54,15 +54,15 @@ public class SessionChatHandler implements ChatHandler { chatQueue.queuePacket( eventManager.fire(toSend) .thenApply(pme -> { - PlayerChatEvent.ChatResult chatResult = pme.getResult(); - if (!chatResult.isAllowed()) { + PlayerChatEvent.ChatResult chatResult = pme.result(); + if (!chatResult.allowed()) { if (packet.isSigned()) { invalidCancel(logger, player); } return null; } - if (chatResult.getMessage().map(str -> !str.equals(packet.getMessage())) + if (chatResult.modifiedMessage().map(str -> !str.equals(packet.getMessage())) .orElse(false)) { if (packet.isSigned()) { invalidChange(logger, player); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionCommandHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionCommandHandler.java index 5425e5251..99a8de242 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionCommandHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/packet/chat/session/SessionCommandHandler.java @@ -44,19 +44,19 @@ public class SessionCommandHandler implements CommandHandler { - CommandExecuteEvent.CommandResult result = event.getResult(); - if (result == CommandExecuteEvent.CommandResult.denied()) { + CommandExecuteEvent.CommandResult result = event.result(); + if (result == CommandExecuteEvent.CommandResult.deny()) { if (packet.isSigned()) { logger.fatal("A plugin tried to deny a command with signable component(s). " + "This is not supported. " - + "Disconnecting player " + player.getUsername() + ". Command packet: " + packet); + + "Disconnecting player " + player.username() + ". Command packet: " + packet); player.disconnect(Component.text( "A proxy plugin caused an illegal protocol state. " + "Contact your network administrator.")); } // We seemingly can't actually do this if signed args exist, if not, we can probs // keep stuff happy - if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { + if (player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { return CompletableFuture.completedFuture( new ChatAcknowledgement(packet.lastSeenMessages.getOffset())); } @@ -71,7 +71,7 @@ public class SessionCommandHandler implements CommandHandler= 0) { + if (player.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { return new ChatAcknowledgement(packet.lastSeenMessages.getOffset()); } return null; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/FaviconSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/FaviconSerializer.java index eebd503a8..d9bdb2ae5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/FaviconSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/FaviconSerializer.java @@ -44,6 +44,6 @@ public final class FaviconSerializer implements JsonSerializer, JsonDes @Override public JsonElement serialize(Favicon src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.getBase64Url()); + return new JsonPrimitive(src.url()); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/GameProfileSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/GameProfileSerializer.java index 9e3b3430b..962f4ea37 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/GameProfileSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/GameProfileSerializer.java @@ -55,9 +55,9 @@ public final class GameProfileSerializer implements JsonSerializer, @Override public JsonElement serialize(GameProfile src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); - obj.add("id", new JsonPrimitive(src.getUndashedId())); - obj.add("name", new JsonPrimitive(src.getName())); - obj.add("properties", context.serialize(src.getProperties(), propertyList)); + obj.add("id", new JsonPrimitive(src.undashedId())); + obj.add("name", new JsonPrimitive(src.name())); + obj.add("properties", context.serialize(src.properties(), propertyList)); return obj; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/PluginMessageUtil.java index bd9829d1c..3d448d536 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/protocol/util/PluginMessageUtil.java @@ -136,7 +136,7 @@ public final class PluginMessageUtil { checkArgument(isMcBrand(message), "message is not a brand plugin message"); String currentBrand = readBrandMessage(message.content()); - String rewrittenBrand = String.format("%s (%s)", currentBrand, version.getName()); + String rewrittenBrand = String.format("%s (%s)", currentBrand, version.name()); ByteBuf rewrittenBuf = Unpooled.buffer(); if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java index 2c6f752f7..a2ee51c83 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java @@ -69,8 +69,8 @@ public class VelocityPluginManager implements PluginManager { } private void registerPlugin(PluginContainer plugin) { - pluginsById.put(plugin.getDescription().getId(), plugin); - Optional instance = plugin.getInstance(); + pluginsById.put(plugin.description().id(), plugin); + Optional instance = plugin.instance(); instance.ifPresent(o -> pluginInstances.put(o, plugin)); } @@ -113,10 +113,10 @@ public class VelocityPluginManager implements PluginManager { pluginLoad: for (PluginDescription candidate : sortedPlugins) { // Verify dependencies - for (PluginDependency dependency : candidate.getDependencies()) { - if (!dependency.isOptional() && !loadedPluginsById.contains(dependency.getId())) { - logger.error("Can't load plugin {} due to missing dependency {}", candidate.getId(), - dependency.getId()); + for (PluginDependency dependency : candidate.dependencies()) { + if (!dependency.optional() && !loadedPluginsById.contains(dependency.id())) { + logger.error("Can't load plugin {} due to missing dependency {}", candidate.id(), + dependency.id()); continue pluginLoad; } } @@ -125,9 +125,9 @@ public class VelocityPluginManager implements PluginManager { PluginDescription realPlugin = loader.createPluginFromCandidate(candidate); VelocityPluginContainer container = new VelocityPluginContainer(realPlugin); pluginContainers.put(container, loader.createModule(container)); - loadedPluginsById.add(realPlugin.getId()); + loadedPluginsById.add(realPlugin.id()); } catch (Throwable e) { - logger.error("Can't create module for plugin {}", candidate.getId(), e); + logger.error("Can't create module for plugin {}", candidate.id(), e); } } @@ -141,7 +141,7 @@ public class VelocityPluginManager implements PluginManager { bind(CommandManager.class).toInstance(server.getCommandManager()); for (PluginContainer container : pluginContainers.keySet()) { bind(PluginContainer.class) - .annotatedWith(Names.named(container.getDescription().getId())) + .annotatedWith(Names.named(container.description().id())) .toInstance(container); } } @@ -149,17 +149,17 @@ public class VelocityPluginManager implements PluginManager { for (Map.Entry plugin : pluginContainers.entrySet()) { PluginContainer container = plugin.getKey(); - PluginDescription description = container.getDescription(); + PluginDescription description = container.description(); try { loader.createPlugin(container, plugin.getValue(), commonModule); } catch (Throwable e) { - logger.error("Can't create plugin {}", description.getId(), e); + logger.error("Can't create plugin {}", description.id(), e); continue; } - logger.info("Loaded plugin {} {} by {}", description.getId(), description.getVersion() - .orElse(""), Joiner.on(", ").join(description.getAuthors())); + logger.info("Loaded plugin {} {} by {}", description.id(), description.version() + .orElse(""), Joiner.on(", ").join(description.authors())); registerPlugin(container); } } @@ -176,13 +176,13 @@ public class VelocityPluginManager implements PluginManager { } @Override - public Optional getPlugin(String id) { + public Optional plugin(String id) { checkNotNull(id, "id"); return Optional.ofNullable(pluginsById.get(id)); } @Override - public Collection getPlugins() { + public Collection plugins() { return Collections.unmodifiableCollection(pluginsById.values()); } @@ -197,7 +197,7 @@ public class VelocityPluginManager implements PluginManager { checkNotNull(path, "path"); Optional optContainer = fromInstance(plugin); checkArgument(optContainer.isPresent(), "plugin is not loaded"); - Optional optInstance = optContainer.get().getInstance(); + Optional optInstance = optContainer.get().instance(); checkArgument(optInstance.isPresent(), "plugin has no instance"); ClassLoader pluginClassloader = optInstance.get().getClass().getClassLoader(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java index 5e757708e..b71c91978 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java @@ -38,12 +38,12 @@ public class VelocityPluginContainer implements PluginContainer { } @Override - public PluginDescription getDescription() { + public PluginDescription description() { return this.description; } @Override - public Optional getInstance() { + public Optional instance() { return Optional.ofNullable(instance); } @@ -52,11 +52,11 @@ public class VelocityPluginContainer implements PluginContainer { } @Override - public ExecutorService getExecutorService() { + public ExecutorService executorService() { if (this.service == null) { synchronized (this) { if (this.service == null) { - String name = this.description.getName().orElse(this.description.getId()); + String name = this.description.name().orElse(this.description.id()); this.service = Executors.unconfigurableExecutorService( Executors.newCachedThreadPool( new ThreadFactoryBuilder().setDaemon(true) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java index cde909efd..ad69505c1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java @@ -66,47 +66,47 @@ public class VelocityPluginDescription implements PluginDescription { this.description = Strings.emptyToNull(description); this.url = Strings.emptyToNull(url); this.authors = authors == null ? ImmutableList.of() : ImmutableList.copyOf(authors); - this.dependencies = Maps.uniqueIndex(dependencies, d -> d == null ? null : d.getId()); + this.dependencies = Maps.uniqueIndex(dependencies, d -> d == null ? null : d.id()); this.source = source; } @Override - public String getId() { + public String id() { return id; } @Override - public Optional getName() { + public Optional name() { return Optional.ofNullable(name); } @Override - public Optional getVersion() { + public Optional version() { return Optional.ofNullable(version); } @Override - public Optional getDescription() { + public Optional description() { return Optional.ofNullable(description); } @Override - public Optional getUrl() { + public Optional url() { return Optional.ofNullable(url); } @Override - public List getAuthors() { + public List authors() { return authors; } @Override - public Collection getDependencies() { + public Collection dependencies() { return dependencies.values(); } @Override - public Optional getDependency(String id) { + public Optional dependency(String id) { return Optional.ofNullable(dependencies.get(id)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java index f39c255e9..9de3f4ae0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java @@ -91,7 +91,7 @@ public class JavaPluginLoader implements PluginLoader { @Override public Module createModule(PluginContainer container) throws Exception { - PluginDescription description = container.getDescription(); + PluginDescription description = container.description(); if (!(description instanceof JavaVelocityPluginDescription)) { throw new IllegalArgumentException("Description provided isn't of the Java plugin loader"); } @@ -111,7 +111,7 @@ public class JavaPluginLoader implements PluginLoader { if (!(container instanceof VelocityPluginContainer)) { throw new IllegalArgumentException("Container provided isn't of the Java plugin loader"); } - PluginDescription description = container.getDescription(); + PluginDescription description = container.description(); if (!(description instanceof JavaVelocityPluginDescription)) { throw new IllegalArgumentException("Description provided isn't of the Java plugin loader"); } @@ -122,7 +122,7 @@ public class JavaPluginLoader implements PluginLoader { if (instance == null) { throw new IllegalStateException( - "Got nothing from injector for plugin " + description.getId()); + "Got nothing from injector for plugin " + description.id()); } ((VelocityPluginContainer) container).setInstance(instance); @@ -183,13 +183,13 @@ public class JavaPluginLoader implements PluginLoader { JavaVelocityPluginDescriptionCandidate description, Class mainClass) { return new JavaVelocityPluginDescription( - description.getId(), - description.getName().orElse(null), - description.getVersion().orElse(null), - description.getDescription().orElse(null), - description.getUrl().orElse(null), - description.getAuthors(), - description.getDependencies(), + description.id(), + description.name().orElse(null), + description.version().orElse(null), + description.description().orElse(null), + description.url().orElse(null), + description.authors(), + description.dependencies(), description.getSource().orElse(null), mainClass ); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java index a6331dd48..5344e2a33 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java @@ -49,13 +49,13 @@ class VelocityPluginModule implements Module { public void configure(Binder binder) { binder.bind(description.getMainClass()).in(Scopes.SINGLETON); - binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(description.getId())); - binder.bind(ComponentLogger.class).toInstance(ComponentLogger.logger(description.getId())); + binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(description.id())); + binder.bind(ComponentLogger.class).toInstance(ComponentLogger.logger(description.id())); binder.bind(Path.class).annotatedWith(DataDirectory.class) - .toInstance(basePluginPath.resolve(description.getId())); + .toInstance(basePluginPath.resolve(description.id())); binder.bind(PluginDescription.class).toInstance(description); binder.bind(PluginContainer.class).toInstance(pluginContainer); - binder.bind(ExecutorService.class).toProvider(pluginContainer::getExecutorService); + binder.bind(ExecutorService.class).toProvider(pluginContainer::executorService); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java index ed2395faa..fd6965bd3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java @@ -51,7 +51,7 @@ public class PluginDependencyUtils { */ public static List sortCandidates(List candidates) { List sortedCandidates = new ArrayList<>(candidates); - sortedCandidates.sort(Comparator.comparing(PluginDescription::getId)); + sortedCandidates.sort(Comparator.comparing(PluginDescription::id)); // Create a graph and populate it with plugin dependencies. Specifically, each graph has plugin // nodes, and edges that represent the dependencies that plugin relies on. Non-existent plugins @@ -61,13 +61,13 @@ public class PluginDependencyUtils { .expectedNodeCount(sortedCandidates.size()) .build(); Map candidateMap = Maps.uniqueIndex(sortedCandidates, - PluginDescription::getId); + PluginDescription::id); for (PluginDescription description : sortedCandidates) { graph.addNode(description); - for (PluginDependency dependency : description.getDependencies()) { - PluginDescription in = candidateMap.get(dependency.getId()); + for (PluginDependency dependency : description.dependencies()) { + PluginDescription in = candidateMap.get(dependency.id()); if (in != null) { graph.putEdge(description, in); @@ -102,7 +102,7 @@ public class PluginDependencyUtils { // circular dependency, thus we do not have a directed acyclic graph and therefore no // topological sort is possible.) currentDependencyScanStack.addLast(current); - final String loop = currentDependencyScanStack.stream().map(PluginDescription::getId) + final String loop = currentDependencyScanStack.stream().map(PluginDescription::id) .collect(Collectors.joining(" -> ")); throw new IllegalStateException("Circular dependency detected: " + loop); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java index 727832bd4..90e65a342 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -119,14 +119,14 @@ public class VelocityScheduler implements Scheduler { task.cancel(); } timerExecutionService.shutdown(); - final List plugins = new ArrayList<>(this.pluginManager.getPlugins()); + final List plugins = new ArrayList<>(this.pluginManager.plugins()); final Iterator pluginIterator = plugins.iterator(); while (pluginIterator.hasNext()) { final PluginContainer container = pluginIterator.next(); if (container instanceof VelocityPluginContainer) { final VelocityPluginContainer pluginContainer = (VelocityPluginContainer) container; if (pluginContainer.hasExecutorService()) { - container.getExecutorService().shutdown(); + container.executorService().shutdown(); } else { pluginIterator.remove(); } @@ -137,8 +137,8 @@ public class VelocityScheduler implements Scheduler { boolean allShutdown = true; for (final PluginContainer container : plugins) { - final String id = container.getDescription().getId(); - final ExecutorService service = (container).getExecutorService(); + final String id = container.description().id(); + final ExecutorService service = (container).executorService(); try { if (!service.awaitTermination(10, TimeUnit.SECONDS)) { @@ -204,7 +204,7 @@ public class VelocityScheduler implements Scheduler { @Override public ScheduledTask schedule() { VelocityTask task = new VelocityTask(container, runnable, consumer, delay, repeat); - tasksByPlugin.put(container.getInstance().get(), task); + tasksByPlugin.put(container.instance().get(), task); task.schedule(); return task; } @@ -242,7 +242,7 @@ public class VelocityScheduler implements Scheduler { @Override public Object plugin() { //noinspection OptionalGetWithoutIsPresent - return container.getInstance().get(); + return container.instance().get(); } @Override @@ -278,7 +278,7 @@ public class VelocityScheduler implements Scheduler { @Override public void run() { - container.getExecutorService().execute(() -> { + container.executorService().execute(() -> { currentTaskThread = Thread.currentThread(); try { if (runnable != null) { @@ -291,8 +291,8 @@ public class VelocityScheduler implements Scheduler { if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); } else { - String friendlyPluginName = container.getDescription().getName() - .orElse(container.getDescription().getId()); + String friendlyPluginName = container.description().name() + .orElse(container.description().id()); Object unit = consumer == null ? runnable : consumer; Log.logger.error("Exception in task {} by plugin {}", unit, friendlyPluginName, e); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index 2388180bb..88c0c813a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -58,7 +58,7 @@ public class PingSessionHandler implements MinecraftSessionHandler { Handshake handshake = new Handshake(); handshake.setNextStatus(StateRegistry.STATUS_ID); - SocketAddress address = server.getServerInfo().getAddress(); + SocketAddress address = server.serverInfo().address(); if (address instanceof InetSocketAddress) { InetSocketAddress socketAddr = (InetSocketAddress) address; handshake.setServerAddress(socketAddr.getHostString()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java index d3fc5431f..d2037ae9c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java @@ -76,13 +76,13 @@ public class ServerMap { */ public RegisteredServer register(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); - String lowerName = serverInfo.getName().toLowerCase(Locale.US); + String lowerName = serverInfo.name().toLowerCase(Locale.US); RegisteredServer rs = createRawRegisteredServer(serverInfo); RegisteredServer existing = servers.putIfAbsent(lowerName, rs); - if (existing != null && !existing.getServerInfo().equals(serverInfo)) { + if (existing != null && !existing.serverInfo().equals(serverInfo)) { throw new IllegalArgumentException( - "Server with name " + serverInfo.getName() + " already registered"); + "Server with name " + serverInfo.name() + " already registered"); } else if (existing == null) { return rs; } else { @@ -97,15 +97,15 @@ public class ServerMap { */ public void unregister(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); - String lowerName = serverInfo.getName().toLowerCase(Locale.US); + String lowerName = serverInfo.name().toLowerCase(Locale.US); RegisteredServer rs = servers.get(lowerName); if (rs == null) { throw new IllegalArgumentException( - "Server with name " + serverInfo.getName() + " is not registered!"); + "Server with name " + serverInfo.name() + " is not registered!"); } - Preconditions.checkArgument(rs.getServerInfo().equals(serverInfo), - "Trying to remove server %s with differing information", serverInfo.getName()); + Preconditions.checkArgument(rs.serverInfo().equals(serverInfo), + "Trying to remove server %s with differing information", serverInfo.name()); Preconditions.checkState(servers.remove(lowerName, rs), - "Server with name %s replaced whilst unregistering", serverInfo.getName()); + "Server with name %s replaced whilst unregistering", serverInfo.name()); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index 4b9d81a0e..5b1f7f79c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -63,12 +63,12 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud } @Override - public ServerInfo getServerInfo() { + public ServerInfo serverInfo() { return serverInfo; } @Override - public Collection getPlayersConnected() { + public Collection players() { return ImmutableList.copyOf(players.values()); } @@ -95,11 +95,11 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud throw new IllegalStateException("No Velocity proxy instance available"); } CompletableFuture pingFuture = new CompletableFuture<>(); - long timeoutMs = pingOptions.getTimeout() == 0 - ? server.getConfiguration().getReadTimeout() : pingOptions.getTimeout(); - server.createBootstrap(loop, serverInfo.getAddress()) + long timeoutMs = pingOptions.timeout() == 0 + ? server.getConfiguration().getReadTimeout() : pingOptions.timeout(); + server.createBootstrap(loop, serverInfo.address()) .handler(new BackendChannelInitializer(timeoutMs)) - .connect(serverInfo.getAddress()) + .connect(serverInfo.address()) .addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { Channel ch = future.channel(); @@ -107,7 +107,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud ch.pipeline().addLast(HANDLER, conn); conn.setActiveSessionHandler(StateRegistry.HANDSHAKE, new PingSessionHandler(pingFuture, VelocityRegisteredServer.this, conn, - pingOptions.getProtocolVersion())); + pingOptions.protocolVersion())); } else { pingFuture.completeExceptionally(future.cause()); } @@ -116,11 +116,11 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud } public void addPlayer(ConnectedPlayer player) { - players.put(player.getUniqueId(), player); + players.put(player.uuid(), player); } public void removePlayer(ConnectedPlayer player) { - players.remove(player.getUniqueId(), player); + players.remove(player.uuid(), player); } @Override @@ -140,7 +140,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud for (ConnectedPlayer player : players.values()) { VelocityServerConnection serverConnection = player.getConnectedServer(); if (serverConnection != null && serverConnection.getConnection() != null - && serverConnection.getServer() == this) { + && serverConnection.server() == this) { return serverConnection.sendPluginMessage(identifier, data); } } @@ -156,6 +156,6 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud @Override public @NonNull Iterable audiences() { - return this.getPlayersConnected(); + return this.players(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabList.java index 3d00a61cd..1261b96a7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabList.java @@ -77,7 +77,7 @@ public class KeyedVelocityTabList implements InternalTabList { Preconditions.checkNotNull(entry, "entry"); Preconditions.checkArgument(entry.getTabList().equals(this), "The provided entry was not created by this tab list"); - Preconditions.checkArgument(!entries.containsKey(entry.getProfile().getId()), + Preconditions.checkArgument(!entries.containsKey(entry.getProfile().uuid()), "this TabList already contains an entry with the same uuid"); Preconditions.checkArgument(entry instanceof KeyedVelocityTabListEntry, "Not a Velocity tab list entry"); @@ -86,7 +86,7 @@ public class KeyedVelocityTabList implements InternalTabList { connection.write( new LegacyPlayerListItem(LegacyPlayerListItem.ADD_PLAYER, Collections.singletonList(packetItem))); - entries.put(entry.getProfile().getId(), (KeyedVelocityTabListEntry) entry); + entries.put(entry.getProfile().uuid(), (KeyedVelocityTabListEntry) entry); } @Override @@ -140,7 +140,7 @@ public class KeyedVelocityTabList implements InternalTabList { } @Override - public Collection getEntries() { + public Collection entries() { return Collections.unmodifiableCollection(this.entries.values()); } @@ -156,7 +156,7 @@ public class KeyedVelocityTabList implements InternalTabList { int gameMode, @Nullable ChatSession chatSession, boolean listed) { return new KeyedVelocityTabListEntry(this, profile, displayName, latency, gameMode, - chatSession == null ? null : chatSession.getIdentifiedKey()); + chatSession == null ? null : chatSession.identifiedKey()); } @Override @@ -222,19 +222,19 @@ public class KeyedVelocityTabList implements InternalTabList { } void updateEntry(int action, TabListEntry entry) { - if (entries.containsKey(entry.getProfile().getId())) { + if (entries.containsKey(entry.getProfile().uuid())) { LegacyPlayerListItem.Item packetItem = LegacyPlayerListItem.Item.from(entry); IdentifiedKey selectedKey = packetItem.getPlayerKey(); - Optional existing = proxyServer.getPlayer(entry.getProfile().getId()); + Optional existing = proxyServer.getPlayer(entry.getProfile().uuid()); if (existing.isPresent()) { - selectedKey = existing.get().getIdentifiedKey(); + selectedKey = existing.get().identifiedKey(); } if (selectedKey != null - && selectedKey.getKeyRevision().getApplicableTo() + && selectedKey.revision().applicableTo() .contains(connection.getProtocolVersion()) - && Objects.equals(selectedKey.getSignatureHolder(), entry.getProfile().getId())) { + && Objects.equals(selectedKey.signatureHolder(), entry.getProfile().uuid())) { packetItem.setPlayerKey(selectedKey); } else { packetItem.setPlayerKey(null); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabListEntry.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabListEntry.java index 0c8b89383..c35aaac7e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabListEntry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/KeyedVelocityTabListEntry.java @@ -114,7 +114,7 @@ public class KeyedVelocityTabListEntry implements TabListEntry { } @Override - public IdentifiedKey getIdentifiedKey() { + public IdentifiedKey identifiedKey() { return playerKey; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index b4b10b2a8..135ef6c9e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -87,12 +87,12 @@ public class VelocityTabList implements InternalTabList { } EnumSet actions = EnumSet.noneOf(UpsertPlayerInfo.Action.class); - UpsertPlayerInfo.Entry playerInfoEntry = new UpsertPlayerInfo.Entry(entry.getProfile().getId()); + UpsertPlayerInfo.Entry playerInfoEntry = new UpsertPlayerInfo.Entry(entry.getProfile().uuid()); Preconditions.checkNotNull(entry.getProfile(), "Profile cannot be null"); - Preconditions.checkNotNull(entry.getProfile().getId(), "Profile ID cannot be null"); + Preconditions.checkNotNull(entry.getProfile().uuid(), "Profile ID cannot be null"); - TabListEntry previousEntry = this.entries.put(entry.getProfile().getId(), entry); + TabListEntry previousEntry = this.entries.put(entry.getProfile().uuid(), entry); if (previousEntry != null) { // we should merge entries here @@ -121,7 +121,7 @@ public class VelocityTabList implements InternalTabList { if (from != null) { actions.add(UpsertPlayerInfo.Action.INITIALIZE_CHAT); playerInfoEntry.setChatSession( - new RemoteChatSession(from.getSessionId(), from.getIdentifiedKey())); + new RemoteChatSession(from.sessionId(), from.identifiedKey())); } } } else { @@ -137,7 +137,7 @@ public class VelocityTabList implements InternalTabList { actions.add(UpsertPlayerInfo.Action.INITIALIZE_CHAT); ChatSession from = entry.getChatSession(); playerInfoEntry.setChatSession( - new RemoteChatSession(from.getSessionId(), from.getIdentifiedKey())); + new RemoteChatSession(from.sessionId(), from.identifiedKey())); } if (entry.getGameMode() != -1 && entry.getGameMode() != 256) { actions.add(UpsertPlayerInfo.Action.UPDATE_GAME_MODE); @@ -166,7 +166,7 @@ public class VelocityTabList implements InternalTabList { } @Override - public Collection getEntries() { + public Collection entries() { return this.entries.values().stream().map(e -> (TabListEntry) e).collect(Collectors.toList()); } @@ -199,8 +199,8 @@ public class VelocityTabList implements InternalTabList { protected UpsertPlayerInfo.Entry createRawEntry(VelocityTabListEntry entry) { Preconditions.checkNotNull(entry, "entry"); Preconditions.checkNotNull(entry.getProfile(), "Profile cannot be null"); - Preconditions.checkNotNull(entry.getProfile().getId(), "Profile ID cannot be null"); - return new UpsertPlayerInfo.Entry(entry.getProfile().getId()); + Preconditions.checkNotNull(entry.getProfile().uuid(), "Profile ID cannot be null"); + return new UpsertPlayerInfo.Entry(entry.getProfile().uuid()); } protected void emitActionRaw(UpsertPlayerInfo.Action action, UpsertPlayerInfo.Entry entry) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java index cd5e58db1..618f63caf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java @@ -34,7 +34,7 @@ public class VelocityTabListEntryLegacy extends KeyedVelocityTabListEntry { @Override public TabListEntry setDisplayName(@Nullable Component displayName) { - getTabList().removeEntry(getProfile().getId()); // We have to remove first if updating + getTabList().removeEntry(getProfile().uuid()); // We have to remove first if updating return super.setDisplayName(displayName); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java index 243ad0264..832bb7305 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java @@ -55,13 +55,13 @@ public class VelocityTabListLegacy extends KeyedVelocityTabList { @Override public void addEntry(TabListEntry entry) { super.addEntry(entry); - nameMapping.put(entry.getProfile().getName(), entry.getProfile().getId()); + nameMapping.put(entry.getProfile().name(), entry.getProfile().uuid()); } @Override public Optional removeEntry(UUID uuid) { Optional entry = super.removeEntry(uuid); - entry.map(TabListEntry::getProfile).map(GameProfile::getName).ifPresent(nameMapping::remove); + entry.map(TabListEntry::getProfile).map(GameProfile::name).ifPresent(nameMapping::remove); return entry; } @@ -115,7 +115,7 @@ public class VelocityTabListLegacy extends KeyedVelocityTabList { @Override void updateEntry(int action, TabListEntry entry) { - if (entries.containsKey(entry.getProfile().getId())) { + if (entries.containsKey(entry.getProfile().uuid())) { switch (action) { case LegacyPlayerListItem.UPDATE_LATENCY: case LegacyPlayerListItem.UPDATE_DISPLAY_NAME: // Add here because we removed beforehand diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java index 24c17e360..2ad38bfcb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java @@ -57,36 +57,36 @@ public enum InformationUtils { */ public static JsonArray collectPluginInfo(ProxyServer proxy) { List allPlugins = ImmutableList.copyOf( - proxy.getPluginManager().getPlugins()); + proxy.getPluginManager().plugins()); JsonArray plugins = new JsonArray(); for (PluginContainer plugin : allPlugins) { - PluginDescription desc = plugin.getDescription(); + PluginDescription desc = plugin.description(); JsonObject current = new JsonObject(); - current.addProperty("id", desc.getId()); - if (desc.getName().isPresent()) { - current.addProperty("name", desc.getName().get()); + current.addProperty("id", desc.id()); + if (desc.name().isPresent()) { + current.addProperty("name", desc.name().get()); } - if (desc.getVersion().isPresent()) { - current.addProperty("version", desc.getVersion().get()); + if (desc.version().isPresent()) { + current.addProperty("version", desc.version().get()); } - if (!desc.getAuthors().isEmpty()) { + if (!desc.authors().isEmpty()) { JsonArray authorsArray = new JsonArray(); - for (String author : desc.getAuthors()) { + for (String author : desc.authors()) { authorsArray.add(author); } current.add("authors", authorsArray); } - if (desc.getDescription().isPresent()) { - current.addProperty("description", desc.getDescription().get()); + if (desc.description().isPresent()) { + current.addProperty("description", desc.description().get()); } - if (desc.getUrl().isPresent()) { - current.addProperty("url", desc.getUrl().get()); + if (desc.url().isPresent()) { + current.addProperty("url", desc.url().get()); } - if (!desc.getDependencies().isEmpty()) { + if (!desc.dependencies().isEmpty()) { JsonArray dependencies = new JsonArray(); - for (PluginDependency dependency : desc.getDependencies()) { - dependencies.add(dependency.getId()); + for (PluginDependency dependency : desc.dependencies()) { + dependencies.add(dependency.id()); } current.add("dependencies", dependencies); } @@ -196,8 +196,8 @@ public enum InformationUtils { */ public static JsonObject collectServerInfo(RegisteredServer server) { JsonObject info = new JsonObject(); - info.addProperty("currentPlayers", server.getPlayersConnected().size()); - SocketAddress addr = server.getServerInfo().getAddress(); + info.addProperty("currentPlayers", server.players().size()); + SocketAddress addr = server.serverInfo().address(); if (addr instanceof InetSocketAddress) { InetSocketAddress iaddr = (InetSocketAddress) addr; if (iaddr.isUnresolved()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java index b0897c02e..ff6a97886 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java @@ -46,10 +46,10 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { for (ChannelIdentifier identifier : identifiers) { if (identifier instanceof MinecraftChannelIdentifier) { - identifierMap.put(identifier.getId(), identifier); + identifierMap.put(identifier.id(), identifier); } else { - String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.getId()); - identifierMap.put(identifier.getId(), identifier); + String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id()); + identifierMap.put(identifier.id(), identifier); identifierMap.put(rewritten, identifier); } } @@ -65,10 +65,10 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { for (ChannelIdentifier identifier : identifiers) { if (identifier instanceof MinecraftChannelIdentifier) { - identifierMap.remove(identifier.getId()); + identifierMap.remove(identifier.id()); } else { - String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.getId()); - identifierMap.remove(identifier.getId()); + String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id()); + identifierMap.remove(identifier.id()); identifierMap.remove(rewritten); } } @@ -82,7 +82,7 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { public Collection getLegacyChannelIds() { Collection ids = new HashSet<>(); for (ChannelIdentifier value : identifierMap.values()) { - ids.add(value.getId()); + ids.add(value.id()); } return ids; } @@ -96,9 +96,9 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { Collection ids = new HashSet<>(); for (ChannelIdentifier value : identifierMap.values()) { if (value instanceof MinecraftChannelIdentifier) { - ids.add(value.getId()); + ids.add(value.id()); } else { - ids.add(PluginMessageUtil.transformLegacyToModernChannel(value.getId())); + ids.add(PluginMessageUtil.transformLegacyToModernChannel(value.id())); } } return ids; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index 21364b170..3bb697c91 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -129,7 +129,7 @@ public class AdventureBossBarManager implements BossBar.Listener { } for (ConnectedPlayer player : holder.subscribers) { Component translated = player.translateMessage(newName); - BossBarPacket packet = holder.createTitleUpdate(translated, player.getProtocolVersion()); + BossBarPacket packet = holder.createTitleUpdate(translated, player.protocolVersion()); player.getConnection().write(packet); } } @@ -211,7 +211,7 @@ public class AdventureBossBarManager implements BossBar.Listener { BossBarPacket packet = new BossBarPacket(); packet.setUuid(this.id); packet.setAction(BossBarPacket.ADD); - packet.setName(ProtocolUtils.getJsonChatSerializer(player.getProtocolVersion()) + packet.setName(ProtocolUtils.getJsonChatSerializer(player.protocolVersion()) .serialize(player.translateMessage(bar.name()))); packet.setColor(COLORS_TO_PROTOCOL.get(bar.color())); packet.setOverlay(OVERLAY_TO_PROTOCOL.get(bar.overlay())); diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandGraphInjectorTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandGraphInjectorTests.java index 3eaba3232..ba4aa6b3a 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandGraphInjectorTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandGraphInjectorTests.java @@ -51,7 +51,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite { @Test void testInjectInvocableCommand() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (SimpleCommand) invocation -> fail()); manager.getInjector().inject(dest, source); @@ -64,7 +64,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite { void testFiltersImpermissibleAlias() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -91,7 +91,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("hint") .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, (SimpleCommand) invocation -> fail()); @@ -109,7 +109,7 @@ public class CommandGraphInjectorTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("hint") .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new RawCommand() { diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java index a6891f585..267f08e06 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -42,17 +42,17 @@ public class CommandManagerTests extends CommandTestSuite { @Test void testRegisterWithMeta() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, DummyCommand.INSTANCE); assertTrue(manager.hasCommand("hello")); assertRegisteredAliases("hello"); - assertEquals(meta, manager.getCommandMeta("hello")); + assertEquals(meta, manager.commandMeta("hello")); } @Test void testRegisterWithMetaContainingMultipleAliases() { - final var meta = manager.metaBuilder("foo") + final var meta = manager.buildMeta("foo") .aliases("bar") .aliases("baz", "qux") .build(); @@ -63,15 +63,15 @@ public class CommandManagerTests extends CommandTestSuite { assertTrue(manager.hasCommand("baz")); assertTrue(manager.hasCommand("qux")); assertRegisteredAliases("foo", "bar", "baz", "qux"); - assertEquals(meta, manager.getCommandMeta("foo")); - assertEquals(meta, manager.getCommandMeta("bar")); - assertEquals(meta, manager.getCommandMeta("baz")); - assertEquals(meta, manager.getCommandMeta("qux")); + assertEquals(meta, manager.commandMeta("foo")); + assertEquals(meta, manager.commandMeta("bar")); + assertEquals(meta, manager.commandMeta("baz")); + assertEquals(meta, manager.commandMeta("qux")); } @Test void testRegisterAliasesAreCaseInsensitive() { - final var meta = manager.metaBuilder("Foo") + final var meta = manager.buildMeta("Foo") .aliases("Bar") .build(); manager.register(meta, DummyCommand.INSTANCE); @@ -96,13 +96,13 @@ public class CommandManagerTests extends CommandTestSuite { void testRegisterOverridesPreviousCommand() { final var called = new AtomicBoolean(); - final var oldMeta = manager.metaBuilder("foo").build(); + final var oldMeta = manager.buildMeta("foo").build(); manager.register(oldMeta, DummyCommand.INSTANCE); // fails on execution - assertEquals(oldMeta, manager.getCommandMeta("foo")); + assertEquals(oldMeta, manager.commandMeta("foo")); - final var newMeta = manager.metaBuilder("foo").build(); + final var newMeta = manager.buildMeta("foo").build(); manager.register(newMeta, (RawCommand) invocation -> called.set(true)); - assertEquals(newMeta, manager.getCommandMeta("foo")); + assertEquals(newMeta, manager.commandMeta("foo")); manager.executeAsync(MockCommandSource.INSTANCE, "foo").join(); assertTrue(called.get()); @@ -116,7 +116,7 @@ public class CommandManagerTests extends CommandTestSuite { .build(); assertThrows(IllegalArgumentException.class, () -> { - manager.metaBuilder("hello").hint(hintNode); + manager.buildMeta("hello").hint(hintNode); }); } @@ -131,7 +131,7 @@ public class CommandManagerTests extends CommandTestSuite { .build(); assertThrows(IllegalArgumentException.class, () -> { - manager.metaBuilder("hello").hint(hintNode); + manager.buildMeta("hello").hint(hintNode); }); } @@ -156,7 +156,7 @@ public class CommandManagerTests extends CommandTestSuite { @Test void testUnregisterSecondaryAlias() { - final var meta = manager.metaBuilder("foo") + final var meta = manager.buildMeta("foo") .aliases("bar") .build(); manager.register(meta, DummyCommand.INSTANCE); @@ -164,13 +164,13 @@ public class CommandManagerTests extends CommandTestSuite { assertFalse(manager.hasCommand("bar")); assertTrue(manager.hasCommand("foo")); - assertEquals(meta, manager.getCommandMeta("foo")); + assertEquals(meta, manager.commandMeta("foo")); assertRegisteredAliases("foo"); } @Test void testUnregisterAllAliases() { - final var meta = manager.metaBuilder("foo") + final var meta = manager.buildMeta("foo") .aliases("bar") .build(); manager.register(meta, DummyCommand.INSTANCE); @@ -182,19 +182,19 @@ public class CommandManagerTests extends CommandTestSuite { @Test void testUnregisterAliasOverlap() { - final var meta1 = manager.metaBuilder("foo") + final var meta1 = manager.buildMeta("foo") .aliases("bar") .build(); manager.register(meta1, DummyCommand.INSTANCE); - final var meta2 = manager.metaBuilder("bar") + final var meta2 = manager.buildMeta("bar") .build(); manager.register(meta2, DummyCommand.INSTANCE); - assertEquals(meta1, manager.getCommandMeta("foo")); - assertEquals(meta2, manager.getCommandMeta("bar")); + assertEquals(meta1, manager.commandMeta("foo")); + assertEquals(meta2, manager.commandMeta("bar")); manager.unregister(meta1); - assertNull(manager.getCommandMeta("foo")); - assertEquals(meta2, manager.getCommandMeta("bar")); + assertNull(manager.commandMeta("foo")); + assertEquals(meta2, manager.commandMeta("bar")); } // Execution diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandTestSuite.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandTestSuite.java index f2d78e509..c2edd69f3 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandTestSuite.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandTestSuite.java @@ -72,7 +72,7 @@ abstract class CommandTestSuite { } final void assertRegisteredAliases(final String... expected) { - final Collection actual = manager.getAliases(); + final Collection actual = manager.aliases(); assertEquals(expected.length, actual.size()); final Collection asList = Arrays.asList(expected); assertTrue(asList.containsAll(actual)); diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java b/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java index b1503a5e5..683a1f63f 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java @@ -29,7 +29,7 @@ public class MockCommandSource implements CommandSource { public static final CommandSource INSTANCE = new MockCommandSource(); @Override - public PermissionChecker getPermissionChecker() { + public PermissionChecker permissionChecker() { return PermissionChecker.always(TriState.NOT_SET); } } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/RawCommandTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/RawCommandTests.java index 04ca8a98e..4838cf5d0 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/RawCommandTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/RawCommandTests.java @@ -45,7 +45,7 @@ public class RawCommandTests extends CommandTestSuite { void testExecuteAlias() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (RawCommand) invocation -> { assertEquals(source, invocation.source()); assertEquals("hello", invocation.alias()); @@ -61,7 +61,7 @@ public class RawCommandTests extends CommandTestSuite { void testExecuteIgnoresAliasCase() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (RawCommand) invocation -> { assertEquals("hello", invocation.alias()); callCount.incrementAndGet(); @@ -75,7 +75,7 @@ public class RawCommandTests extends CommandTestSuite { void testExecuteInputIsTrimmed() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (RawCommand) invocation -> { assertEquals("hello", invocation.alias()); assertEquals("", invocation.arguments()); @@ -91,7 +91,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testExecuteAfterUnregisterForwards() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (RawCommand) invocation -> fail()); manager.unregister("hello"); @@ -102,7 +102,7 @@ public class RawCommandTests extends CommandTestSuite { void testForwardsAndDoesNotExecuteImpermissibleAlias() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -127,7 +127,7 @@ public class RawCommandTests extends CommandTestSuite { void testExecutesWithArguments() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (RawCommand) invocation -> { assertEquals("hello", invocation.alias()); assertEquals("dear world", invocation.arguments()); @@ -142,7 +142,7 @@ public class RawCommandTests extends CommandTestSuite { void testHandlesAndDoesNotExecuteWithImpermissibleArgs() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("color").build(); + final var meta = manager.buildMeta("color").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -166,7 +166,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestAliasIfImpermissible() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -189,7 +189,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestAliasAfterUnregister() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -208,7 +208,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testSuggestsArgumentsAfterAlias() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -228,7 +228,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testSuggestsArgumentsAfterAliasIgnoresAliasCase() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -247,7 +247,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testSuggestsArgumentsAfterPartialArguments() { - final var meta = manager.metaBuilder("numbers").build(); + final var meta = manager.buildMeta("numbers").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -268,7 +268,7 @@ public class RawCommandTests extends CommandTestSuite { void testDoesNotSuggestFirstArgumentIfImpermissibleAlias() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -297,7 +297,7 @@ public class RawCommandTests extends CommandTestSuite { void testDoesNotSuggestArgumentsAfterPartialImpermissibleArguments() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("foo").build(); + final var meta = manager.buildMeta("foo").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -324,7 +324,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestIfFutureCompletesExceptionally() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -342,7 +342,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestIfSuggestAsyncThrows() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -361,7 +361,7 @@ public class RawCommandTests extends CommandTestSuite { @Test void testSuggestCompletesExceptionallyIfHasPermissionThrows() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -392,7 +392,7 @@ public class RawCommandTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("hint") .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new RawCommand() { @@ -415,7 +415,7 @@ public class RawCommandTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("hint") .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new RawCommand() { @@ -439,7 +439,7 @@ public class RawCommandTests extends CommandTestSuite { .argument("hint", word()) .suggests((context, builder) -> CompletableFuture.failedFuture(new RuntimeException())) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new RawCommand() { @@ -465,7 +465,7 @@ public class RawCommandTests extends CommandTestSuite { throw new RuntimeException(); }) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new RawCommand() { diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/SimpleCommandTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/SimpleCommandTests.java index 39496c118..1aea9d5ee 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/SimpleCommandTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/SimpleCommandTests.java @@ -46,7 +46,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testExecutesAlias() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (SimpleCommand) invocation -> { assertEquals(source, invocation.source()); assertEquals("hello", invocation.alias()); @@ -62,7 +62,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testExecuteIgnoresAliasCase() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (SimpleCommand) invocation -> { assertEquals("hello", invocation.alias()); callCount.incrementAndGet(); @@ -76,7 +76,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testExecuteInputIsTrimmed() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (SimpleCommand) invocation -> { assertEquals("hello", invocation.alias()); assertArrayEquals(new String[0], invocation.arguments()); @@ -92,7 +92,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testExecuteAfterUnregisterForwards() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (SimpleCommand) invocation -> fail()); manager.unregister("hello"); @@ -103,7 +103,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testForwardsAndDoesNotExecuteImpermissibleAlias() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -128,7 +128,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testExecutesWithArguments() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, (SimpleCommand) invocation -> { assertEquals("hello", invocation.alias()); assertArrayEquals(new String[]{"dear", "world"}, invocation.arguments()); @@ -143,7 +143,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testHandlesAndDoesNotExecuteWithImpermissibleArgs() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("color").build(); + final var meta = manager.buildMeta("color").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -167,7 +167,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestAliasIfImpermissible() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -190,7 +190,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestAliasAfterUnregister() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -209,7 +209,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testSuggestsArgumentsAfterAlias() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -229,7 +229,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testSuggestsArgumentsAfterAliasIgnoresAliasCase() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -248,7 +248,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testSuggestsArgumentsAfterPartialArguments() { - final var meta = manager.metaBuilder("numbers").build(); + final var meta = manager.buildMeta("numbers").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -269,7 +269,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testDoesNotSuggestFirstArgumentIfImpermissibleAlias() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -298,7 +298,7 @@ public class SimpleCommandTests extends CommandTestSuite { void testDoesNotSuggestArgumentsAfterPartialImpermissibleArguments() { final var callCount = new AtomicInteger(); - final var meta = manager.metaBuilder("foo").build(); + final var meta = manager.buildMeta("foo").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -325,7 +325,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestIfFutureCompletesExceptionally() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -343,7 +343,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testDoesNotSuggestIfSuggestAsyncThrows() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -362,7 +362,7 @@ public class SimpleCommandTests extends CommandTestSuite { @Test void testSuggestCompletesExceptionallyIfHasPermissionThrows() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new SimpleCommand() { @Override public void execute(final Invocation invocation) { @@ -393,7 +393,7 @@ public class SimpleCommandTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("hint") .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new SimpleCommand() { @@ -416,7 +416,7 @@ public class SimpleCommandTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("hint") .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new SimpleCommand() { @@ -440,7 +440,7 @@ public class SimpleCommandTests extends CommandTestSuite { .argument("hint", word()) .suggests((context, builder) -> CompletableFuture.failedFuture(new RuntimeException())) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new SimpleCommand() { @@ -466,7 +466,7 @@ public class SimpleCommandTests extends CommandTestSuite { throw new RuntimeException(); }) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, new SimpleCommand() { diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/SuggestionsProviderTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/SuggestionsProviderTests.java index 9fe863354..0823099f9 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/SuggestionsProviderTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/SuggestionsProviderTests.java @@ -38,9 +38,9 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testSuggestsAliasesForEmptyInput() { - manager.register(manager.metaBuilder("foo").build(), NoSuggestionsCommand.INSTANCE); - manager.register(manager.metaBuilder("bar").build(), NoSuggestionsCommand.INSTANCE); - manager.register(manager.metaBuilder("baz").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("foo").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("bar").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("baz").build(), NoSuggestionsCommand.INSTANCE); assertSuggestions("", "bar", "baz", "foo"); // in alphabetical order } @@ -48,9 +48,9 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void willNotSuggestAliasesIfNotAnnouncingForPlayer() { manager.setAnnounceProxyCommands(false); - manager.register(manager.metaBuilder("foo").build(), NoSuggestionsCommand.INSTANCE); - manager.register(manager.metaBuilder("bar").build(), NoSuggestionsCommand.INSTANCE); - manager.register(manager.metaBuilder("baz").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("foo").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("bar").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("baz").build(), NoSuggestionsCommand.INSTANCE); assertPlayerSuggestions(""); // for a fake player assertSuggestions("", "bar", "baz", "foo"); // for non-players @@ -58,7 +58,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testDoesNotSuggestForLeadingWhitespace() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); assertSuggestions(" "); @@ -66,8 +66,8 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testSuggestsAliasesForPartialAlias() { - manager.register(manager.metaBuilder("hello").build(), NoSuggestionsCommand.INSTANCE); - manager.register(manager.metaBuilder("hey").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("hello").build(), NoSuggestionsCommand.INSTANCE); + manager.register(manager.buildMeta("hey").build(), NoSuggestionsCommand.INSTANCE); assertSuggestions("hell", "hello"); assertSuggestions("He", "hello", "hey"); @@ -75,7 +75,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testDoesNotSuggestForFullAlias() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); assertSuggestions("hello"); @@ -84,7 +84,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testDoesNotSuggestForPartialIncorrectAlias() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); assertSuggestions("yo"); @@ -93,7 +93,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testDoesNotSuggestArgumentsForIncorrectAlias() { - final var meta = manager.metaBuilder("hello").build(); + final var meta = manager.buildMeta("hello").build(); manager.register(meta, new RawCommand() { @Override public void execute(final Invocation invocation) { @@ -115,7 +115,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testSuggestsAllAliases() { - final var meta = manager.metaBuilder("foo") + final var meta = manager.buildMeta("foo") .aliases("bar", "baz") .build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); @@ -125,7 +125,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { @Test void testSuggestsArgumentsViaAlias() { - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .aliases("hi") .build(); manager.register(meta, new RawCommand() { @@ -150,7 +150,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("hint") .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); @@ -170,7 +170,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { .suggest("three") .buildFuture()) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); @@ -184,7 +184,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { final var hint = LiteralArgumentBuilder .literal("bar") .build(); - final var meta = manager.metaBuilder("foo") + final var meta = manager.buildMeta("foo") .hint(hint) .build(); manager.register(meta, new RawCommand() { @@ -213,7 +213,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { .requires(source1 -> fail()) .suggests((context, builder) -> builder.suggest("suggestion").buildFuture()) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); @@ -228,7 +228,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { .argument("hint", word()) .suggests((context, builder) -> builder.suggest("suggestion").buildFuture()) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.setAnnounceProxyCommands(false); @@ -245,7 +245,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { .argument("hint", word()) .suggests((context, builder) -> CompletableFuture.failedFuture(new RuntimeException())) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); @@ -261,7 +261,7 @@ public class SuggestionsProviderTests extends CommandTestSuite { throw new RuntimeException(); }) .build(); - final var meta = manager.metaBuilder("hello") + final var meta = manager.buildMeta("hello") .hint(hint) .build(); manager.register(meta, NoSuggestionsCommand.INSTANCE); diff --git a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java index ca58839a6..313f4c2bf 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java @@ -37,12 +37,12 @@ public class MockPluginManager implements PluginManager { } @Override - public Optional getPlugin(final String id) { + public Optional plugin(final String id) { return Optional.empty(); } @Override - public Collection getPlugins() { + public Collection plugins() { return ImmutableList.of(); } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java index b1bc1af72..6009cbdb1 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java @@ -56,7 +56,7 @@ public class FakePluginManager implements PluginManager { } @Override - public @NonNull Optional getPlugin(@NonNull String id) { + public @NonNull Optional plugin(@NonNull String id) { switch (id) { case "a": return Optional.of(containerA); @@ -68,7 +68,7 @@ public class FakePluginManager implements PluginManager { } @Override - public @NonNull Collection getPlugins() { + public @NonNull Collection plugins() { return ImmutableList.of(containerA, containerB); } @@ -97,17 +97,17 @@ public class FakePluginManager implements PluginManager { } @Override - public @NonNull PluginDescription getDescription() { + public @NonNull PluginDescription description() { return () -> id; } @Override - public Optional getInstance() { + public Optional instance() { return Optional.of(instance); } @Override - public ExecutorService getExecutorService() { + public ExecutorService executorService() { return service; } } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java index 504df681f..75e3dfb58 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java @@ -45,9 +45,9 @@ class VelocityChannelRegistrarTest { // Two channels cover the modern channel (velocity:test) and the legacy-mapped channel // (legacy:velocitytest). Make sure they're what we expect. - assertEquals(ImmutableSet.of(MODERN.getId(), SIMPLE_LEGACY_REMAPPED), registrar + assertEquals(ImmutableSet.of(MODERN.id(), SIMPLE_LEGACY_REMAPPED), registrar .getModernChannelIds()); - assertEquals(ImmutableSet.of(SIMPLE_LEGACY.getId(), MODERN.getId()), registrar + assertEquals(ImmutableSet.of(SIMPLE_LEGACY.id(), MODERN.id()), registrar .getLegacyChannelIds()); } @@ -57,8 +57,8 @@ class VelocityChannelRegistrarTest { registrar.register(SPECIAL_REMAP_LEGACY, MODERN_SPECIAL_REMAP); // This one, just one channel for the modern case. - assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.getId()), registrar.getModernChannelIds()); - assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.getId(), SPECIAL_REMAP_LEGACY.getId()), + assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id()), registrar.getModernChannelIds()); + assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id(), SPECIAL_REMAP_LEGACY.id()), registrar.getLegacyChannelIds()); } @@ -68,7 +68,7 @@ class VelocityChannelRegistrarTest { registrar.register(MODERN, SIMPLE_LEGACY); registrar.unregister(SIMPLE_LEGACY); - assertEquals(ImmutableSet.of(MODERN.getId()), registrar.getModernChannelIds()); - assertEquals(ImmutableSet.of(MODERN.getId()), registrar.getLegacyChannelIds()); + assertEquals(ImmutableSet.of(MODERN.id()), registrar.getModernChannelIds()); + assertEquals(ImmutableSet.of(MODERN.id()), registrar.getLegacyChannelIds()); } } \ No newline at end of file