Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1.8.8 - 1.12.2 support (#428) #429

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class BukkitWorldInfoProvider implements WorldInfoProvider {

private static final boolean SUPPORTS_BUKKIT_GAMERULES;
private static final boolean SUPPORTS_PAPER_COUNT_METHODS;

static {
boolean supportsGameRules = false;
try {
Class.forName("org.bukkit.GameRule");
supportsGameRules = true;
} catch (final Throwable ignored) {
// ignored
}
SUPPORTS_BUKKIT_GAMERULES = supportsGameRules;

boolean supportsPaperCountMethods = false;
try {
World.class.getMethod("getEntityCount");
Expand Down Expand Up @@ -113,24 +123,30 @@ public ChunksResult<BukkitChunkInfo> pollChunks() {
}

@Override
@SuppressWarnings("deprecation")
public GameRulesResult pollGameRules() {
GameRulesResult data = new GameRulesResult();

boolean addDefaults = true; // add defaults in the first iteration
for (World world : this.server.getWorlds()) {
for (String gameRule : world.getGameRules()) {
GameRule<?> ruleObj = GameRule.getByName(gameRule);
if (ruleObj == null) {
continue;
}
for (final World world : this.server.getWorlds()) {
for (final String gameRule : world.getGameRules()) {
final Object value;
if (SUPPORTS_BUKKIT_GAMERULES) {
GameRule<?> ruleObj = GameRule.getByName(gameRule);
if (ruleObj == null) {
continue;
}
value = world.getGameRuleValue(ruleObj);

if (addDefaults) {
Object defaultValue = world.getGameRuleDefault(ruleObj);
data.putDefault(gameRule, Objects.toString(defaultValue));
if (addDefaults) {
Object defaultValue = world.getGameRuleDefault(ruleObj);
data.putDefault(gameRule, String.valueOf(defaultValue));
}
} else {
value = world.getGameRuleValue(gameRule);
}

Object value = world.getGameRuleValue(ruleObj);
data.put(gameRule, world.getName(), Objects.toString(value));
data.put(gameRule, world.getName(), String.valueOf(value));
}

addDefaults = false;
Expand Down