diff --git a/api/src/ap/java/com/velocitypowered/api/plugin/ap/PluginAnnotationProcessor.java b/api/src/ap/java/com/velocitypowered/api/plugin/ap/PluginAnnotationProcessor.java index 7806a03e4..b22b448e9 100644 --- a/api/src/ap/java/com/velocitypowered/api/plugin/ap/PluginAnnotationProcessor.java +++ b/api/src/ap/java/com/velocitypowered/api/plugin/ap/PluginAnnotationProcessor.java @@ -57,8 +57,8 @@ public class PluginAnnotationProcessor extends AbstractProcessor { if (Objects.equals(pluginClassFound, qualifiedName.toString())) { if (!warnedAboutMultiplePlugins) { environment.getMessager() - .printMessage(Diagnostic.Kind.WARNING, "Velocity does not yet currently support " + - "multiple plugins. We are using " + pluginClassFound + .printMessage(Diagnostic.Kind.WARNING, "Velocity does not yet currently support " + + "multiple plugins. We are using " + pluginClassFound + " for your plugin's main class."); warnedAboutMultiplePlugins = true; } @@ -69,8 +69,8 @@ public class PluginAnnotationProcessor extends AbstractProcessor { if (!PluginDescription.ID_PATTERN.matcher(plugin.id()).matches()) { environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Invalid ID for plugin " + qualifiedName - + ". IDs must start alphabetically, have alphanumeric characters, and can " + - "contain dashes or underscores."); + + ". IDs must start alphabetically, have alphanumeric characters, and can " + + "contain dashes or underscores."); return false; } diff --git a/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java b/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java index 0a52e340d..782fe3b7f 100644 --- a/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java +++ b/api/src/ap/java/com/velocitypowered/api/plugin/ap/SerializedPluginDescription.java @@ -23,7 +23,7 @@ public class SerializedPluginDescription { private final @Nullable List dependencies; private final String main; - public SerializedPluginDescription(String id, String name, String version, String description, + private SerializedPluginDescription(String id, String name, String version, String description, String url, List authors, List dependencies, String main) { this.id = Preconditions.checkNotNull(id, "id"); @@ -37,7 +37,7 @@ public class SerializedPluginDescription { this.main = Preconditions.checkNotNull(main, "main"); } - public static SerializedPluginDescription from(Plugin plugin, String qualifiedName) { + static SerializedPluginDescription from(Plugin plugin, String qualifiedName) { List dependencies = new ArrayList<>(); for (com.velocitypowered.api.plugin.Dependency dependency : plugin.dependencies()) { dependencies.add(new Dependency(dependency.id(), dependency.optional())); @@ -89,14 +89,14 @@ public class SerializedPluginDescription { return false; } SerializedPluginDescription that = (SerializedPluginDescription) o; - return Objects.equals(id, that.id) && - Objects.equals(name, that.name) && - Objects.equals(version, that.version) && - Objects.equals(description, that.description) && - Objects.equals(url, that.url) && - Objects.equals(authors, that.authors) && - Objects.equals(dependencies, that.dependencies) && - Objects.equals(main, that.main); + return Objects.equals(id, that.id) + && Objects.equals(name, that.name) + && Objects.equals(version, that.version) + && Objects.equals(description, that.description) + && Objects.equals(url, that.url) + && Objects.equals(authors, that.authors) + && Objects.equals(dependencies, that.dependencies) + && Objects.equals(main, that.main); } @Override @@ -106,16 +106,16 @@ public class SerializedPluginDescription { @Override public String toString() { - return "SerializedPluginDescription{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", version='" + version + '\'' + - ", description='" + description + '\'' + - ", url='" + url + '\'' + - ", authors=" + authors + - ", dependencies=" + dependencies + - ", main='" + main + '\'' + - '}'; + return "SerializedPluginDescription{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", version='" + version + '\'' + + ", description='" + description + '\'' + + ", url='" + url + '\'' + + ", authors=" + authors + + ", dependencies=" + dependencies + + ", main='" + main + '\'' + + '}'; } public static class Dependency { @@ -145,8 +145,8 @@ public class SerializedPluginDescription { return false; } Dependency that = (Dependency) o; - return optional == that.optional && - Objects.equals(id, that.id); + return optional == that.optional + && Objects.equals(id, that.id); } @Override @@ -156,10 +156,10 @@ public class SerializedPluginDescription { @Override public String toString() { - return "Dependency{" + - "id='" + id + '\'' + - ", optional=" + optional + - '}'; + return "Dependency{" + + "id='" + id + '\'' + + ", optional=" + optional + + '}'; } } } 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 2fbd8c891..0a7986bf7 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 @@ -20,8 +20,8 @@ public final class ConnectionHandshakeEvent { @Override public String toString() { - return "ConnectionHandshakeEvent{" + - "connection=" + connection + - '}'; + return "ConnectionHandshakeEvent{" + + "connection=" + 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 471e639c5..dee4dd7e0 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 @@ -21,8 +21,8 @@ public final class DisconnectEvent { @Override public String toString() { - return "DisconnectEvent{" + - "player=" + player + - '}'; + return "DisconnectEvent{" + + "player=" + player + + '}'; } } 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 5958bfd04..c204d9027 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 @@ -34,9 +34,9 @@ public final class LoginEvent implements ResultedEvent *
  • Survival
  • @@ -142,7 +144,7 @@ public interface TabListEntry { } /** - * Sets the displayed name of the {@link TabListEntry} + * Sets the displayed name of the {@link TabListEntry}. * * @param displayName to set * @return {@code this}, for chaining @@ -154,7 +156,7 @@ public interface TabListEntry { } /** - * Sets the latency of the {@link TabListEntry} + * Sets the latency of the {@link TabListEntry}. * * @param latency to set * @return {@code this}, for chaining @@ -166,7 +168,7 @@ public interface TabListEntry { } /** - * Sets the game mode of the {@link TabListEntry} + * Sets the game mode of the {@link TabListEntry}. * * @param gameMode to set * @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 1e934dfeb..b02a446e5 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 @@ -1,5 +1,6 @@ package com.velocitypowered.api.proxy.server; +import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.proxy.config.ProxyConfig; @@ -7,6 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Optional; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -90,7 +92,7 @@ public final class QueryResponse { } /** - * Get proxy (public facing) hostname + * Get proxy (public facing) hostname. * * @return proxy hostname */ @@ -99,7 +101,7 @@ public final class QueryResponse { } /** - * Get proxy (public facing) port + * Get proxy (public facing) port. * * @return proxy port */ @@ -136,7 +138,7 @@ public final class QueryResponse { /** - * Creates a new {@link Builder} instance from data represented by this response + * Creates a new {@link Builder} instance from data represented by this response. * * @return {@link QueryResponse} builder */ @@ -155,7 +157,7 @@ public final class QueryResponse { } /** - * Creates a new {@link Builder} instance + * Creates a new {@link Builder} instance. * * @return {@link QueryResponse} builder */ @@ -225,6 +227,11 @@ public final class QueryResponse { return this; } + /** + * Sets the port where this proxy is running. + * @param proxyPort the port where the proxy is running + * @return this instance, for chaining + */ public Builder proxyPort(int proxyPort) { Preconditions .checkArgument(proxyPort >= 1 && proxyPort <= 65535, "proxyPort must be between 1-65535"); @@ -262,13 +269,19 @@ public final class QueryResponse { return this; } + /** + * Clears all currently set plugins. + * + * @return this builder, for chaining + */ public Builder clearPlugins() { this.plugins.clear(); return this; } /** - * Builds new {@link QueryResponse} with supplied data + * Builds a new {@link QueryResponse} with the supplied data. The current instance can be reused + * after this method is called. * * @return response */ @@ -289,37 +302,36 @@ public final class QueryResponse { } /** - * Plugin information + * Represents a plugin in the query response. */ public static class PluginInformation { - private String name; - private String version; + private final String name; + private final @Nullable String version; - public PluginInformation(String name, String version) { + PluginInformation(String name, @Nullable String version) { this.name = Preconditions.checkNotNull(name, "name"); - this.version = Preconditions.checkNotNull(version, "version"); + this.version = version; } public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - - public void setVersion(@Nullable String version) { - this.version = version; - } - - @Nullable - public String getVersion() { - return version; + public Optional getVersion() { + return Optional.ofNullable(version); } public static PluginInformation of(String name, @Nullable String version) { return new PluginInformation(name, version); } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("name", name) + .add("version", version) + .toString(); + } } } 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 16dafc20c..e1317f9e8 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 @@ -35,10 +35,10 @@ public final class ServerInfo { @Override public String toString() { - return "ServerInfo{" + - "name='" + name + '\'' + - ", address=" + address + - '}'; + return "ServerInfo{" + + "name='" + name + '\'' + + ", address=" + address + + '}'; } @Override @@ -50,8 +50,8 @@ public final class ServerInfo { return false; } ServerInfo that = (ServerInfo) o; - return Objects.equals(name, that.name) && - Objects.equals(address, that.address); + return Objects.equals(name, that.name) + && Objects.equals(address, that.address); } @Override 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 31eb1dc12..80a995d93 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 @@ -1,5 +1,6 @@ package com.velocitypowered.api.proxy.server; +import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.util.Favicon; @@ -59,14 +60,18 @@ public final class ServerPing { @Override public String toString() { - return "ServerPing{" + - "version=" + version + - ", players=" + players + - ", description=" + description + - ", favicon='" + favicon + '\'' + - '}'; + return "ServerPing{" + + "version=" + version + + ", players=" + players + + ", description=" + description + + ", favicon='" + favicon + '\'' + + '}'; } + /** + * Returns a copy of this {@link ServerPing} instance as a builder so that it can be modified. + * @return a copy of this instance as a {@link Builder} + */ public Builder asBuilder() { Builder builder = new Builder(); builder.version = version; @@ -171,6 +176,11 @@ public final class ServerPing { return this; } + /** + * Uses the information from this builder to create a new {@link ServerPing} instance. The + * builder can be re-used after this event has been called. + * @return a new {@link ServerPing} instance + */ public ServerPing build() { if (this.version == null) { throw new IllegalStateException("version not specified"); @@ -217,18 +227,18 @@ public final class ServerPing { @Override public String toString() { - return "Builder{" + - "version=" + version + - ", onlinePlayers=" + onlinePlayers + - ", maximumPlayers=" + maximumPlayers + - ", samplePlayers=" + samplePlayers + - ", modType=" + modType + - ", mods=" + mods + - ", description=" + description + - ", favicon=" + favicon + - ", nullOutPlayers=" + nullOutPlayers + - ", nullOutModinfo=" + nullOutModinfo + - '}'; + return MoreObjects.toStringHelper(this) + .add("version", version) + .add("onlinePlayers", onlinePlayers) + .add("maximumPlayers", maximumPlayers) + .add("samplePlayers", samplePlayers) + .add("modType", modType) + .add("mods", mods) + .add("description", description) + .add("favicon", favicon) + .add("nullOutPlayers", nullOutPlayers) + .add("nullOutModinfo", nullOutModinfo) + .toString(); } } @@ -237,9 +247,14 @@ public final class ServerPing { private final int protocol; private final String name; + /** + * Creates a new instance. + * @param protocol the protocol version as an integer + * @param name a friendly name for the protocol version + */ public Version(int protocol, String name) { this.protocol = protocol; - this.name = name; + this.name = Preconditions.checkNotNull(name, "name"); } public int getProtocol() { @@ -252,10 +267,10 @@ public final class ServerPing { @Override public String toString() { - return "Version{" + - "protocol=" + protocol + - ", name='" + name + '\'' + - '}'; + return "Version{" + + "protocol=" + protocol + + ", name='" + name + '\'' + + '}'; } } @@ -265,6 +280,12 @@ public final class ServerPing { private final int max; private final List sample; + /** + * Creates a new instance. + * @param online the number of online players + * @param max the maximum number of players + * @param sample a sample of players on the server + */ public Players(int online, int max, List sample) { this.online = online; this.max = max; @@ -285,11 +306,11 @@ public final class ServerPing { @Override public String toString() { - return "Players{" + - "online=" + online + - ", max=" + max + - ", sample=" + sample + - '}'; + return "Players{" + + "online=" + online + + ", max=" + max + + ", sample=" + sample + + '}'; } } @@ -313,10 +334,10 @@ public final class ServerPing { @Override public String toString() { - return "SamplePlayer{" + - "name='" + name + '\'' + - ", id=" + id + - '}'; + return "SamplePlayer{" + + "name='" + name + '\'' + + ", id=" + id + + '}'; } } } 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 c6aa38c9c..276ad13d1 100644 --- a/api/src/main/java/com/velocitypowered/api/util/Favicon.java +++ b/api/src/main/java/com/velocitypowered/api/util/Favicon.java @@ -59,9 +59,9 @@ public final class Favicon { @Override public String toString() { - return "Favicon{" + - "base64Url='" + base64Url + '\'' + - '}'; + return "Favicon{" + + "base64Url='" + base64Url + '\'' + + '}'; } /** @@ -72,9 +72,8 @@ public final class Favicon { */ public static Favicon create(BufferedImage image) { Preconditions.checkNotNull(image, "image"); - Preconditions - .checkArgument(image.getWidth() == 64 && image.getHeight() == 64, "Image does not have" + - " 64x64 dimensions (found %sx%s)", image.getWidth(), image.getHeight()); + Preconditions.checkArgument(image.getWidth() == 64 && image.getHeight() == 64, + "Image is not 64x64(found %sx%s)", image.getWidth(), image.getHeight()); ByteArrayOutputStream os = new ByteArrayOutputStream(); try { ImageIO.write(image, "PNG", os); 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 4646ededa..a868a801c 100644 --- a/api/src/main/java/com/velocitypowered/api/util/GameProfile.java +++ b/api/src/main/java/com/velocitypowered/api/util/GameProfile.java @@ -50,11 +50,11 @@ public final class GameProfile { @Override public String toString() { - return "GameProfile{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", properties=" + properties + - '}'; + return "GameProfile{" + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", properties=" + properties + + '}'; } public static final class Property { @@ -83,11 +83,11 @@ public final class GameProfile { @Override public String toString() { - return "Property{" + - "name='" + name + '\'' + - ", value='" + value + '\'' + - ", signature='" + signature + '\'' + - '}'; + return "Property{" + + "name='" + name + '\'' + + ", value='" + value + '\'' + + ", signature='" + 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 2c4aee8dd..c858cfb4b 100644 --- a/api/src/main/java/com/velocitypowered/api/util/ModInfo.java +++ b/api/src/main/java/com/velocitypowered/api/util/ModInfo.java @@ -26,10 +26,10 @@ public final class ModInfo { @Override public String toString() { - return "ModInfo{" + - "type='" + type + '\'' + - ", modList=" + modList + - '}'; + return "ModInfo{" + + "type='" + type + '\'' + + ", modList=" + modList + + '}'; } public static final class Mod { @@ -52,10 +52,10 @@ public final class ModInfo { @Override public String toString() { - return "Mod{" + - "id='" + id + '\'' + - ", version='" + version + '\'' + - '}'; + return "Mod{" + + "id='" + id + '\'' + + ", version='" + version + '\'' + + '}'; } } } \ No newline at end of file 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 b55ed0a68..59d31a903 100644 --- a/api/src/main/java/com/velocitypowered/api/util/ProxyVersion.java +++ b/api/src/main/java/com/velocitypowered/api/util/ProxyVersion.java @@ -13,6 +13,13 @@ public final class ProxyVersion { private final String vendor; private final String version; + /** + * Creates a new {@link ProxyVersion} instance. + * + * @param name the name for the proxy implementation + * @param vendor the vendor for the proxy implementation + * @param version the version for the proxy implementation + */ public ProxyVersion(String name, String vendor, String version) { this.name = Preconditions.checkNotNull(name, "name"); this.vendor = Preconditions.checkNotNull(vendor, "vendor"); @@ -40,9 +47,9 @@ public final class ProxyVersion { return false; } ProxyVersion that = (ProxyVersion) o; - return Objects.equals(name, that.name) && - Objects.equals(vendor, that.vendor) && - Objects.equals(version, that.version); + return Objects.equals(name, that.name) + && Objects.equals(vendor, that.vendor) + && Objects.equals(version, that.version); } @Override @@ -52,10 +59,10 @@ public final class ProxyVersion { @Override public String toString() { - return "ProxyVersion{" + - "name='" + name + '\'' + - ", vendor='" + vendor + '\'' + - ", version='" + version + '\'' + - '}'; + return "ProxyVersion{" + + "name='" + name + '\'' + + ", vendor='" + vendor + '\'' + + ", version='" + version + '\'' + + '}'; } } 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 a0f0e3f85..7e443c7b5 100644 --- a/api/src/main/java/com/velocitypowered/api/util/UuidUtils.java +++ b/api/src/main/java/com/velocitypowered/api/util/UuidUtils.java @@ -38,8 +38,10 @@ public final class UuidUtils { */ public static String toUndashed(final UUID uuid) { Preconditions.checkNotNull(uuid, "uuid"); - return Strings.padStart(Long.toHexString(uuid.getMostSignificantBits()), 16, '0') + - Strings.padStart(Long.toHexString(uuid.getLeastSignificantBits()), 16, '0'); + String msbStr = Long.toHexString(uuid.getMostSignificantBits()); + String lsbStr = Long.toHexString(uuid.getLeastSignificantBits()); + return Strings.padStart(msbStr, 16, '0') + Strings.padStart(lsbStr, + 16, '0'); } /** diff --git a/api/src/main/java/com/velocitypowered/api/util/title/TextTitle.java b/api/src/main/java/com/velocitypowered/api/util/title/TextTitle.java index 3fd650e62..4d0b1ec59 100644 --- a/api/src/main/java/com/velocitypowered/api/util/title/TextTitle.java +++ b/api/src/main/java/com/velocitypowered/api/util/title/TextTitle.java @@ -1,5 +1,6 @@ package com.velocitypowered.api.util.title; +import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import java.util.Objects; import java.util.Optional; @@ -110,24 +111,24 @@ public final class TextTitle implements Title { return false; } TextTitle textTitle = (TextTitle) o; - return stay == textTitle.stay && - fadeIn == textTitle.fadeIn && - fadeOut == textTitle.fadeOut && - resetBeforeSend == textTitle.resetBeforeSend && - Objects.equals(title, textTitle.title) && - Objects.equals(subtitle, textTitle.subtitle); + return stay == textTitle.stay + && fadeIn == textTitle.fadeIn + && fadeOut == textTitle.fadeOut + && resetBeforeSend == textTitle.resetBeforeSend + && Objects.equals(title, textTitle.title) + && Objects.equals(subtitle, textTitle.subtitle); } @Override public String toString() { - return "TextTitle{" + - "title=" + title + - ", subtitle=" + subtitle + - ", stay=" + stay + - ", fadeIn=" + fadeIn + - ", fadeOut=" + fadeOut + - ", resetBeforeSend=" + resetBeforeSend + - '}'; + return MoreObjects.toStringHelper(this) + .add("title", title) + .add("subtitle", subtitle) + .add("stay", stay) + .add("fadeIn", fadeIn) + .add("fadeOut", fadeOut) + .add("resetBeforeSend", resetBeforeSend) + .toString(); } @Override @@ -238,14 +239,14 @@ public final class TextTitle implements Title { @Override public String toString() { - return "Builder{" + - "title=" + title + - ", subtitle=" + subtitle + - ", stay=" + stay + - ", fadeIn=" + fadeIn + - ", fadeOut=" + fadeOut + - ", resetBeforeSend=" + resetBeforeSend + - '}'; + return MoreObjects.toStringHelper(this) + .add("title", title) + .add("subtitle", subtitle) + .add("stay", stay) + .add("fadeIn", fadeIn) + .add("fadeOut", fadeOut) + .add("resetBeforeSend", resetBeforeSend) + .toString(); } } }