Begin switching to JSpecify annotations (#11448)
* Begin switching to JSpecify annotations * more * fixes
This commit is contained in:
parent
6d7a438fad
commit
f9c7f2a5c1
66 changed files with 750 additions and 920 deletions
|
@ -6,25 +6,25 @@ Subject: [PATCH] Add GS4 Query event
|
|||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/event/server/GS4QueryEvent.java b/src/main/java/com/destroystokyo/paper/event/server/GS4QueryEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097291978a6
|
||||
index 0000000000000000000000000000000000000000..5a8813c80e56d17ccaa35a7eef2f6bd70c7a3d96
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/event/server/GS4QueryEvent.java
|
||||
@@ -0,0 +1,424 @@
|
||||
@@ -0,0 +1,395 @@
|
||||
+package com.destroystokyo.paper.event.server;
|
||||
+
|
||||
+import com.google.common.base.Preconditions;
|
||||
+import com.google.common.collect.ImmutableList;
|
||||
+import org.bukkit.Server;
|
||||
+import org.bukkit.event.Event;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.net.InetAddress;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.Collection;
|
||||
+import java.util.List;
|
||||
+import org.bukkit.Server;
|
||||
+import org.bukkit.event.Event;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+/**
|
||||
+ * This event is fired if server is getting queried over GS4 Query protocol.
|
||||
|
@ -33,6 +33,7 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @author Mark Vainomaa
|
||||
+ */
|
||||
+@NullMarked
|
||||
+public final class GS4QueryEvent extends Event {
|
||||
+
|
||||
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
@ -42,7 +43,7 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ private QueryResponse response;
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public GS4QueryEvent(@NotNull QueryType queryType, @NotNull InetAddress querierAddress, @NotNull QueryResponse response) {
|
||||
+ public GS4QueryEvent(final QueryType queryType, final InetAddress querierAddress, final QueryResponse response) {
|
||||
+ super(true); // should always be called async
|
||||
+ this.queryType = queryType;
|
||||
+ this.querierAddress = querierAddress;
|
||||
|
@ -54,7 +55,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return query type
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public QueryType getQueryType() {
|
||||
+ return this.queryType;
|
||||
+ }
|
||||
|
@ -64,7 +64,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return querier address
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public InetAddress getQuerierAddress() {
|
||||
+ return this.querierAddress;
|
||||
+ }
|
||||
|
@ -74,7 +73,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return query response
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public QueryResponse getResponse() {
|
||||
+ return this.response;
|
||||
+ }
|
||||
|
@ -84,17 +82,15 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @param response query response
|
||||
+ */
|
||||
+ public void setResponse(@NotNull QueryResponse response) {
|
||||
+ public void setResponse(final QueryResponse response) {
|
||||
+ this.response = Preconditions.checkNotNull(response, "response");
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return HANDLER_LIST;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return HANDLER_LIST;
|
||||
+ }
|
||||
|
@ -115,7 +111,7 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ FULL
|
||||
+ }
|
||||
+
|
||||
+ public final static class QueryResponse {
|
||||
+ public static final class QueryResponse {
|
||||
+
|
||||
+ private final String motd;
|
||||
+ private final String gameVersion;
|
||||
|
@ -128,7 +124,7 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ private final String serverVersion;
|
||||
+ private final Collection<PluginInformation> plugins;
|
||||
+
|
||||
+ private QueryResponse(String motd, String gameVersion, String map, int currentPlayers, int maxPlayers, String hostname, int port, Collection<String> players, String serverVersion, Collection<PluginInformation> plugins) {
|
||||
+ private QueryResponse(final String motd, final String gameVersion, final String map, final int currentPlayers, final int maxPlayers, final String hostname, final int port, final Collection<String> players, final String serverVersion, final Collection<PluginInformation> plugins) {
|
||||
+ this.motd = motd;
|
||||
+ this.gameVersion = gameVersion;
|
||||
+ this.map = map;
|
||||
|
@ -142,21 +138,19 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Get motd which will be used to reply to the query. By default it is {@link Server#getMotd()}.
|
||||
+ * Get motd which will be used to reply to the query. By default, it is {@link Server#getMotd()}.
|
||||
+ *
|
||||
+ * @return motd
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public String getMotd() {
|
||||
+ return this.motd;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Get game version which will be used to reply to the query. By default supported Minecraft versions range is sent.
|
||||
+ * Get game version which will be used to reply to the query. By default, supported Minecraft versions range is sent.
|
||||
+ *
|
||||
+ * @return game version
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public String getGameVersion() {
|
||||
+ return this.gameVersion;
|
||||
+ }
|
||||
|
@ -166,7 +160,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return map name
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public String getMap() {
|
||||
+ return this.map;
|
||||
+ }
|
||||
|
@ -194,7 +187,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return server hostname
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public String getHostname() {
|
||||
+ return this.hostname;
|
||||
+ }
|
||||
|
@ -213,7 +205,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return collection of players
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public Collection<String> getPlayers() {
|
||||
+ return this.players;
|
||||
+ }
|
||||
|
@ -223,7 +214,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return server software
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public String getServerVersion() {
|
||||
+ return this.serverVersion;
|
||||
+ }
|
||||
|
@ -233,7 +223,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return collection of plugins
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public Collection<PluginInformation> getPlugins() {
|
||||
+ return this.plugins;
|
||||
+ }
|
||||
|
@ -243,19 +232,18 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return {@link QueryResponse} builder
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public Builder toBuilder() {
|
||||
+ return QueryResponse.builder()
|
||||
+ .motd(getMotd())
|
||||
+ .gameVersion(getGameVersion())
|
||||
+ .map(getMap())
|
||||
+ .currentPlayers(getCurrentPlayers())
|
||||
+ .maxPlayers(getMaxPlayers())
|
||||
+ .hostname(getHostname())
|
||||
+ .port(getPort())
|
||||
+ .players(getPlayers())
|
||||
+ .serverVersion(getServerVersion())
|
||||
+ .plugins(getPlugins());
|
||||
+ .motd(this.getMotd())
|
||||
+ .gameVersion(this.getGameVersion())
|
||||
+ .map(this.getMap())
|
||||
+ .currentPlayers(this.getCurrentPlayers())
|
||||
+ .maxPlayers(this.getMaxPlayers())
|
||||
+ .hostname(this.getHostname())
|
||||
+ .port(this.getPort())
|
||||
+ .players(this.getPlayers())
|
||||
+ .serverVersion(this.getServerVersion())
|
||||
+ .plugins(this.getPlugins());
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -263,7 +251,6 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return {@link QueryResponse} builder
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public static Builder builder() {
|
||||
+ return new Builder();
|
||||
+ }
|
||||
|
@ -272,11 +259,12 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ * A builder for {@link QueryResponse} objects.
|
||||
+ */
|
||||
+ public static final class Builder {
|
||||
+ private String motd;
|
||||
+ private String gameVersion;
|
||||
+ private String map;
|
||||
+ private String hostname;
|
||||
+ private String serverVersion;
|
||||
+
|
||||
+ private @MonotonicNonNull String motd;
|
||||
+ private @MonotonicNonNull String gameVersion;
|
||||
+ private @MonotonicNonNull String map;
|
||||
+ private @MonotonicNonNull String hostname;
|
||||
+ private @MonotonicNonNull String serverVersion;
|
||||
+
|
||||
+ private int currentPlayers;
|
||||
+ private int maxPlayers;
|
||||
|
@ -285,90 +273,77 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ private final List<String> players = new ArrayList<>();
|
||||
+ private final List<PluginInformation> plugins = new ArrayList<>();
|
||||
+
|
||||
+ private Builder() {}
|
||||
+ private Builder() {
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder motd(@NotNull String motd) {
|
||||
+ public Builder motd(final String motd) {
|
||||
+ this.motd = Preconditions.checkNotNull(motd, "motd");
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder gameVersion(@NotNull String gameVersion) {
|
||||
+ public Builder gameVersion(final String gameVersion) {
|
||||
+ this.gameVersion = Preconditions.checkNotNull(gameVersion, "gameVersion");
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder map(@NotNull String map) {
|
||||
+ public Builder map(final String map) {
|
||||
+ this.map = Preconditions.checkNotNull(map, "map");
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder currentPlayers(int currentPlayers) {
|
||||
+ public Builder currentPlayers(final int currentPlayers) {
|
||||
+ Preconditions.checkArgument(currentPlayers >= 0, "currentPlayers cannot be negative");
|
||||
+ this.currentPlayers = currentPlayers;
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder maxPlayers(int maxPlayers) {
|
||||
+ public Builder maxPlayers(final int maxPlayers) {
|
||||
+ Preconditions.checkArgument(maxPlayers >= 0, "maxPlayers cannot be negative");
|
||||
+ this.maxPlayers = maxPlayers;
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder hostname(@NotNull String hostname) {
|
||||
+ public Builder hostname(final String hostname) {
|
||||
+ this.hostname = Preconditions.checkNotNull(hostname, "hostname");
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder port(int port) {
|
||||
+ public Builder port(final int port) {
|
||||
+ Preconditions.checkArgument(port >= 1 && port <= 65535, "port must be between 1-65535");
|
||||
+ this.port = port;
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder players(@NotNull Collection<String> players) {
|
||||
+ public Builder players(final Collection<String> players) {
|
||||
+ this.players.addAll(Preconditions.checkNotNull(players, "players"));
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder players(@NotNull String... players) {
|
||||
+ public Builder players(final String... players) {
|
||||
+ this.players.addAll(Arrays.asList(Preconditions.checkNotNull(players, "players")));
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder clearPlayers() {
|
||||
+ this.players.clear();
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder serverVersion(@NotNull String serverVersion) {
|
||||
+ public Builder serverVersion(final String serverVersion) {
|
||||
+ this.serverVersion = Preconditions.checkNotNull(serverVersion, "serverVersion");
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder plugins(@NotNull Collection<PluginInformation> plugins) {
|
||||
+ public Builder plugins(final Collection<PluginInformation> plugins) {
|
||||
+ this.plugins.addAll(Preconditions.checkNotNull(plugins, "plugins"));
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder plugins(@NotNull PluginInformation... plugins) {
|
||||
+ public Builder plugins(final PluginInformation... plugins) {
|
||||
+ this.plugins.addAll(Arrays.asList(Preconditions.checkNotNull(plugins, "plugins")));
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public Builder clearPlugins() {
|
||||
+ this.plugins.clear();
|
||||
+ return this;
|
||||
|
@ -379,19 +354,18 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ *
|
||||
+ * @return response
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public QueryResponse build() {
|
||||
+ return new QueryResponse(
|
||||
+ Preconditions.checkNotNull(motd, "motd"),
|
||||
+ Preconditions.checkNotNull(gameVersion, "gameVersion"),
|
||||
+ Preconditions.checkNotNull(map, "map"),
|
||||
+ currentPlayers,
|
||||
+ maxPlayers,
|
||||
+ Preconditions.checkNotNull(hostname, "hostname"),
|
||||
+ port,
|
||||
+ ImmutableList.copyOf(players),
|
||||
+ Preconditions.checkNotNull(serverVersion, "serverVersion"),
|
||||
+ ImmutableList.copyOf(plugins)
|
||||
+ Preconditions.checkNotNull(this.motd, "motd"),
|
||||
+ Preconditions.checkNotNull(this.gameVersion, "gameVersion"),
|
||||
+ Preconditions.checkNotNull(this.map, "map"),
|
||||
+ this.currentPlayers,
|
||||
+ this.maxPlayers,
|
||||
+ Preconditions.checkNotNull(this.hostname, "hostname"),
|
||||
+ this.port,
|
||||
+ ImmutableList.copyOf(this.players),
|
||||
+ Preconditions.checkNotNull(this.serverVersion, "serverVersion"),
|
||||
+ ImmutableList.copyOf(this.plugins)
|
||||
+ );
|
||||
+ }
|
||||
+ }
|
||||
|
@ -404,31 +378,28 @@ index 0000000000000000000000000000000000000000..8edc33bde29e967cec488d0f5e2f1097
|
|||
+ private String name;
|
||||
+ private String version;
|
||||
+
|
||||
+ public PluginInformation(@NotNull String name, @NotNull String version) {
|
||||
+ public PluginInformation(final String name, final String version) {
|
||||
+ this.name = Preconditions.checkNotNull(name, "name");
|
||||
+ this.version = Preconditions.checkNotNull(version, "version");
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public String getName() {
|
||||
+ return this.name;
|
||||
+ }
|
||||
+
|
||||
+ public void setName(@NotNull String name) {
|
||||
+ public void setName(final String name) {
|
||||
+ this.name = name;
|
||||
+ }
|
||||
+
|
||||
+ public void setVersion(@NotNull String version) {
|
||||
+ public void setVersion(final String version) {
|
||||
+ this.version = version;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public String getVersion() {
|
||||
+ return this.version;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public static PluginInformation of(@NotNull String name, @NotNull String version) {
|
||||
+ public static PluginInformation of(final String name, final String version) {
|
||||
+ return new PluginInformation(name, version);
|
||||
+ }
|
||||
+ }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue