Apply new rules against var and change #isStable to #isRelease

This commit is contained in:
masmc05 2024-05-01 22:14:51 +03:00
parent 7b98d0d28a
commit a505bb32b2
2 changed files with 17 additions and 15 deletions

View File

@ -6,7 +6,7 @@ Subject: [PATCH] Add paper version util class
diff --git a/src/main/java/io/papermc/paper/util/ServerInfo.java b/src/main/java/io/papermc/paper/util/ServerInfo.java
new file mode 100644
index 0000000000000000000000000000000000000000..cf39052c7d9f152313762e928fb49c5e3cd22dbc
index 0000000000000000000000000000000000000000..931c6b704257b8baac7674c101d04ad7216d84e2
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/ServerInfo.java
@@ -0,0 +1,98 @@
@ -54,10 +54,10 @@ index 0000000000000000000000000000000000000000..cf39052c7d9f152313762e928fb49c5e
+ /**
+ * Returns true if the server is a minecraft release version,
+ * false is it's a snapshot, pre-release, etc
+ * @return if the server is stable
+ * @return if the server is on a release version
+ */
+ public static boolean isStable() {
+ return provider.isStable();
+ public static boolean isRelease() {
+ return provider.isRelease();
+ }
+
+ /**
@ -110,7 +110,7 @@ index 0000000000000000000000000000000000000000..cf39052c7d9f152313762e928fb49c5e
+}
diff --git a/src/main/java/io/papermc/paper/util/ServerInfoProvider.java b/src/main/java/io/papermc/paper/util/ServerInfoProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..cee83c849668c79d0aca1e4e2b38698b67f5e948
index 0000000000000000000000000000000000000000..a692c159d82f3233f8211d5b37d1c3edff775088
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/ServerInfoProvider.java
@@ -0,0 +1,72 @@
@ -152,9 +152,9 @@ index 0000000000000000000000000000000000000000..cee83c849668c79d0aca1e4e2b38698b
+
+ /**
+ * Returns true if the server is a release version, false otherwise
+ * @return if the server is stable
+ * @return if the server is on a release version
+ */
+ boolean isStable();
+ boolean isRelease();
+
+ /**
+ * Checks if the server runs exactly the specified version

View File

@ -6,14 +6,16 @@ Subject: [PATCH] Add paper version util class
diff --git a/src/main/java/io/papermc/paper/util/misc/ServerInfoProviderImpl.java b/src/main/java/io/papermc/paper/util/misc/ServerInfoProviderImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..40ea612034c21fc4abc95cc4dcd7439b56fd9033
index 0000000000000000000000000000000000000000..3c0de7f103c6e733f4c3353da465634dfdae9934
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/misc/ServerInfoProviderImpl.java
@@ -0,0 +1,194 @@
@@ -0,0 +1,196 @@
+package io.papermc.paper.util.misc;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+import com.mojang.logging.LogUtils;
+import io.papermc.paper.util.ServerInfoProvider;
@ -81,7 +83,7 @@ index 0000000000000000000000000000000000000000..40ea612034c21fc4abc95cc4dcd7439b
+ }
+
+ @Override
+ public boolean isStable() {
+ public boolean isRelease() {
+ return SharedConstants.getCurrentVersion().isStable();
+ }
+
@ -168,9 +170,9 @@ index 0000000000000000000000000000000000000000..40ea612034c21fc4abc95cc4dcd7439b
+ .uri(URI.create(manifestURL))
+ .build();
+ HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ var parsed = JsonParser.parseString(response.body());
+ var versionArray = parsed.getAsJsonObject().getAsJsonArray("versions");
+ for (var version : versionArray) {
+ JsonElement parsed = JsonParser.parseString(response.body());
+ JsonArray versionArray = parsed.getAsJsonObject().getAsJsonArray("versions");
+ for (JsonElement version : versionArray) {
+ versionList.add(version.getAsJsonObject().get("id").getAsString());
+ }
+ } catch (IOException | InterruptedException e) {
@ -194,12 +196,12 @@ index 0000000000000000000000000000000000000000..40ea612034c21fc4abc95cc4dcd7439b
+ if (version.length == 0) {
+ return true;
+ }
+ var builder = new StringBuilder();
+ StringBuilder builder = new StringBuilder();
+ builder.append(version[0]);
+ for (int i = 1; i < version.length; i++) {
+ builder.append('.').append(version[i]);
+ }
+ var versionString = builder.toString();
+ String versionString = builder.toString();
+ return this.versionList.join().indexOf(versionString) > this.versionList.join().indexOf(this.id);
+ }
+ }