From 0c97efbf08987e2d28003dc2a33b987686b1ccce Mon Sep 17 00:00:00 2001 From: iGabyTM Date: Sun, 26 May 2024 17:59:21 +0300 Subject: [PATCH] feat: use java 8 and spigot api SADLY --- build.gradle.kts | 10 ++++++++-- .../expansion/server/util/ServerUtil.java | 20 ++++++++++++------- .../expansion/server/util/VersionHelper.java | 20 +++++++++++-------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d92f4c3..bd6fefe 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,16 +7,22 @@ group = "at.helpch.placeholderapi.expansion" version = "2.7.2" repositories { - maven("https://papermc.io/repo/repository/maven-public/") + mavenCentral() + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") } dependencies { - compileOnly("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT") compileOnly("me.clip:placeholderapi:2.11.3") } tasks { + java { + targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 + } + shadowJar { archiveFileName.set("PAPI-Expansion-Server-${project.version}.jar") } diff --git a/src/main/java/at/helpch/placeholderapi/expansion/server/util/ServerUtil.java b/src/main/java/at/helpch/placeholderapi/expansion/server/util/ServerUtil.java index 4579938..d9b1e2d 100644 --- a/src/main/java/at/helpch/placeholderapi/expansion/server/util/ServerUtil.java +++ b/src/main/java/at/helpch/placeholderapi/expansion/server/util/ServerUtil.java @@ -4,19 +4,22 @@ 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.TreeMap; public final class ServerUtil { private static final Map variants = new TreeMap<>(); - private static final String variant; - private static final String build; // TPS stuff private static final Object craftServer; private static final Field tpsField; - private static boolean hasTpsMethod; // Paper and its forks have Bukkit#getTps + private static Method getTpsMethod; // Paper and its forks have Bukkit#getTPS + // ---- + + private static final String variant; + private static final String build; static { variants.put("net.pl3x.purpur.PurpurConfig", "Purpur"); @@ -78,8 +81,7 @@ public final class ServerUtil { private static Field getTpsHandler() { try { - Bukkit.class.getMethod("getTPS"); - hasTpsMethod = true; + getTpsMethod = Bukkit.class.getMethod("getTPS"); return null; } catch (NoSuchMethodException ignored) { } @@ -138,8 +140,12 @@ public final class ServerUtil { } public static double[] getTps() { - if (hasTpsMethod) { - return Bukkit.getTPS(); + if (getTpsMethod != null) { + try { + return (double[]) getTpsMethod.invoke(null); + } catch (IllegalAccessException | InvocationTargetException ignored) { + return new double[]{0, 0, 0}; + } } if (craftServer == null || tpsField == null) { diff --git a/src/main/java/at/helpch/placeholderapi/expansion/server/util/VersionHelper.java b/src/main/java/at/helpch/placeholderapi/expansion/server/util/VersionHelper.java index b8caee4..93c9913 100644 --- a/src/main/java/at/helpch/placeholderapi/expansion/server/util/VersionHelper.java +++ b/src/main/java/at/helpch/placeholderapi/expansion/server/util/VersionHelper.java @@ -27,6 +27,8 @@ import com.google.common.primitives.Ints; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -39,11 +41,10 @@ public final class VersionHelper { private static final int V1_17 = 1_17_0; + private static final boolean IS_PAPER = checkPaper(); public static final String MINECRAFT_VERSION = getMinecraftVersion(); private static final int CURRENT_VERSION = getCurrentVersion(); - private static final boolean IS_PAPER = checkPaper(); - public static final boolean IS_1_17_OR_HIGHER = CURRENT_VERSION >= V1_17; /** @@ -92,13 +93,16 @@ public final class VersionHelper { } private static String getMinecraftVersion() { - try { - // Paper method from 2020 - returns the version like 1.20.1 - return Bukkit.getMinecraftVersion(); - } catch (NoSuchMethodError ignored) { - // The version is formatted as 1.20.1-R0.1-SNAPSHOT - return Bukkit.getBukkitVersion().split("-")[0]; + if (IS_PAPER) { + try { + // Paper method from 2020 - returns the version like 1.20.1 + final Method method = Bukkit.class.getDeclaredMethod("getMinecraftVersion"); + return (String) method.invoke(Bukkit.getServer()); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } } + + // The version is formatted as 1.20.1-R0.1-SNAPSHOT + return Bukkit.getBukkitVersion().split("-")[0]; } public static String getNmsVersion() {