Skip to content

Commit

Permalink
Fix gamerule read on older Bukkit versions (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Jul 23, 2024
1 parent b78afab commit 4c0149b
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -114,6 +126,10 @@ public ChunksResult<BukkitChunkInfo> pollChunks() {

@Override
public GameRulesResult pollGameRules() {
if (!SUPPORTS_GAMERULES) {
return null;
}

GameRulesResult data = new GameRulesResult();

boolean addDefaults = true; // add defaults in the first iteration
Expand Down

0 comments on commit 4c0149b

Please sign in to comment.