diff --git a/patches/api/0463-Add-paper-version-util-class.patch b/patches/api/0463-Add-paper-version-util-class.patch index da69f4a694..6002781af0 100644 --- a/patches/api/0463-Add-paper-version-util-class.patch +++ b/patches/api/0463-Add-paper-version-util-class.patch @@ -6,14 +6,16 @@ Subject: [PATCH] Add paper version util class diff --git a/src/main/java/io/papermc/paper/util/PaperServerInfo.java b/src/main/java/io/papermc/paper/util/PaperServerInfo.java new file mode 100644 -index 0000000000000000000000000000000000000000..b882b328e87cffa06c32fa6618afeab8d08ab0a1 +index 0000000000000000000000000000000000000000..36d71c598529c77ee0c1012cabfa0ebd4a1692db --- /dev/null +++ b/src/main/java/io/papermc/paper/util/PaperServerInfo.java -@@ -0,0 +1,73 @@ +@@ -0,0 +1,98 @@ +package io.papermc.paper.util; + ++import net.kyori.adventure.key.Key; +import net.kyori.adventure.util.Services; +import org.bukkit.UnsafeValues; ++import org.jetbrains.annotations.NotNull; + +/** + * A utility class to get information about the server @@ -24,11 +26,12 @@ index 0000000000000000000000000000000000000000..b882b328e87cffa06c32fa6618afeab8 + throw new UnsupportedOperationException("This class cannot be instantiated"); + } + private static final PaperServerInfoProvider provider = Services.service(PaperServerInfoProvider.class).orElseThrow(); ++ + /** + * Get the version of the server -+ * @return the version of the server (e.g. "1.20.4") ++ * @return the version of the server (e.g. "1.20.4", "1.20.2 Pre-release 2", "23w31a") + */ -+ public static String version() { ++ public static @NotNull String version() { + return provider.version(); + } + @@ -36,7 +39,7 @@ index 0000000000000000000000000000000000000000..b882b328e87cffa06c32fa6618afeab8 + * Get the api version of the server + * @return the api version of the server (e.g. "1.20.4-R0.1-SNAPSHOT") + */ -+ public static String apiVersion() { ++ public static @NotNull String apiVersion() { + return provider.apiVersion(); + } + @@ -44,53 +47,76 @@ index 0000000000000000000000000000000000000000..b882b328e87cffa06c32fa6618afeab8 + * Get the name of the server + * @return the name of the server (e.g. "Paper") + */ -+ public static String serverName() { ++ public static @NotNull String serverName() { + return provider.serverName(); + } ++ ++ /** ++ * 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 ++ */ ++ public static boolean isStable() { ++ return provider.isStable(); ++ } ++ + /** + * Returns the unsafe values for the server for unsafe version values + * @return the unsafe values for the server + */ + @Deprecated ++ @NotNull + public static UnsafeValues unsafe() { + return provider.unsafe(); + } + + /** + * Checks if the server runs exactly the specified version ++ *
++ * Note: Will always return false on non release versions + * @param version the version to check (e.g. 1, 20, 4) + * @return true if the server runs exactly the specified version + */ -+ public static boolean is(int... version) { ++ public static boolean is(int @NotNull... version) { + return provider.is(version); + } + + /** -+ * Checks if the server runs at least the specified version ++ * Checks if the server runs exactly the specified version ++ * @param version the version to check (e.g. "1.20.4", "1.20.2 Pre-release 2", "1.20.2-pre2", "23w31a") ++ * @return true if the server runs exactly the specified version ++ */ ++ public static boolean is(@NotNull String version) { ++ return provider.is(version); ++ } ++ ++ /** ++ * Checks if the server runs a version which is after this version or the same + * @param version the version to check (e.g. 1, 20, 4) + * @return true if the server runs on this version or a newer version + */ -+ public static boolean isAtLeast(int... version) { ++ public static boolean isAtLeast(int @NotNull... version) { + return provider.isAtLeast(version); + } + + /** -+ * Checks if the server implements the specified API -+ * @param api the API to check (e.g. "Folia"), case insensitive -+ * @return true if the server implements the specified API ++ * Checks if the server is implementing the specified API ++ * @param api the API to check (e.g. "papermc:folia") ++ * @return true if the server is implementing the specified API + */ -+ public static boolean implement(String api) { -+ return provider.implement(api); ++ public static boolean isImplementing(@NotNull Key api) { ++ return provider.isImplementing(api); + } +} diff --git a/src/main/java/io/papermc/paper/util/PaperServerInfoProvider.java b/src/main/java/io/papermc/paper/util/PaperServerInfoProvider.java new file mode 100644 -index 0000000000000000000000000000000000000000..fbb138623f93fd6e8fe534cf1cf339657f4b5418 +index 0000000000000000000000000000000000000000..79ce6cfafc9d05b696c7bab1d84c8a5455acf162 --- /dev/null +++ b/src/main/java/io/papermc/paper/util/PaperServerInfoProvider.java -@@ -0,0 +1,56 @@ +@@ -0,0 +1,72 @@ +package io.papermc.paper.util; + ++import net.kyori.adventure.key.Key; +import org.bukkit.UnsafeValues; +import org.jetbrains.annotations.NotNull; + @@ -100,7 +126,7 @@ index 0000000000000000000000000000000000000000..fbb138623f93fd6e8fe534cf1cf33965 +public interface PaperServerInfoProvider { + /** + * Get the version of the server -+ * @return the version of the server (e.g. "1.20.4") ++ * @return the version of the server (e.g. "1.20.4", "1.20.2 Pre-release 2", "23w31a") + */ + @NotNull String version(); + @@ -125,23 +151,38 @@ index 0000000000000000000000000000000000000000..fbb138623f93fd6e8fe534cf1cf33965 + UnsafeValues unsafe(); + + /** ++ * Returns true if the server is a release version, false otherwise ++ * @return if the server is stable ++ */ ++ boolean isStable(); ++ ++ /** + * Checks if the server runs exactly the specified version ++ *
++ * Note: Will always return false on non release versions
+ * @param version the version to check (e.g. 1, 20, 4)
+ * @return true if the server runs exactly the specified version
+ */
+ boolean is(int @NotNull... version);
+
+ /**
-+ * Checks if the server runs at least the specified version
++ * Checks if the server runs exactly the specified version
++ * @param version the version to check (e.g. "1.20.4", "1.20.2 Pre-release 2", "1.20.2-pre2", "23w31a")
++ * @return true if the server runs exactly the specified version
++ */
++ boolean is(@NotNull String version);
++
++ /**
++ * Checks if the server runs a version which is after this version or the same
+ * @param version the version to check (e.g. 1, 20, 4)
+ * @return true if the server runs on this version or a newer version
+ */
+ boolean isAtLeast(int @NotNull... version);
+
+ /**
-+ * Checks if the server implements the specified API
-+ * @param api the API to check (e.g. "Folia"), case insensitive
-+ * @return true if the server implements the specified API
++ * Checks if the server is implementing the specified API
++ * @param api the API to check (e.g. "papermc:folia")
++ * @return true if the server is implementing the specified API
+ */
-+ boolean implement(@NotNull String api);
++ boolean isImplementing(@NotNull Key api);
+}
diff --git a/patches/server/1046-Add-paper-version-util-class.patch b/patches/server/1046-Add-paper-version-util-class.patch
index 516141c034..c679870553 100644
--- a/patches/server/1046-Add-paper-version-util-class.patch
+++ b/patches/server/1046-Add-paper-version-util-class.patch
@@ -6,35 +6,59 @@ Subject: [PATCH] Add paper version util class
diff --git a/src/main/java/io/papermc/paper/util/misc/PaperServerInfoProviderImpl.java b/src/main/java/io/papermc/paper/util/misc/PaperServerInfoProviderImpl.java
new file mode 100644
-index 0000000000000000000000000000000000000000..4a105d428778b95232e8acb1bb3d09a6c4e94477
+index 0000000000000000000000000000000000000000..d85ba01b83c2f29b1b56775d0f51f6b1d182252c
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/misc/PaperServerInfoProviderImpl.java
-@@ -0,0 +1,83 @@
+@@ -0,0 +1,195 @@
+package io.papermc.paper.util.misc;
+
+import com.google.common.base.Preconditions;
++import com.google.common.collect.ImmutableList;
++import com.google.gson.Gson;
++import com.google.gson.JsonParser;
++import com.google.gson.stream.JsonReader;
++import com.mojang.logging.LogUtils;
+import io.papermc.paper.util.PaperServerInfoProvider;
++import net.kyori.adventure.key.Key;
++import net.kyori.adventure.key.KeyPattern;
+import net.minecraft.SharedConstants;
+import org.bukkit.UnsafeValues;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+import org.bukkit.craftbukkit.util.Versioning;
+import org.jetbrains.annotations.NotNull;
++import org.slf4j.Logger;
++import java.io.IOException;
++import java.net.URI;
++import java.net.http.HttpClient;
++import java.net.http.HttpRequest;
++import java.net.http.HttpResponse;
++import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
++import java.util.List;
+import java.util.Locale;
++import java.util.Objects;
++import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Stream;
+
+public class PaperServerInfoProviderImpl implements PaperServerInfoProvider {
+ private final String bukkitVersion = Versioning.getBukkitVersion();
-+ private final Set