From 4c0149b6a15fa887328bbd88c8055c2138cc4d72 Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 23 Jul 2024 20:39:05 +0100 Subject: [PATCH] Fix gamerule read on older Bukkit versions (#428) --- .../spark/bukkit/BukkitWorldInfoProvider.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java index 62903918..be04640a 100644 --- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java +++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitWorldInfoProvider.java @@ -37,6 +37,7 @@ public class BukkitWorldInfoProvider implements WorldInfoProvider { private static final boolean SUPPORTS_PAPER_COUNT_METHODS; + private static final boolean SUPPORTS_GAMERULES; static { boolean supportsPaperCountMethods = false; @@ -48,7 +49,18 @@ public class BukkitWorldInfoProvider implements WorldInfoProvider { } catch (Exception e) { // ignored } + + boolean supportsGameRules = false; + try { + Class.forName("org.bukkit.GameRule"); + World.class.getMethod("getGameRuleValue", GameRule.class); + supportsGameRules = true; + } catch (Exception e) { + // ignored + } + SUPPORTS_PAPER_COUNT_METHODS = supportsPaperCountMethods; + SUPPORTS_GAMERULES = supportsGameRules; } private final Server server; @@ -114,6 +126,10 @@ public ChunksResult pollChunks() { @Override public GameRulesResult pollGameRules() { + if (!SUPPORTS_GAMERULES) { + return null; + } + GameRulesResult data = new GameRulesResult(); boolean addDefaults = true; // add defaults in the first iteration