Skip to content

Commit 534a893

Browse files
committed
feat: re-add paper api but compile for java 8
1 parent 1176318 commit 534a893

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

build.gradle.kts

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ version = "2.7.2"
88

99
repositories {
1010
mavenCentral()
11-
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
11+
maven("https://papermc.io/repo/repository/maven-public/")
1212
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
1313
}
1414

1515
dependencies {
16-
compileOnly("org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT")
16+
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
1717
compileOnly("me.clip:placeholderapi:2.11.3")
1818
}
1919

@@ -23,6 +23,10 @@ tasks {
2323
attributes["Implementation-Title"] = "server"
2424
attributes["Implementation-Version"] = project.version
2525
}
26+
}
27+
28+
java {
29+
disableAutoTargetJvm()
2630
targetCompatibility = JavaVersion.VERSION_1_8
2731
sourceCompatibility = JavaVersion.VERSION_1_8
2832
}

src/main/java/at/helpch/placeholderapi/expansion/server/util/ServerUtil.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final class ServerUtil {
1717
// TPS stuff
1818
private static final Object craftServer;
1919
private static final Field tpsField;
20-
private static Method getTpsMethod; // Paper and its forks have Bukkit#getTPS
20+
private static boolean hasTpsMethod; // Paper and its forks have Bukkit#getTps
2121
// ----
2222

2323
private static final String variant;
@@ -86,7 +86,8 @@ private static Object getCraftServer() {
8686

8787
private static Field getTpsHandler() {
8888
try {
89-
getTpsMethod = Bukkit.class.getMethod("getTPS");
89+
Bukkit.class.getMethod("getTPS");
90+
hasTpsMethod = true;
9091
return null;
9192
} catch (NoSuchMethodException ignored) { }
9293

@@ -148,12 +149,8 @@ public static String getBuild() {
148149
}
149150

150151
public static double[] getTps() {
151-
if (getTpsMethod != null) {
152-
try {
153-
return (double[]) getTpsMethod.invoke(null);
154-
} catch (IllegalAccessException | InvocationTargetException ignored) {
155-
return new double[]{0, 0, 0};
156-
}
152+
if (hasTpsMethod) {
153+
return Bukkit.getTPS();
157154
}
158155

159156
if (craftServer == null || tpsField == null) {
@@ -183,8 +180,9 @@ private static String getVariant0() {
183180

184181
private static String getBuild0() {
185182
OptionalInt buildNumber = ServerBuildInfo.buildInfo().buildNumber();
186-
if (buildNumber.isEmpty())
183+
if (!buildNumber.isPresent()) {
187184
return "Unknown";
185+
}
188186

189187
return String.valueOf(buildNumber.getAsInt());
190188
}

src/main/java/at/helpch/placeholderapi/expansion/server/util/VersionHelper.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ private static String getMinecraftVersion() {
9696
if (IS_PAPER) {
9797
try {
9898
// Paper method from 2020 - returns the version like 1.20.1
99-
final Method method = Bukkit.class.getDeclaredMethod("getMinecraftVersion");
100-
return (String) method.invoke(Bukkit.getServer());
101-
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
99+
return Bukkit.getMinecraftVersion();
100+
} catch (NoSuchMethodError ignored) {
101+
// The version is formatted as 1.20.1-R0.1-SNAPSHOT
102+
return Bukkit.getBukkitVersion().split("-")[0];
103+
}
102104
}
103105

104106
// The version is formatted as 1.20.1-R0.1-SNAPSHOT

0 commit comments

Comments
 (0)