From 62174c0e3b3a630d3df1889df564350062c8b71e Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 28 Jun 2021 20:48:44 -0400 Subject: [PATCH] Spigot plugin fixes - If non-NMS world adapter: don't try to load a chunk if it doesn't exist - Don't error out with older Spigot versions if a gamerule doesn't exist --- .../world/manager/GeyserSpigotWorldManager.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java index 41e2fd801..6746a8d1a 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java @@ -71,6 +71,11 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager { return BlockTranslator.JAVA_AIR_ID; } World world = bukkitPlayer.getWorld(); + if (!world.isChunkLoaded(x >> 4, z >> 4)) { + // If the chunk isn't loaded, how could we even be here? + return BlockTranslator.JAVA_AIR_ID; + } + return BlockTranslator.getJavaIdBlockMap().getOrDefault(world.getBlockAt(x, y, z).getBlockData().getAsString(), BlockTranslator.JAVA_AIR_ID); } @@ -151,12 +156,20 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager { } public Boolean getGameRuleBool(GeyserSession session, GameRule gameRule) { - return Boolean.parseBoolean(Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID())); + String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID()); + if (!value.isEmpty()) { + return Boolean.parseBoolean(value); + } + return (Boolean) gameRule.getDefaultValue(); } @Override public int getGameRuleInt(GeyserSession session, GameRule gameRule) { - return Integer.parseInt(Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID())); + String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID()); + if (!value.isEmpty()) { + return Integer.parseInt(value); + } + return (int) gameRule.getDefaultValue(); } @Override