Merge branch 'master' into feature/use-java-8-and-spigot-api

# Conflicts:
#	build.gradle.kts
This commit is contained in:
iGabyTM committed 2024-09-15 13:42:20 +03:00
commit 0d73fb7e10
2 files changed
+30 -1

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
@@ -1,11 +1,13 @@
package at.helpch.placeholderapi.expansion.server.util;
import io.papermc.paper.ServerBuildInfo;
import org.bukkit.Bukkit;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.OptionalInt;
import java.util.TreeMap;
public final class ServerUtil {
@@ -35,6 +37,9 @@ public final class ServerUtil {
}
private static String findVariant() {
if (hasServerBuildInfo())
return getVariant0();
for (final Map.Entry<String, String> entry : variants.entrySet()) {
try {
Class.forName(entry.getKey());
@@ -99,6 +104,9 @@ public final class ServerUtil {
}
private static String findBuild() {
if (hasServerBuildInfo())
return getBuild0();
String[] buildParts = Bukkit.getVersion().split("-");
switch (getVariant().toLowerCase()) {
@@ -159,4 +167,25 @@ public final class ServerUtil {
}
}
// Available since recent 1.20.6 versions of Paper. Allows easier retrieval of certain info.
private static boolean hasServerBuildInfo() {
try {
Class.forName("io.papermc.paper.ServerBuildInfo");
return true;
} catch(ClassNotFoundException ignored) {
return false;
}
}
private static String getVariant0() {
return ServerBuildInfo.buildInfo().brandName();
}
private static String getBuild0() {
OptionalInt buildNumber = ServerBuildInfo.buildInfo().buildNumber();
if (buildNumber.isEmpty())
return "Unknown";
return String.valueOf(buildNumber.getAsInt());
}
}