From 54f8f0d68fad069691ff0b42a03a72964c72fc66 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:13:17 -0500 Subject: [PATCH] Always initialize block stacks, fixes #2312 --- .../me/pikamug/quests/BukkitQuestsPlugin.java | 4 +- .../pikamug/quests/player/BukkitQuester.java | 10 ++--- .../pikamug/quests/util/BukkitMiscUtil.java | 45 +++++++++++++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/me/pikamug/quests/BukkitQuestsPlugin.java b/core/src/main/java/me/pikamug/quests/BukkitQuestsPlugin.java index 8cf612dc3..5ff6d56f2 100644 --- a/core/src/main/java/me/pikamug/quests/BukkitQuestsPlugin.java +++ b/core/src/main/java/me/pikamug/quests/BukkitQuestsPlugin.java @@ -51,6 +51,7 @@ import me.pikamug.quests.storage.implementation.file.BukkitQuestYamlStorage; import me.pikamug.quests.storage.implementation.jar.BukkitModuleJarStorage; import me.pikamug.quests.tasks.BukkitNpcEffectThread; import me.pikamug.quests.tasks.BukkitPlayerMoveThread; +import me.pikamug.quests.util.BukkitMiscUtil; import me.pikamug.quests.util.BukkitLang; import me.pikamug.quests.util.BukkitUpdateChecker; import me.pikamug.quests.util.stack.BlockItemStacks; @@ -144,11 +145,10 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { try { Class.forName("me.pikamug.quests.libs.localelib.LocaleManager"); localeManager = new LocaleManager(); - BlockItemStacks.init(!localeManager.isBelow113()); } catch (final Exception ignored) { getLogger().warning("LocaleLib not present! Is this a debug environment?"); } - + BlockItemStacks.init(!BukkitMiscUtil.isBelow113()); convoListener = new BukkitConvoListener(); blockListener = new BukkitBlockListener(this); itemListener = new BukkitItemListener(this); diff --git a/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java b/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java index aed56b652..01c06cf87 100644 --- a/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java +++ b/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java @@ -1978,7 +1978,7 @@ public class BukkitQuester implements Quester { // Blocks are solid so check for durability if (broken.getDurability() == toBreak.getDurability()) { goal = toBreak; - } else if (!plugin.getLocaleManager().isBelow113()) { + } else if (!BukkitMiscUtil.isBelow113()) { // Ignore durability for 1.13+ goal = toBreak; } @@ -2079,7 +2079,7 @@ public class BukkitQuester implements Quester { // Blocks are solid so check for durability if (damaged.getDurability() == toDamage.getDurability()) { goal = toDamage; - } else if (!plugin.getLocaleManager().isBelow113()) { + } else if (!BukkitMiscUtil.isBelow113()) { // Ignore durability for 1.13+ goal = toDamage; } @@ -2157,7 +2157,7 @@ public class BukkitQuester implements Quester { // Blocks are solid so check for durability if (placed.getDurability() == toPlace.getDurability()) { goal = toPlace; - } else if (!plugin.getLocaleManager().isBelow113()) { + } else if (!BukkitMiscUtil.isBelow113()) { // Ignore durability for 1.13+ goal = toPlace; } @@ -2235,7 +2235,7 @@ public class BukkitQuester implements Quester { // Blocks are solid so check for durability if (used.getDurability() == toUse.getDurability()) { goal = toUse; - } else if (!plugin.getLocaleManager().isBelow113()) { + } else if (!BukkitMiscUtil.isBelow113()) { // Ignore durability for 1.13+ goal = toUse; } @@ -2313,7 +2313,7 @@ public class BukkitQuester implements Quester { // Blocks are solid so check for durability if (cut.getDurability() == toCut.getDurability()) { goal = toCut; - } else if (!plugin.getLocaleManager().isBelow113()) { + } else if (!BukkitMiscUtil.isBelow113()) { // Ignore durability for 1.13+ goal = toCut; } diff --git a/core/src/main/java/me/pikamug/quests/util/BukkitMiscUtil.java b/core/src/main/java/me/pikamug/quests/util/BukkitMiscUtil.java index 6ba5cce53..16b66b5f9 100644 --- a/core/src/main/java/me/pikamug/quests/util/BukkitMiscUtil.java +++ b/core/src/main/java/me/pikamug/quests/util/BukkitMiscUtil.java @@ -10,6 +10,7 @@ package me.pikamug.quests.util; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Effect; @@ -305,4 +306,48 @@ public class BukkitMiscUtil { input = input.replaceFirst(" ", ""); return input; } + + public static boolean isBelow113() { + return _isBelow113(Bukkit.getServer().getBukkitVersion().split("-")[0]); + } + + private static boolean _isBelow113(String bukkitVersion) { + if (bukkitVersion.matches("^[0-9.]+$")) { + switch (bukkitVersion) { + case "1.12.2": + case "1.12.1": + case "1.12": + case "1.11.2": + case "1.11.1": + case "1.11": + case "1.10.2": + case "1.10.1": + case "1.10": + case "1.9.4": + case "1.9.3": + case "1.9.2": + case "1.9.1": + case "1.9": + case "1.8.9": + case "1.8.8": + case "1.8.7": + case "1.8.6": + case "1.8.5": + case "1.8.4": + case "1.8.3": + case "1.8.2": + case "1.8.1": + case "1.8": + case "1.7.10": + case "1.7.9": + case "1.7.2": + return true; + default: + return false; + } + } else { + Bukkit.getLogger().severe("[Quests] Received invalid Bukkit version " + bukkitVersion); + return false; + } + } }