From 868976e09c53b3094364205704a029b1dfd62e66 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 15 Nov 2018 19:04:39 -0500 Subject: [PATCH] Add Javadoc and remove all Checkstyle issues from API and natives. --- .../event/player/KickedFromServerEvent.java | 12 +++- .../api/event/player/PlayerChatEvent.java | 21 ++++++- .../api/event/player/PlayerModInfoEvent.java | 2 +- .../event/player/ServerPreConnectEvent.java | 18 ++++++ .../api/proxy/player/TabList.java | 11 +++- .../api/proxy/player/TabListEntry.java | 2 +- .../api/proxy/server/QueryResponse.java | 61 ++++++++++++++++++- .../api/proxy/server/ServerPing.java | 8 +++ .../velocitypowered/api/util/GameProfile.java | 12 +++- .../natives/util/NativeCodeLoader.java | 8 +-- .../velocitypowered/natives/util/Natives.java | 2 +- .../compression/VelocityCompressorTest.java | 4 +- .../encryption/VelocityCipherTest.java | 2 +- .../proxy/connection/MinecraftConnection.java | 2 +- .../proxy/network/ConnectionManager.java | 2 +- 15 files changed, 149 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java index 22a411ec4..ce55ae353 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java @@ -11,7 +11,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * Fired when a player is kicked from a server. You may either allow Velocity to kick the player - * (with an optional reason override) or redirect the player to a separate server. + * (with an optional reason override) or redirect the player to a separate server. By default, + * Velocity will notify the user (if they are already connected to a server) or disconnect them + * (if they are not on a server and no other servers are available). */ public final class KickedFromServerEvent implements ResultedEvent { @@ -22,6 +24,14 @@ public final class KickedFromServerEvent implements private final boolean duringServerConnect; private ServerKickResult result; + /** + * Creates a {@code KickedFromServerEvent} instance. + * @param player the player affected + * @param server the server the player disconnected from + * @param originalReason the reason for being kicked, optional + * @param duringServerConnect whether or not the player was kicked during the connection process + * @param fancyReason a fancy reason for being disconnected, used for the initial result + */ public KickedFromServerEvent(Player player, RegisteredServer server, @Nullable Component originalReason, boolean duringServerConnect, Component fancyReason) { this.player = Preconditions.checkNotNull(player, "player"); 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 ffb3f1a05..6b8b7bba1 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 @@ -16,6 +16,11 @@ public final class PlayerChatEvent implements ResultedEvent getEntries(); - // Necessary because the TabListEntry implementation isn't in the api + /** + * Builds a tab list entry. + * + * @deprecated Internal usage. Use {@link TabListEntry.Builder} instead. + * @param profile profile + * @param displayName display name + * @param latency latency + * @param gameMode game mode + * @return entry + */ @Deprecated TabListEntry buildEntry(GameProfile profile, @Nullable Component displayName, int latency, int gameMode); 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 e4fbb606d..41af4e496 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 @@ -86,7 +86,7 @@ public interface TabListEntry { int getGameMode(); /** - * Sets the game mode for {@code this} entry to the specified value + * Sets the game mode for {@code this} entry to the specified value. * * @param gameMode to change to * @return {@code this}, for chaining 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 b02a446e5..7530e54d6 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 @@ -195,33 +195,63 @@ public final class QueryResponse { private Builder() { } + /** + * Sets the hostname for the response. + * @param hostname the hostname to set + * @return this builder, for chaining + */ public Builder hostname(String hostname) { this.hostname = Preconditions.checkNotNull(hostname, "hostname"); return this; } + /** + * Sets the game version for the response. + * @param gameVersion the game version to set + * @return this builder, for chaining + */ public Builder gameVersion(String gameVersion) { this.gameVersion = Preconditions.checkNotNull(gameVersion, "gameVersion"); return this; } + /** + * Sets the map that will appear in the response. + * @param map the map to set + * @return this builder, for chaining + */ public Builder map(String map) { this.map = Preconditions.checkNotNull(map, "map"); return this; } + /** + * Sets the players that are currently claimed to be online. + * @param currentPlayers a non-negative number representing all players online + * @return this builder, for chaining + */ public Builder currentPlayers(int currentPlayers) { Preconditions.checkArgument(currentPlayers >= 0, "currentPlayers cannot be negative"); this.currentPlayers = currentPlayers; return this; } + /** + * Sets the maximum number of players this server purportedly can hold. + * @param maxPlayers a non-negative number representing the maximum number of builders + * @return this builder, for chaining + */ public Builder maxPlayers(int maxPlayers) { Preconditions.checkArgument(maxPlayers >= 0, "maxPlayers cannot be negative"); this.maxPlayers = maxPlayers; return this; } + /** + * Sets the host where this proxy is running. + * @param proxyHost the host where the proxy is running + * @return this instance, for chaining + */ public Builder proxyHost(String proxyHost) { this.proxyHost = Preconditions.checkNotNull(proxyHost, "proxyHost"); return this; @@ -239,33 +269,62 @@ public final class QueryResponse { return this; } + /** + * Adds the specified players to the player list. + * @param players the players to add + * @return this builder, for chaining + */ public Builder players(Collection players) { this.players.addAll(Preconditions.checkNotNull(players, "players")); return this; } + /** + * Adds the specified players to the player list. + * @param players the players to add + * @return this builder, for chaining + */ public Builder players(String... players) { this.players.addAll(Arrays.asList(Preconditions.checkNotNull(players, "players"))); return this; } + /** + * Removes all players from the builder. This does not affect {@link #getCurrentPlayers()}. + * @return this builder, for chaining + */ public Builder clearPlayers() { this.players.clear(); return this; } + /** + * Sets the proxy version. + * @param proxyVersion the proxy version to set + * @return this builder, for chaining + */ public Builder proxyVersion(String proxyVersion) { this.proxyVersion = Preconditions.checkNotNull(proxyVersion, "proxyVersion"); return this; } + /** + * Adds the specified plugins to the plugins list. + * @param plugins the plugins to add + * @return this builder, for chaining + */ public Builder plugins(Collection plugins) { this.plugins.addAll(Preconditions.checkNotNull(plugins, "plugins")); return this; } + /** + * Adds the specified plugins to the plugins list. + * @param plugins the plugins to add + * @return this builder, for chaining + */ public Builder plugins(PluginInformation... plugins) { - this.plugins.addAll(Arrays.asList(Preconditions.checkNotNull(plugins, "plugins"))); + this.plugins.addAll(Arrays.asList(plugins)); return this; } 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 80a995d93..6a094b662 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 @@ -29,6 +29,14 @@ public final class ServerPing { this(version, players, description, favicon, ModInfo.DEFAULT); } + /** + * Constructs a ServerPing instance. + * @param version the version of the server + * @param players the players on the server + * @param description the MOTD for the server + * @param favicon the server's favicon + * @param modinfo the mods this server runs + */ public ServerPing(Version version, @Nullable Players players, Component description, @Nullable Favicon favicon, @Nullable ModInfo modinfo) { this.version = Preconditions.checkNotNull(version, "version"); 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 015cdae97..e2760de9e 100644 --- a/api/src/main/java/com/velocitypowered/api/util/GameProfile.java +++ b/api/src/main/java/com/velocitypowered/api/util/GameProfile.java @@ -11,7 +11,8 @@ import java.util.UUID; public final class GameProfile { private final UUID id; - private final String undashedId, name; + private final String undashedId; + private final String name; private final List properties; public GameProfile(UUID id, String name, List properties) { @@ -136,12 +137,21 @@ public final class GameProfile { + '}'; } + /** + * Represents a Mojang profile property. Just like {@link GameProfile}, this class is immutable. + */ public static final class Property { private final String name; private final String value; private final String signature; + /** + * Creates a profile property entry. + * @param name the name of the property + * @param value the value of the property + * @param signature the Mojang signature for the property + */ public Property(String name, String value, String signature) { this.name = Preconditions.checkNotNull(name, "name"); this.value = Preconditions.checkNotNull(value, "value"); diff --git a/native/src/main/java/com/velocitypowered/natives/util/NativeCodeLoader.java b/native/src/main/java/com/velocitypowered/natives/util/NativeCodeLoader.java index 11dc09d5f..060de76a0 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/NativeCodeLoader.java +++ b/native/src/main/java/com/velocitypowered/natives/util/NativeCodeLoader.java @@ -76,10 +76,10 @@ public final class NativeCodeLoader implements Supplier { } static final BooleanSupplier MACOS = () -> - System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X") && - System.getProperty("os.arch").equals("x86_64"); + System.getProperty("os.name", "").equalsIgnoreCase("Mac OS X") + && System.getProperty("os.arch").equals("x86_64"); static final BooleanSupplier LINUX = () -> - System.getProperties().getProperty("os.name", "").equalsIgnoreCase("Linux") && - System.getProperty("os.arch").equals("amd64"); + System.getProperties().getProperty("os.name", "").equalsIgnoreCase("Linux") + && System.getProperty("os.arch").equals("amd64"); static final BooleanSupplier ALWAYS = () -> true; } diff --git a/native/src/main/java/com/velocitypowered/natives/util/Natives.java b/native/src/main/java/com/velocitypowered/natives/util/Natives.java index c028850df..af40ccc7e 100644 --- a/native/src/main/java/com/velocitypowered/natives/util/Natives.java +++ b/native/src/main/java/com/velocitypowered/natives/util/Natives.java @@ -43,7 +43,7 @@ public class Natives { }; } - public static final NativeCodeLoader compressor = new NativeCodeLoader<>( + public static final NativeCodeLoader compress = new NativeCodeLoader<>( ImmutableList.of( new NativeCodeLoader.Variant<>(NativeCodeLoader.MACOS, copyAndLoadNative("/macosx/velocity-compress.dylib"), "native (macOS)", diff --git a/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java b/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java index 64c1df251..641e6ada4 100644 --- a/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java +++ b/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java @@ -20,13 +20,13 @@ class VelocityCompressorTest { @BeforeAll static void checkNatives() { - Natives.compressor.getLoadedVariant(); + Natives.compress.getLoadedVariant(); } @Test @EnabledOnOs({MAC, LINUX}) void nativeIntegrityCheck() throws DataFormatException { - VelocityCompressor compressor = Natives.compressor.get().create(Deflater.DEFAULT_COMPRESSION); + VelocityCompressor compressor = Natives.compress.get().create(Deflater.DEFAULT_COMPRESSION); if (compressor instanceof JavaVelocityCompressor) { compressor.dispose(); fail("Loaded regular compressor"); diff --git a/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java b/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java index 968f675b5..d2db05af4 100644 --- a/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java +++ b/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java @@ -28,7 +28,7 @@ class VelocityCipherTest { void nativeIntegrityCheck() throws GeneralSecurityException { VelocityCipherFactory factory = Natives.cipher.get(); if (factory == JavaVelocityCipher.FACTORY) { - fail("Loaded regular compressor"); + fail("Loaded regular cipher"); } check(factory); } 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 441ff38b6..d2c375f66 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -248,7 +248,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { } int level = server.getConfiguration().getCompressionLevel(); - VelocityCompressor compressor = Natives.compressor.get().create(level); + VelocityCompressor compressor = Natives.compress.get().create(level); MinecraftCompressEncoder encoder = new MinecraftCompressEncoder(threshold, compressor); MinecraftCompressDecoder decoder = new MinecraftCompressDecoder(threshold, compressor); 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 544c6f2f5..92d5a657d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -39,7 +39,7 @@ public final class ConnectionManager { public void logChannelInformation() { LOGGER.info("Connections will use {} channels, {} compression, {} ciphers", this.transportType, - Natives.compressor.getLoadedVariant(), Natives.cipher.getLoadedVariant()); + Natives.compress.getLoadedVariant(), Natives.cipher.getLoadedVariant()); } public void bind(final InetSocketAddress address) {