diff --git a/api/build.gradle b/api/build.gradle index afc2c8a6b..1c7d350a9 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -48,6 +48,21 @@ artifacts { archives sourcesJar } +javadoc { + options.encoding = 'UTF-8' + options.charSet = 'UTF-8' + options.links( + 'http://www.slf4j.org/apidocs/', + 'https://google.github.io/guava/releases/25.1-jre/api/docs/', + 'https://google.github.io/guice/api-docs/4.2/javadoc/', + 'https://jd.kyori.net/text/1.12-1.6.4/', + 'https://docs.oracle.com/javase/8/docs/api/' + ) + + // Disable the crazy super-strict doclint tool in Java 8 + options.addStringOption('Xdoclint:none', '-quiet') +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/api/src/main/java/com/velocitypowered/api/command/package-info.java b/api/src/main/java/com/velocitypowered/api/command/package-info.java new file mode 100644 index 000000000..1ce9d9c30 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/command/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides a simple command framework. + */ +package com.velocitypowered.api.command; \ No newline at end of file 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 43500eebc..cf7330180 100644 --- a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java @@ -19,7 +19,7 @@ public interface ResultedEvent { R getResult(); /** - * Sets the result of this event. + * Sets the result of this event. The result must be non-null. * @param result the new result */ void setResult(@NonNull R result); @@ -28,6 +28,11 @@ public interface ResultedEvent { * Represents a result for an event. */ interface Result { + /** + * Returns whether or not 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 + */ boolean isAllowed(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/package-info.java b/api/src/main/java/com/velocitypowered/api/event/connection/package-info.java new file mode 100644 index 000000000..44e41f8d5 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides events for handling incoming connections to the proxy and loigns. + */ +package com.velocitypowered.api.event.connection; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/event/package-info.java b/api/src/main/java/com/velocitypowered/api/event/package-info.java new file mode 100644 index 000000000..34819f6ba --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides core support for handling events with Velocity. Subpackages include event classes. + */ +package com.velocitypowered.api.event; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/event/permission/package-info.java b/api/src/main/java/com/velocitypowered/api/event/permission/package-info.java new file mode 100644 index 000000000..402d8db84 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/permission/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides events to handle setting up permissions for permission subjects. + */ +package com.velocitypowered.api.event.permission; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/event/player/gameprofile/GameProfileRequestEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java similarity index 91% rename from api/src/main/java/com/velocitypowered/api/event/player/gameprofile/GameProfileRequestEvent.java rename to api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java index a8df9304d..2a02d0a18 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/gameprofile/GameProfileRequestEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java @@ -1,4 +1,4 @@ -package com.velocitypowered.api.event.player.gameprofile; +package com.velocitypowered.api.event.player; import com.velocitypowered.api.proxy.InboundConnection; import org.checkerframework.checker.nullness.qual.Nullable; @@ -43,7 +43,7 @@ public class GameProfileRequestEvent { /** * Returns the game profile that will be used to initialize the connection with. Should no profile be currently * specified, the one generated by the proxy (for offline mode) or retrieved from the Mojang session servers (for - * online mode). + * online mode) will be returned instead. * @return the user's {@link GameProfile} */ public GameProfile getGameProfile() { @@ -51,7 +51,7 @@ public class GameProfileRequestEvent { } /** - * Sets the game profile to use for this connection. Using this method on an online-mode connection is invalid. + * Sets the game profile to use for this connection. It is invalid to use this method on an online-mode connection. * @param gameProfile the profile to use for the connection, {@code null} uses the original profile */ public void setGameProfile(@Nullable GameProfile gameProfile) { 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 1c7c3f416..726ceb2e7 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 @@ -2,7 +2,7 @@ package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; /** * This event is fired once the player has successfully connected to the target server and the connection to the previous diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java index a80ce70e3..2d86c06f8 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java @@ -3,7 +3,7 @@ package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/api/src/main/java/com/velocitypowered/api/event/player/package-info.java b/api/src/main/java/com/velocitypowered/api/event/player/package-info.java new file mode 100644 index 000000000..1d0513b60 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides events for handling actions performed by players. + */ +package com.velocitypowered.api.event.player; \ No newline at end of file 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 a4cdf9ef2..e40d810b9 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 @@ -2,8 +2,11 @@ package com.velocitypowered.api.event.proxy; import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.InboundConnection; -import com.velocitypowered.api.server.ServerPing; +import com.velocitypowered.api.proxy.server.ServerPing; +/** + * This event is fired when a server list ping request is sent by a remote client. + */ public class ProxyPingEvent { private final InboundConnection connection; private ServerPing ping; diff --git a/api/src/main/java/com/velocitypowered/api/event/proxy/package-info.java b/api/src/main/java/com/velocitypowered/api/event/proxy/package-info.java new file mode 100644 index 000000000..3b7aab6b7 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/proxy/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides events for handling the lifecycle of the proxy. + */ +package com.velocitypowered.api.event.proxy; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/package-info.java b/api/src/main/java/com/velocitypowered/api/package-info.java deleted file mode 100644 index 6d8698019..000000000 --- a/api/src/main/java/com/velocitypowered/api/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.velocitypowered.api; - -/** - * Welcome to the Velocity API documentation. - */ \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/permission/package-info.java b/api/src/main/java/com/velocitypowered/api/permission/package-info.java new file mode 100644 index 000000000..a68255248 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/permission/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides the basic building blocks for a custom permission system. + */ +package com.velocitypowered.api.permission; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/plugin/annotation/package-info.java b/api/src/main/java/com/velocitypowered/api/plugin/annotation/package-info.java new file mode 100644 index 000000000..81486dfed --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/plugin/annotation/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides annotations to handle injecting dependencies for plugins. + */ +package com.velocitypowered.api.plugin.annotation; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/plugin/meta/package-info.java b/api/src/main/java/com/velocitypowered/api/plugin/meta/package-info.java new file mode 100644 index 000000000..cde1887ae --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/plugin/meta/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides metadata for plugins. + */ +package com.velocitypowered.api.plugin.meta; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/plugin/package-info.java b/api/src/main/java/com/velocitypowered/api/plugin/package-info.java new file mode 100644 index 000000000..6eea17fd6 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/plugin/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides the Velocity plugin API. + */ +package com.velocitypowered.api.plugin; \ No newline at end of file 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 e4507d752..853b4c3de 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ConnectionRequestBuilder.java @@ -1,6 +1,6 @@ package com.velocitypowered.api.proxy; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import net.kyori.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; @@ -8,8 +8,8 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; /** - * Represents a connection request. A connection request is created using {@link Player#createConnectionRequest(ServerInfo)} - * and is used to allow a plugin to compose and request a connection to another Minecraft server using a fluent API. + * Provides a fluent interface to compose and send a connection request to another server behind the proxy. A connection + * request is created using {@link Player#createConnectionRequest(ServerInfo)}. */ public interface ConnectionRequestBuilder { /** @@ -50,7 +50,7 @@ public interface ConnectionRequestBuilder { Status getStatus(); /** - * Returns a reason for the failure to connect to the server. None may be provided. + * 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 getReason(); 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 18bd0b421..e3cdcce24 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/InboundConnection.java @@ -4,7 +4,7 @@ import java.net.InetSocketAddress; import java.util.Optional; /** - * Represents a connection to the proxy. There is no guarantee that the connection has been fully initialized. + * Represents an incoming connection to the proxy. */ public interface InboundConnection { /** 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 e90a34c13..dc56e527e 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -3,7 +3,7 @@ package com.velocitypowered.api.proxy; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.util.MessagePosition; import net.kyori.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; @@ -56,19 +56,20 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage ConnectionRequestBuilder createConnectionRequest(@NonNull ServerInfo info); /** - * Sets a header and footer to the player - * @param header component with header - * @param footer component with footer + * Sets the tab list header and footer for the player. + * @param header the header component + * @param footer the footer component */ void setHeaderAndFooter(Component header, Component footer); /** - * Clears a header and footer for the player + * Clears the tab list header and footer for the player. */ void clearHeaderAndFooter(); /** - * Disconnects the player with the reason + * Disconnects the player with the specified reason. Once this method is called, further calls to other {@link Player} + * methods will become undefined. * @param reason component with the reason */ void disconnect(Component reason); 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 6877c550d..a2af42b28 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -6,27 +6,27 @@ import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.plugin.PluginManager; import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.scheduler.Scheduler; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import java.util.Collection; import java.util.Optional; import java.util.UUID; /** - * Represents a Minecraft proxy server that is compatible with the Velocity API. + * Provides an interface to a Minecraft server proxy. */ public interface ProxyServer { /** - * Retrieves the player currently connected to this proxy by their Minecraft username. - * @param username the username - * @return an {@link Optional} with the player + * Retrieves the player currently connected to this proxy by their Minecraft username. The search is case-insensitive. + * @param username the username to search for + * @return an {@link Optional} with the player, which may be empty */ Optional getPlayer(String username); /** * Retrieves the player currently connected to this proxy by their Minecraft UUID. * @param uuid the UUID - * @return an {@link Optional} with the player + * @return an {@link Optional} with the player, which may be empty */ Optional getPlayer(UUID uuid); @@ -44,9 +44,9 @@ public interface ProxyServer { int getPlayerCount(); /** - * Retrieves a registered {@link ServerInfo} instance by its name. + * Retrieves a registered {@link ServerInfo} instance by its name. The search is case-insensitive. * @param name the name of the server - * @return the server + * @return the registered server, which may be empty */ Optional getServerInfo(String name); 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 5fb44a44a..5f12fb326 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ServerConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ServerConnection.java @@ -2,7 +2,7 @@ package com.velocitypowered.api.proxy; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; /** * Represents a connection to a backend server from the proxy for a client. 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 0af1eeae2..4acd5d72a 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 @@ -4,5 +4,9 @@ package com.velocitypowered.api.proxy.messages; * Represents a kind of channel identifier. */ public interface ChannelIdentifier { + /** + * Returns the textual representation of this identifier. + * @return the textual representation of the identifier + */ String getId(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/package-info.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/package-info.java new file mode 100644 index 000000000..d55279722 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides an interface to receive, handle, and send plugin messages on the proxy from clients and servers. + */ +package com.velocitypowered.api.proxy.messages; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/proxy/package-info.java b/api/src/main/java/com/velocitypowered/api/proxy/package-info.java new file mode 100644 index 000000000..3a22511ab --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides an interface to interact with the proxy at a low level. + */ +package com.velocitypowered.api.proxy; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/server/ServerInfo.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java similarity index 97% rename from api/src/main/java/com/velocitypowered/api/server/ServerInfo.java rename to api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java index ef83511f1..3dffa7111 100644 --- a/api/src/main/java/com/velocitypowered/api/server/ServerInfo.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java @@ -1,4 +1,4 @@ -package com.velocitypowered.api.server; +package com.velocitypowered.api.proxy.server; import com.google.common.base.Preconditions; import org.checkerframework.checker.nullness.qual.NonNull; diff --git a/api/src/main/java/com/velocitypowered/api/server/ServerPing.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java similarity index 97% rename from api/src/main/java/com/velocitypowered/api/server/ServerPing.java rename to api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java index f7842b412..f48fbc3a8 100644 --- a/api/src/main/java/com/velocitypowered/api/server/ServerPing.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java @@ -1,7 +1,8 @@ -package com.velocitypowered.api.server; +package com.velocitypowered.api.proxy.server; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.velocitypowered.api.util.Favicon; import net.kyori.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -65,6 +66,9 @@ public class ServerPing { return new Builder(); } + /** + * A builder for {@link ServerPing} objects. + */ public static class Builder { private Version version; private int onlinePlayers; diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/package-info.java b/api/src/main/java/com/velocitypowered/api/proxy/server/package-info.java new file mode 100644 index 000000000..7f902113a --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides utilities to handle server information. + */ +package com.velocitypowered.api.proxy.server; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java b/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java index 5565a9e79..fd652d1c6 100644 --- a/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java +++ b/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java @@ -6,17 +6,50 @@ import java.util.concurrent.TimeUnit; * Represents a scheduler to execute tasks on the proxy. */ public interface Scheduler { + /** + * Initializes a new {@link TaskBuilder} for creating a task on the proxy. + * @param plugin the plugin to request the task for + * @param runnable the task to run when scheduled + * @return the task builder + */ TaskBuilder buildTask(Object plugin, Runnable runnable); + /** + * Represents a fluent interface to schedule tasks on the proxy. + */ interface TaskBuilder { + /** + * Specifies that the task should delay its execution by the specified amount of time. + * @param time the time to delay by + * @param unit the unit of time for {@code time} + * @return this builder, for chaining + */ TaskBuilder delay(int time, TimeUnit unit); + /** + * Specifies that the task should continue running after waiting for the specified amount, until it is cancelled. + * @param time the time to delay by + * @param unit the unit of time for {@code time} + * @return this builder, for chaining + */ TaskBuilder repeat(int time, TimeUnit unit); + /** + * Clears the delay on this task. + * @return this builder, for chaining + */ TaskBuilder clearDelay(); + /** + * Clears the repeat interval on this task. + * @return this builder, for chaining + */ TaskBuilder clearRepeat(); + /** + * Schedules this task for execution. + * @return the scheduled task + */ ScheduledTask schedule(); } } diff --git a/api/src/main/java/com/velocitypowered/api/scheduler/package-info.java b/api/src/main/java/com/velocitypowered/api/scheduler/package-info.java new file mode 100644 index 000000000..155395528 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/scheduler/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides utilities for scheduling tasks with a fluent builder. + */ +package com.velocitypowered.api.scheduler; \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/server/Favicon.java b/api/src/main/java/com/velocitypowered/api/util/Favicon.java similarity index 98% rename from api/src/main/java/com/velocitypowered/api/server/Favicon.java rename to api/src/main/java/com/velocitypowered/api/util/Favicon.java index a25e5bea8..8fc1b2cb3 100644 --- a/api/src/main/java/com/velocitypowered/api/server/Favicon.java +++ b/api/src/main/java/com/velocitypowered/api/util/Favicon.java @@ -1,4 +1,4 @@ -package com.velocitypowered.api.server; +package com.velocitypowered.api.util; import com.google.common.base.Preconditions; import org.checkerframework.checker.nullness.qual.NonNull; 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 237939ef1..5fd716436 100644 --- a/api/src/main/java/com/velocitypowered/api/util/GameProfile.java +++ b/api/src/main/java/com/velocitypowered/api/util/GameProfile.java @@ -8,9 +8,9 @@ import java.util.List; import java.util.UUID; /** - * Represents a Mojang game profile. + * Represents a Mojang game profile. This class is immutable. */ -public class GameProfile { +public final class GameProfile { private final String id; private final String name; private final List properties; @@ -37,6 +37,11 @@ public class GameProfile { return properties; } + /** + * Creates a game profile suitable for use in offline-mode. + * @param username the username to use + * @return the new offline-mode game profile + */ public static GameProfile forOfflinePlayer(@NonNull String username) { Preconditions.checkNotNull(username, "username"); String id = UuidUtils.toUndashed(UuidUtils.generateOfflinePlayerUuid(username)); @@ -52,7 +57,7 @@ public class GameProfile { '}'; } - public class Property { + public final class Property { private final String name; private final String value; private final String signature; diff --git a/api/src/main/java/com/velocitypowered/api/util/UuidUtils.java b/api/src/main/java/com/velocitypowered/api/util/UuidUtils.java index 3cff823cd..a6c89b9cd 100644 --- a/api/src/main/java/com/velocitypowered/api/util/UuidUtils.java +++ b/api/src/main/java/com/velocitypowered/api/util/UuidUtils.java @@ -7,11 +7,19 @@ import java.nio.charset.StandardCharsets; import java.util.Objects; import java.util.UUID; +/** + * Provides a small, useful selection of utilities for working with Minecraft UUIDs. + */ public class UuidUtils { private UuidUtils() { throw new AssertionError(); } + /** + * Converts from an undashed Mojang-style UUID into a Java {@link UUID} object. + * @param string the string to convert + * @return the UUID object + */ public static @NonNull UUID fromUndashed(final @NonNull String string) { Objects.requireNonNull(string, "string"); Preconditions.checkArgument(string.length() == 32, "Length is incorrect"); @@ -21,11 +29,21 @@ public class UuidUtils { ); } + /** + * Converts from a Java {@link UUID} object into an undashed Mojang-style UUID. + * @param uuid the UUID to convert + * @return the undashed UUID + */ public static @NonNull String toUndashed(final @NonNull UUID uuid) { Preconditions.checkNotNull(uuid, "uuid"); return Long.toUnsignedString(uuid.getMostSignificantBits(), 16) + Long.toUnsignedString(uuid.getLeastSignificantBits(), 16); } + /** + * Generates a UUID for use for offline mode. + * @param username the username to use + * @return the offline mode UUID + */ public static @NonNull UUID generateOfflinePlayerUuid(@NonNull String username) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(StandardCharsets.UTF_8)); } diff --git a/api/src/main/java/com/velocitypowered/api/util/package-info.java b/api/src/main/java/com/velocitypowered/api/util/package-info.java new file mode 100644 index 000000000..ef28b6624 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/util/package-info.java @@ -0,0 +1,4 @@ +/** + * Provides a selection of miscellaneous utilities for use by plugins and the proxy. + */ +package com.velocitypowered.api.util; \ No newline at end of file diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 76ef64ab1..92db57593 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -10,10 +10,10 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; -import com.velocitypowered.api.server.Favicon; +import com.velocitypowered.api.util.Favicon; import com.velocitypowered.api.plugin.PluginManager; -import com.velocitypowered.api.server.ServerInfo; -import com.velocitypowered.network.ConnectionManager; +import com.velocitypowered.api.proxy.server.ServerInfo; +import com.velocitypowered.proxy.network.ConnectionManager; import com.velocitypowered.proxy.command.ServerCommand; import com.velocitypowered.proxy.command.ShutdownCommand; import com.velocitypowered.proxy.command.VelocityCommand; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java index 1a16f34c0..695aa5094 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/ServerCommand.java @@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableList; import com.velocitypowered.api.command.Command; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.Player; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.proxy.VelocityServer; import net.kyori.text.TextComponent; import net.kyori.text.format.TextColor; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 45a707b29..5843cb59a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.config; import com.google.common.collect.ImmutableMap; import com.moandjiezana.toml.Toml; -import com.velocitypowered.api.server.Favicon; +import com.velocitypowered.api.util.Favicon; import com.velocitypowered.proxy.util.AddressUtil; import com.velocitypowered.api.util.LegacyChatColorUtils; import io.netty.buffer.ByteBufUtil; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index a87c95e40..a6ec95604 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -24,14 +24,14 @@ import javax.crypto.spec.SecretKeySpec; import java.security.GeneralSecurityException; -import static com.velocitypowered.network.Connections.CIPHER_DECODER; -import static com.velocitypowered.network.Connections.CIPHER_ENCODER; -import static com.velocitypowered.network.Connections.COMPRESSION_DECODER; -import static com.velocitypowered.network.Connections.COMPRESSION_ENCODER; -import static com.velocitypowered.network.Connections.FRAME_DECODER; -import static com.velocitypowered.network.Connections.FRAME_ENCODER; -import static com.velocitypowered.network.Connections.MINECRAFT_DECODER; -import static com.velocitypowered.network.Connections.MINECRAFT_ENCODER; +import static com.velocitypowered.proxy.network.Connections.CIPHER_DECODER; +import static com.velocitypowered.proxy.network.Connections.CIPHER_ENCODER; +import static com.velocitypowered.proxy.network.Connections.COMPRESSION_DECODER; +import static com.velocitypowered.proxy.network.Connections.COMPRESSION_ENCODER; +import static com.velocitypowered.proxy.network.Connections.FRAME_DECODER; +import static com.velocitypowered.proxy.network.Connections.FRAME_ENCODER; +import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER; +import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER; /** * A utility class to make working with the pipeline a little less painful and transparently handles certain Minecraft 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 46516dd17..23e4f6062 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 @@ -2,7 +2,6 @@ package com.velocitypowered.proxy.connection.backend; import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.ConnectionRequestBuilder; -import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.proxy.config.PlayerInfoForwarding; @@ -17,7 +16,7 @@ import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.ServerLogin; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.protocol.StateRegistry; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import io.netty.channel.*; @@ -27,13 +26,13 @@ import io.netty.util.AttributeKey; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import static com.velocitypowered.network.Connections.FRAME_DECODER; -import static com.velocitypowered.network.Connections.FRAME_ENCODER; -import static com.velocitypowered.network.Connections.HANDLER; -import static com.velocitypowered.network.Connections.MINECRAFT_DECODER; -import static com.velocitypowered.network.Connections.MINECRAFT_ENCODER; -import static com.velocitypowered.network.Connections.READ_TIMEOUT; -import static com.velocitypowered.network.Connections.SERVER_READ_TIMEOUT_SECONDS; +import static com.velocitypowered.proxy.network.Connections.FRAME_DECODER; +import static com.velocitypowered.proxy.network.Connections.FRAME_ENCODER; +import static com.velocitypowered.proxy.network.Connections.HANDLER; +import static com.velocitypowered.proxy.network.Connections.MINECRAFT_DECODER; +import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER; +import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; +import static com.velocitypowered.proxy.network.Connections.SERVER_READ_TIMEOUT_SECONDS; public class VelocityServerConnection implements MinecraftConnectionAssociation, ServerConnection { static final AttributeKey> CONNECTION_NOTIFIER = 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 91c88ce8b..1660f68b4 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 @@ -21,7 +21,7 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.util.ThrowableUtils; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; 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 9cfa0227f..58ce7bff5 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 @@ -9,7 +9,7 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; -import com.velocitypowered.api.server.ServerPing; +import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolConstants; import com.velocitypowered.proxy.protocol.StateRegistry; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index e4bd26180..67b3cdf82 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -5,9 +5,9 @@ import com.velocitypowered.api.event.connection.LoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent.PreLoginComponentResult; import com.velocitypowered.api.event.permission.PermissionsSetupEvent; -import com.velocitypowered.api.event.player.gameprofile.GameProfileRequestEvent; +import com.velocitypowered.api.event.player.GameProfileRequestEvent; import com.velocitypowered.api.proxy.InboundConnection; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.proxy.connection.VelocityConstants; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.proxy.protocol.MinecraftPacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index 97d479dec..fb70edd02 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -12,7 +12,7 @@ import com.velocitypowered.proxy.protocol.packet.StatusPing; import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.StatusResponse; import com.velocitypowered.proxy.connection.MinecraftConnection; -import com.velocitypowered.api.server.ServerPing; +import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; diff --git a/proxy/src/main/java/com/velocitypowered/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java similarity index 93% rename from proxy/src/main/java/com/velocitypowered/network/ConnectionManager.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index d4efdee5e..732b8b331 100644 --- a/proxy/src/main/java/com/velocitypowered/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -1,4 +1,4 @@ -package com.velocitypowered.network; +package com.velocitypowered.proxy.network; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.velocitypowered.natives.util.Natives; @@ -44,14 +44,7 @@ import java.util.Set; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; -import static com.velocitypowered.network.Connections.CLIENT_READ_TIMEOUT_SECONDS; -import static com.velocitypowered.network.Connections.FRAME_DECODER; -import static com.velocitypowered.network.Connections.FRAME_ENCODER; -import static com.velocitypowered.network.Connections.LEGACY_PING_DECODER; -import static com.velocitypowered.network.Connections.LEGACY_PING_ENCODER; -import static com.velocitypowered.network.Connections.MINECRAFT_DECODER; -import static com.velocitypowered.network.Connections.MINECRAFT_ENCODER; -import static com.velocitypowered.network.Connections.READ_TIMEOUT; +import static com.velocitypowered.proxy.network.Connections.*; public final class ConnectionManager { private static final Logger logger = LogManager.getLogger(ConnectionManager.class); diff --git a/proxy/src/main/java/com/velocitypowered/network/Connections.java b/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java similarity index 94% rename from proxy/src/main/java/com/velocitypowered/network/Connections.java rename to proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java index 3ca2ff9dc..518a3acbe 100644 --- a/proxy/src/main/java/com/velocitypowered/network/Connections.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/Connections.java @@ -1,4 +1,4 @@ -package com.velocitypowered.network; +package com.velocitypowered.proxy.network; public interface Connections { String CIPHER_DECODER = "cipher-decoder"; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java index f980ccdb7..2b733f5ef 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/LegacyPingResponse.java @@ -1,6 +1,6 @@ package com.velocitypowered.proxy.protocol.packet; -import com.velocitypowered.api.server.ServerPing; +import com.velocitypowered.api.proxy.server.ServerPing; import net.kyori.text.serializer.ComponentSerializers; public class LegacyPingResponse { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/FaviconSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/FaviconSerializer.java index 7243e8b06..012c9fca0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/FaviconSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/FaviconSerializer.java @@ -1,7 +1,7 @@ package com.velocitypowered.proxy.protocol.util; import com.google.gson.*; -import com.velocitypowered.api.server.Favicon; +import com.velocitypowered.api.util.Favicon; import java.lang.reflect.Type; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/ServerMap.java b/proxy/src/main/java/com/velocitypowered/proxy/util/ServerMap.java index d961d719d..75784ef0b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/ServerMap.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/ServerMap.java @@ -2,7 +2,7 @@ package com.velocitypowered.proxy.util; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import java.util.*; import java.util.concurrent.locks.ReadWriteLock; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java index 30d2c617d..e332ed85f 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java @@ -1,6 +1,6 @@ package com.velocitypowered.proxy.util; -import com.velocitypowered.api.server.ServerInfo; +import com.velocitypowered.api.proxy.server.ServerInfo; import org.junit.jupiter.api.Test; import java.net.InetAddress;