From 78003bc53250ea50b7be9b747cb877ad1a14c08b Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 21 Oct 2021 21:03:00 +0200 Subject: [PATCH 1/8] Improve ServerUtils and TPS resolving --- pom.xml | 14 +- .../expansion/server/ServerExpansion.java | 95 +++------- .../papi/expansion/server/ServerUtils.java | 165 ++++++++++++++---- 3 files changed, 159 insertions(+), 115 deletions(-) diff --git a/pom.xml b/pom.xml index 64369ac..f9ad552 100644 --- a/pom.xml +++ b/pom.xml @@ -8,12 +8,8 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - sonatype - https://oss.sonatype.org/content/groups/public/ + paper-repo + https://papermc.io/repo/repository/maven-public/ placeholderapi @@ -23,9 +19,9 @@ - org.spigotmc - spigot-api - 1.17-R0.1-SNAPSHOT + io.papermc.paper + paper-api + 1.17.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java index 0bb844f..4f256fa 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java @@ -35,7 +35,6 @@ import org.jetbrains.annotations.NotNull; import java.lang.management.ManagementFactory; -import java.lang.reflect.Field; import java.text.SimpleDateFormat; import java.time.Duration; import java.time.temporal.ChronoUnit; @@ -44,16 +43,13 @@ import java.util.Map; import java.util.StringJoiner; import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class ServerExpansion extends PlaceholderExpansion implements Cacheable, Configurable { - + + private final ServerUtils serverUtils; + private final Map dateFormats = new HashMap<>(); private final Runtime runtime = Runtime.getRuntime(); - private Object craftServer; - private Field tps; - private String version; private final String variant; // config stuff @@ -70,20 +66,9 @@ public class ServerExpansion extends PlaceholderExpansion implements Cacheable, private final String VERSION = getClass().getPackage().getImplementationVersion(); public ServerExpansion() { - this.version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + this.serverUtils = new ServerUtils(); - try { - if (minecraftVersion() >= 17) { - craftServer = Class.forName("net.minecraft.server.MinecraftServer").getMethod("getServer").invoke(null); - } else { - craftServer = Class.forName("net.minecraft.server." + version + ".MinecraftServer").getMethod("getServer").invoke(null); - } - tps = craftServer.getClass().getField("recentTps"); - } catch (Exception e) { - e.printStackTrace(); - } - - this.variant = ServerUtils.getServerVariant(); + this.variant = serverUtils.getServerVariant(); } @Override @@ -97,9 +82,7 @@ public boolean canRegister() { @Override public void clear() { - craftServer = null; - tps = null; - version = null; + serverUtils.clear(); dateFormats.clear(); cache.invalidateAll(); @@ -146,12 +129,12 @@ public String onRequest(OfflinePlayer p, String identifier) { // Version placeholders case "version": - return ServerUtils.VERSION; + return serverUtils.getVersion(); case "build": - return ServerUtils.BUILD; + return serverUtils.getBuild(); case "version_build": case "version_full": - return ServerUtils.VERSION + '-' + ServerUtils.BUILD; + return serverUtils.getVersion() + '-' + serverUtils.getBuild(); // ----- // Ram placeholders @@ -296,7 +279,7 @@ public String onRequest(OfflinePlayer p, String identifier) { public String getTps(String arg) { if (arg == null || arg.isEmpty()) { StringBuilder sb = new StringBuilder(); - for (double t : tps()) { + for (double t : serverUtils.getTps()) { sb.append(getColoredTps(t)) .append(ChatColor.GRAY) .append(", "); @@ -306,26 +289,26 @@ public String getTps(String arg) { switch (arg) { case "1": case "one": - return String.valueOf(fix(tps()[0])); + return String.valueOf(fix(serverUtils.getTps()[0])); case "5": case "five": - return String.valueOf(fix(tps()[1])); + return String.valueOf(fix(serverUtils.getTps()[1])); case "15": case "fifteen": - return String.valueOf(tps()[2]); + return String.valueOf(serverUtils.getTps()[2]); case "1_colored": case "one_colored": - return getColoredTps(tps()[0]); + return getColoredTps(serverUtils.getTps()[0]); case "5_colored": case "five_colored": - return getColoredTps(tps()[1]); + return getColoredTps(serverUtils.getTps()[1]); case "15_colored": case "fifteen_colored": - return getColoredTps(tps()[2]); + return getColoredTps(serverUtils.getTps()[2]); case "percent": { final StringJoiner joiner = new StringJoiner(ChatColor.GRAY + ", "); - for (double t : tps()) { + for (double t : serverUtils.getTps()) { joiner.add(getColoredTpsPercent(t)); } @@ -333,22 +316,22 @@ public String getTps(String arg) { } case "1_percent": case "one_percent": - return getPercent(tps()[0]); + return getPercent(serverUtils.getTps()[0]); case "5_percent": case "five_percent": - return getPercent(tps()[1]); + return getPercent(serverUtils.getTps()[1]); case "15_percent": case "fifteen_percent": - return getPercent(tps()[2]); + return getPercent(serverUtils.getTps()[2]); case "1_percent_colored": case "one_percent_colored": - return getColoredTpsPercent(tps()[0]); + return getColoredTpsPercent(serverUtils.getTps()[0]); case "5_percent_colored": case "five_percent_colored": - return getColoredTpsPercent(tps()[1]); + return getColoredTpsPercent(serverUtils.getTps()[1]); case "15_percent_colored": case "fifteen_percent_colored": - return getColoredTpsPercent(tps()[2]); + return getColoredTpsPercent(serverUtils.getTps()[2]); } return null; } @@ -409,18 +392,6 @@ public static String formatTime(final Duration duration) { return builder.toString(); } - private double[] tps() { - if (version == null || craftServer == null || tps == null) { - return new double[] { 0, 0, 0 }; - } - try { - return ((double[]) tps.get(craftServer)); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return new double[] { 0, 0, 0 }; - } - private double fix(double tps) { return Math.min(Math.round(tps * 100.0) / 100.0, 20.0); } @@ -469,24 +440,4 @@ private String getPercent(double tps){ return Math.min(Math.round(100 / 20.0 * tps), 100.0) + "%"; } - /** - * Helper method to return the major version that the server is running. - * - * This is needed because in 1.17, NMS is no longer versioned. - * - * @return the major version of Minecraft the server is running - */ - public static int minecraftVersion() { - try { - final Matcher matcher = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)").matcher(Bukkit.getVersion()); - if (matcher.find()) { - return Integer.parseInt(matcher.toMatchResult().group(2), 10); - } else { - throw new IllegalArgumentException(String.format("No match found in '%s'", Bukkit.getVersion())); - } - } catch (final IllegalArgumentException ex) { - throw new RuntimeException("Failed to determine Minecraft version", ex); - } - } - } diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java index 685503e..ff038d7 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java @@ -1,51 +1,148 @@ package com.extendedclip.papi.expansion.server; +import me.clip.placeholderapi.PlaceholderAPIPlugin; import org.bukkit.Bukkit; +import java.lang.reflect.Field; import java.util.HashMap; +import java.util.Locale; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public final class ServerUtils { - - public static final String VERSION = Bukkit.getBukkitVersion().split("-")[0]; - public static final String BUILD; - private static final Map variants = new HashMap<>(); - - static { - boolean isPaper = false; - variants.put("Purpur", "net.pl3x.purpur.PurpurConfig"); - variants.put("Airplane", "gg.airplane.AirplaneConfig"); - variants.put("Tuinity", "com.tuinity.tuinity.config.TuinityConfig"); + private String version = null; + private String build = null; + private String variant = null; + + private final Map variants = new HashMap<>(); + + private Object craftServer = null; + private Field tps = null; + + private boolean hasTpsMethod = false; + + public ServerUtils() { + variants.put("Spigot", "org.spigotnc.SpigotConfig"); variants.put("Paper", "com.destroystokyo.paper.PaperConfig"); - variants.put("Spigot", "org.spigotmc.SpigotConfig"); - - try { - Class.forName("com.destroystokyo.paper.PaperConfig"); - isPaper = true; - } catch (ClassNotFoundException ignored) { } - + variants.put("Tuinity", "com.tuinity.tuinity.config.TuinityConfig"); + variants.put("Airplane", "gg.airplane.AirplaneConfig"); + variants.put("Purpur", "net.pl3x.purpur.PurpurConfig"); + + resolveTPSHandler(); + } + + public String getServerVariant() { + if (variant != null) { + return variant; + } + + for(Map.Entry variant : variants.entrySet()) { + try { + Class.forName(variant.getValue()); + + return (this.variant = variant.getKey()); + } catch (ClassNotFoundException ignored) {} + } + + return (this.variant = "Unknown"); + } + + public String getVersion() { + if (version != null) { + return version; + } + + return (version = Bukkit.getBukkitVersion().split("-")[0]); + } + + public String getBuild() { + if (build != null) { + return build; + } + String[] buildParts = Bukkit.getVersion().split("-"); - - if (buildParts.length >= 3) { - BUILD = isPaper ? buildParts[2].substring(0, buildParts[2].indexOf(" ")) : buildParts[0]; - } else { - BUILD = "UNKNOWN"; + switch (getServerVariant().toLowerCase(Locale.ROOT)) { + case "spigot": + // TODO: Find out what those variants return. + case "tuinity": + case "airplane": + case "purpur": + return (build = buildParts[0]); + + case "paper": + if (buildParts.length >= 3) { + if (buildParts[2].contains(" ")) { + return (build = buildParts[2].substring(0, buildParts[2].indexOf(" "))); + } else { + return (build = buildParts[2]); + } + } else { + return (build = "Unknown"); + } + + default: + return (build = "Unknown"); } } - - private ServerUtils() { } - - public static String getServerVariant() { - - for (Map.Entry variant : variants.entrySet()) { + + public void clear() { + craftServer = null; + tps = null; + } + + public double[] getTps() { + if (hasTpsMethod) { + return Bukkit.getTPS(); + } + + if (craftServer == null || tps == null) { + return new double[]{0, 0, 0}; + } + + try { + return (double[]) tps.get(craftServer); + } catch (IllegalAccessException ignored) { + return new double[]{0, 0, 0}; + } + } + + private void resolveTPSHandler() { + try { + // If this throws is the server not a fork... + Bukkit.getTPS(); + hasTpsMethod = true; + } catch (Exception ignored) { + final String mcVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + try { - Class.forName(variant.getValue()); - return variant.getKey(); - } catch (ClassNotFoundException ignored) { } + if (getMajorVersion() >= 17) { + craftServer = Class.forName("net.minecraft.server.MinecraftServer") + .getMethod("getServer").invoke(null); + } else { + craftServer = Class.forName("net.minecraft.server." + mcVersion + ".MinecraftServer") + .getMethod("getServer").invoke(null); + } + + tps = craftServer.getClass().getField("recentTps"); + } catch (Exception ex) { + PlaceholderAPIPlugin.getInstance().getLogger().warning("Could not resolve TPS handling!"); + ex.printStackTrace(); + } + } + } + + private int getMajorVersion() { + final Matcher matcher = Pattern.compile("\\(MC: (\\d)\\.(\\d+)\\.?(\\d+?)?\\)").matcher(Bukkit.getVersion()); + if (matcher.find()) { + try{ + return Integer.parseInt(matcher.toMatchResult().group(2), 10); + } catch (NumberFormatException ignored) { + return -1; + } + } else { + return -1; } - - return "Unknown"; } - } From d4ecbd4fefe8d548ac4bcb053b5f121e2e322082 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 21 Oct 2021 21:13:50 +0200 Subject: [PATCH 2/8] Don't use Constructor --- .../papi/expansion/server/ServerExpansion.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java index 4f256fa..8cf510e 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java @@ -46,11 +46,10 @@ public class ServerExpansion extends PlaceholderExpansion implements Cacheable, Configurable { - private final ServerUtils serverUtils; + private ServerUtils serverUtils = null; private final Map dateFormats = new HashMap<>(); private final Runtime runtime = Runtime.getRuntime(); - private final String variant; // config stuff private String serverName; @@ -65,12 +64,6 @@ public class ServerExpansion extends PlaceholderExpansion implements Cacheable, private final String VERSION = getClass().getPackage().getImplementationVersion(); - public ServerExpansion() { - this.serverUtils = new ServerUtils(); - - this.variant = serverUtils.getServerVariant(); - } - @Override public boolean canRegister() { serverName = this.getString("server_name", "A Minecraft Server"); @@ -84,7 +77,7 @@ public boolean canRegister() { public void clear() { serverUtils.clear(); dateFormats.clear(); - + serverUtils = null; cache.invalidateAll(); } @@ -114,8 +107,11 @@ public Map getDefaults() { } @Override - public String onRequest(OfflinePlayer p, String identifier) { + public String onRequest(OfflinePlayer p, @NotNull String identifier) { final int MB = 1048576; + if (serverUtils == null) { + serverUtils = new ServerUtils(); + } switch (identifier) { // Players placeholders @@ -152,7 +148,7 @@ public String onRequest(OfflinePlayer p, String identifier) { case "name": return serverName == null ? "" : serverName; case "variant": - return variant; + return serverUtils.getServerVariant(); // ----- // Other placeholders From 3ee87ea06567df3f05a61a7eea8bd390829478b1 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 21 Oct 2021 21:45:05 +0200 Subject: [PATCH 3/8] Fix some inconsistencies --- .../expansion/server/ServerExpansion.java | 40 +++++++++---------- .../papi/expansion/server/ServerUtils.java | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java index 8cf510e..21474cf 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java @@ -274,24 +274,22 @@ public String onRequest(OfflinePlayer p, @NotNull String identifier) { public String getTps(String arg) { if (arg == null || arg.isEmpty()) { - StringBuilder sb = new StringBuilder(); - for (double t : serverUtils.getTps()) { - sb.append(getColoredTps(t)) - .append(ChatColor.GRAY) - .append(", "); + StringJoiner joiner = new StringJoiner(ChatColor.GRAY + ", "); + for (double tps : serverUtils.getTps()) { + joiner.add(getColoredTps(tps)); } - return sb.toString(); + return joiner.toString(); } - switch (arg) { + switch (arg) { case "1": - case "one": - return String.valueOf(fix(serverUtils.getTps()[0])); + case "one": + return fix(serverUtils.getTps()[0]); case "5": case "five": - return String.valueOf(fix(serverUtils.getTps()[1])); + return fix(serverUtils.getTps()[1]); case "15": case "fifteen": - return String.valueOf(serverUtils.getTps()[2]); + return fix(serverUtils.getTps()[2]); case "1_colored": case "one_colored": return getColoredTps(serverUtils.getTps()[0]); @@ -388,13 +386,14 @@ public static String formatTime(final Duration duration) { return builder.toString(); } - private double fix(double tps) { - return Math.min(Math.round(tps * 100.0) / 100.0, 20.0); + private String fix(double tps) { + double finalTps = Math.min(Math.round(tps), 20.0); + + return (tps > 20.0 ? "*" : "") + finalTps; } private String color(double tps) { - return ChatColor.translateAlternateColorCodes('&', (tps > 18.0) ? high : (tps > 16.0) ? medium : low) - + ((tps > 20.0) ? "*" : ""); + return ChatColor.translateAlternateColorCodes('&', (tps > 18.0) ? high : (tps > 16.0) ? medium : low); } private String getColoredTps(double tps) { @@ -405,6 +404,12 @@ private String getColoredTpsPercent(double tps){ return color(tps) + getPercent(tps); } + private String getPercent(double tps){ + double finalPercent = Math.min(Math.round(100 / 20.0 * tps), 100.0); + + return (tps > 20.0 ? "*" : "") + finalPercent + "%"; + } + private Integer getChunks(){ int loadedChunks = 0; for (final World world : Bukkit.getWorlds()) { @@ -431,9 +436,4 @@ private Integer getTotalEntities(){ return allEntities; } - - private String getPercent(double tps){ - return Math.min(Math.round(100 / 20.0 * tps), 100.0) + "%"; - } - } diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java index ff038d7..9e0f3e7 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java @@ -93,6 +93,7 @@ public void clear() { } public double[] getTps() { + System.out.println(hasTpsMethod); if (hasTpsMethod) { return Bukkit.getTPS(); } From 905d6ef477afdce6dbb39b9bc9389b26975ec5b2 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 21 Oct 2021 21:45:56 +0200 Subject: [PATCH 4/8] Add dependency-reduced-pom.xml to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ab0f7f9..00f972c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build/ target/ -*.iml \ No newline at end of file +*.iml +/dependency-reduced-pom.xml From ad81a89a233c3930ea6873ea4c48d95c6ff9775a Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 21 Oct 2021 21:48:24 +0200 Subject: [PATCH 5/8] Remove debug message --- .../java/com/extendedclip/papi/expansion/server/ServerUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java index 9e0f3e7..ff038d7 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java @@ -93,7 +93,6 @@ public void clear() { } public double[] getTps() { - System.out.println(hasTpsMethod); if (hasTpsMethod) { return Bukkit.getTPS(); } From dbd017b27a220fa04d83c2a3cbccb190829b69d9 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 21 Oct 2021 21:51:33 +0200 Subject: [PATCH 6/8] Just drop ServerUtils instance on clear() --- .../extendedclip/papi/expansion/server/ServerExpansion.java | 1 - .../com/extendedclip/papi/expansion/server/ServerUtils.java | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java index 21474cf..cdb6ca5 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerExpansion.java @@ -75,7 +75,6 @@ public boolean canRegister() { @Override public void clear() { - serverUtils.clear(); dateFormats.clear(); serverUtils = null; cache.invalidateAll(); diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java index ff038d7..ad47acc 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java @@ -87,11 +87,6 @@ public String getBuild() { } } - public void clear() { - craftServer = null; - tps = null; - } - public double[] getTps() { if (hasTpsMethod) { return Bukkit.getTPS(); From 08826c71429ae57a94e81197eaf8ee09c7e89700 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 19 Apr 2022 22:16:21 +0200 Subject: [PATCH 7/8] Use Class.forName(...).getMethod(...) Also, fix typo --- .../com/extendedclip/papi/expansion/server/ServerUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java index ad47acc..b303755 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java @@ -24,7 +24,7 @@ public final class ServerUtils { private boolean hasTpsMethod = false; public ServerUtils() { - variants.put("Spigot", "org.spigotnc.SpigotConfig"); + variants.put("Spigot", "org.spigotmc.SpigotConfig"); variants.put("Paper", "com.destroystokyo.paper.PaperConfig"); variants.put("Tuinity", "com.tuinity.tuinity.config.TuinityConfig"); variants.put("Airplane", "gg.airplane.AirplaneConfig"); @@ -106,9 +106,9 @@ public double[] getTps() { private void resolveTPSHandler() { try { // If this throws is the server not a fork... - Bukkit.getTPS(); + Class.forName("org.bukkit.Bukkit").getMethod("getTPS"); hasTpsMethod = true; - } catch (Exception ignored) { + } catch (ClassNotFoundException | NoSuchMethodException ignored) { final String mcVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; try { From 4ec200a7d273422ff18f558516e3984f1f7488ed Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Tue, 19 Apr 2022 22:46:40 +0200 Subject: [PATCH 8/8] Use Bukkit.class instead of Class.forName --- .../com/extendedclip/papi/expansion/server/ServerUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java index b303755..92a8a0c 100644 --- a/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java +++ b/src/main/java/com/extendedclip/papi/expansion/server/ServerUtils.java @@ -106,9 +106,9 @@ public double[] getTps() { private void resolveTPSHandler() { try { // If this throws is the server not a fork... - Class.forName("org.bukkit.Bukkit").getMethod("getTPS"); + Bukkit.class.getMethod("getTPS"); hasTpsMethod = true; - } catch (ClassNotFoundException | NoSuchMethodException ignored) { + } catch (NoSuchMethodException ignored) { final String mcVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; try {