From 447e7d1d50e1f1fd443ad85d8277702fdbf064f1 Mon Sep 17 00:00:00 2001 From: Mark Vainomaa Date: Sat, 27 Oct 2018 21:38:20 +0300 Subject: [PATCH] Adapt to upcoming Checker framework related changes --- .../api/proxy/server/QueryResponse.java | 83 ++++++++----------- .../proxy/protocol/netty/GS4QueryHandler.java | 2 + 2 files changed, 36 insertions(+), 49 deletions(-) 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 0edd95bc8..2da751e6f 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 @@ -3,7 +3,7 @@ package com.velocitypowered.api.proxy.server; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.proxy.config.ProxyConfig; -import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; @@ -43,7 +43,6 @@ public final class QueryResponse { * Get hostname which will be used to reply to the query. By default it is {@link ProxyConfig#getMotdComponent()} in plain text without colour codes. * @return hostname */ - @NonNull public String getHostname() { return hostname; } @@ -52,7 +51,6 @@ public final class QueryResponse { * Get game version which will be used to reply to the query. By default supported Minecraft versions range is sent. * @return game version */ - @NonNull public String getGameVersion() { return gameVersion; } @@ -61,7 +59,6 @@ public final class QueryResponse { * Get map name which will be used to reply to the query. By default {@link ProxyConfig#getQueryMap()} is sent. * @return map name */ - @NonNull public String getMap() { return map; } @@ -86,7 +83,6 @@ public final class QueryResponse { * Get proxy (public facing) hostname * @return proxy hostname */ - @NonNull public String getProxyHost() { return proxyHost; } @@ -103,7 +99,6 @@ public final class QueryResponse { * Get collection of players which will be used to reply to the query. * @return collection of players */ - @NonNull public Collection getPlayers() { return players; } @@ -112,7 +107,6 @@ public final class QueryResponse { * Get server software (name and version) which will be used to reply to the query. * @return server software */ - @NonNull public String getProxyVersion() { return proxyVersion; } @@ -121,7 +115,6 @@ public final class QueryResponse { * Get list of plugins which will be used to reply to the query. * @return collection of plugins */ - @NonNull public Collection getPlugins() { return plugins; } @@ -131,7 +124,6 @@ public final class QueryResponse { * Creates a new {@link Builder} instance from data represented by this response * @return {@link QueryResponse} builder */ - @NonNull public Builder toBuilder() { return QueryResponse.builder() .hostname(getHostname()) @@ -150,7 +142,6 @@ public final class QueryResponse { * Creates a new {@link Builder} instance * @return {@link QueryResponse} builder */ - @NonNull public static Builder builder() { return new Builder(); } @@ -159,101 +150,98 @@ public final class QueryResponse { * A builder for {@link QueryResponse} objects. */ public static final class Builder { + @MonotonicNonNull private String hostname; + + @MonotonicNonNull private String gameVersion; + + @MonotonicNonNull private String map; + + @MonotonicNonNull + private String proxyHost; + + @MonotonicNonNull + private String proxyVersion; + private int currentPlayers; private int maxPlayers; - private String proxyHost; private int proxyPort; - private Collection players = new ArrayList<>(); - private String proxyVersion; + + private List players = new ArrayList<>(); private List plugins = new ArrayList<>(); private Builder() {} - @NonNull - public Builder hostname(@NonNull String hostname) { + public Builder hostname(String hostname) { this.hostname = Preconditions.checkNotNull(hostname, "hostname"); return this; } - @NonNull - public Builder gameVersion(@NonNull String gameVersion) { + public Builder gameVersion(String gameVersion) { this.gameVersion = Preconditions.checkNotNull(gameVersion, "gameVersion"); return this; } - @NonNull - public Builder map(@NonNull String map) { + public Builder map(String map) { this.map = Preconditions.checkNotNull(map, "map"); return this; } - @NonNull public Builder currentPlayers(int currentPlayers) { Preconditions.checkArgument(currentPlayers >= 0, "currentPlayers cannot be negative"); this.currentPlayers = currentPlayers; return this; } - @NonNull public Builder maxPlayers(int maxPlayers) { Preconditions.checkArgument(maxPlayers >= 0, "maxPlayers cannot be negative"); this.maxPlayers = maxPlayers; return this; } - @NonNull - public Builder proxyHost(@NonNull String proxyHost) { + public Builder proxyHost(String proxyHost) { this.proxyHost = Preconditions.checkNotNull(proxyHost, "proxyHost"); return this; } - @NonNull public Builder proxyPort(int proxyPort) { Preconditions.checkArgument(proxyPort >= 1 && proxyPort <= 65535, "proxyPort must be between 1-65535"); this.proxyPort = proxyPort; return this; } - @NonNull - public Builder players(@NonNull Collection players) { + public Builder players(Collection players) { this.players.addAll(Preconditions.checkNotNull(players, "players")); return this; } - @NonNull - public Builder players(@NonNull String... players) { + public Builder players(String... players) { this.players.addAll(Arrays.asList(Preconditions.checkNotNull(players, "players"))); return this; } - @NonNull public Builder clearPlayers() { this.players.clear(); return this; } - @NonNull - public Builder proxyVersion(@NonNull String proxyVersion) { + public Builder proxyVersion(String proxyVersion) { this.proxyVersion = Preconditions.checkNotNull(proxyVersion, "proxyVersion"); return this; } - @NonNull - public Builder plugins(@NonNull Collection plugins) { + public Builder plugins(Collection plugins) { this.plugins.addAll(Preconditions.checkNotNull(plugins, "plugins")); return this; } - @NonNull - public Builder plugins(@NonNull PluginInformation... plugins) { + public Builder plugins(PluginInformation... plugins) { this.plugins.addAll(Arrays.asList(Preconditions.checkNotNull(plugins, "plugins"))); return this; } - @NonNull public Builder clearPlugins() { this.plugins.clear(); return this; @@ -263,18 +251,17 @@ public final class QueryResponse { * Builds new {@link QueryResponse} with supplied data * @return response */ - @NonNull public QueryResponse build() { return new QueryResponse( - hostname, - gameVersion, - map, + Preconditions.checkNotNull(hostname, "hostname"), + Preconditions.checkNotNull(gameVersion, "gameVersion"), + Preconditions.checkNotNull(map, "map"), currentPlayers, maxPlayers, - proxyHost, + Preconditions.checkNotNull(proxyHost, "proxyHost"), proxyPort, ImmutableList.copyOf(players), - proxyVersion, + Preconditions.checkNotNull(proxyVersion, "proxyVersion"), ImmutableList.copyOf(plugins) ); } @@ -287,17 +274,16 @@ public final class QueryResponse { private String name; private String version; - public PluginInformation(@NonNull String name, @Nullable String version) { - this.name = name; - this.version = version; + public PluginInformation(String name, String version) { + this.name = Preconditions.checkNotNull(name, "name"); + this.version = Preconditions.checkNotNull(version, "version"); } - @NonNull public String getName() { return name; } - public void setName(@NonNull String name) { + public void setName(String name) { this.name = name; } @@ -310,8 +296,7 @@ public final class QueryResponse { return version; } - @NonNull - public static PluginInformation of(@NonNull String name, @Nullable String version) { + public static PluginInformation of(String name, @Nullable String version) { return new PluginInformation(name, version); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java index 8710dd94c..e9a6a016e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/GS4QueryHandler.java @@ -16,6 +16,7 @@ import io.netty.channel.socket.DatagramPacket; import net.kyori.text.serializer.ComponentSerializers; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import java.net.InetAddress; import java.nio.charset.StandardCharsets; @@ -56,6 +57,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler .expireAfterWrite(30, TimeUnit.SECONDS) .build(); + @MonotonicNonNull private volatile List pluginInformationList = null; private final VelocityServer server;