From 6afb92c0de806f1beed087c8e817c3a9669cf43e Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Sat, 15 Jun 2024 14:33:47 -0400 Subject: [PATCH] Compatibility with Minecraft 1.21 --- .../quests/actions/BukkitActionFactory.java | 8 ++- .../conditions/BukkitConditionFactory.java | 8 ++- .../quests/quests/BukkitQuestFactory.java | 8 ++- .../quests/util/BukkitFakeConversable.java | 6 +- .../pikamug/quests/util/BukkitItemUtil.java | 70 +------------------ .../me/pikamug/quests/util/BukkitLang.java | 7 +- 6 files changed, 25 insertions(+), 82 deletions(-) diff --git a/core/src/main/java/me/pikamug/quests/actions/BukkitActionFactory.java b/core/src/main/java/me/pikamug/quests/actions/BukkitActionFactory.java index 5ccabd381..07db50dd7 100644 --- a/core/src/main/java/me/pikamug/quests/actions/BukkitActionFactory.java +++ b/core/src/main/java/me/pikamug/quests/actions/BukkitActionFactory.java @@ -39,6 +39,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -66,8 +67,11 @@ public BukkitActionFactory(final BukkitQuestsPlugin plugin) { this.plugin = plugin; // Ensure to initialize factory last so that 'this' is fully initialized before it is passed this.conversationFactory = new ConversationFactory(plugin).withModality(false).withLocalEcho(false) - .withFirstPrompt(new ActionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable(), - new HashMap<>()))).withTimeout(3600) + .withFirstPrompt(new ActionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable() { + @Override + public void sendRawMessage(@Nullable final UUID uuid, @NotNull final String s) { + } + }, new HashMap<>()))).withTimeout(3600) .withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this); } diff --git a/core/src/main/java/me/pikamug/quests/conditions/BukkitConditionFactory.java b/core/src/main/java/me/pikamug/quests/conditions/BukkitConditionFactory.java index 136596636..e5b283fa5 100644 --- a/core/src/main/java/me/pikamug/quests/conditions/BukkitConditionFactory.java +++ b/core/src/main/java/me/pikamug/quests/conditions/BukkitConditionFactory.java @@ -32,6 +32,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -52,8 +53,11 @@ public BukkitConditionFactory(final BukkitQuestsPlugin plugin) { this.plugin = plugin; // Ensure to initialize factory last so that 'this' is fully initialized before it is passed this.conversationFactory = new ConversationFactory(plugin).withModality(false).withLocalEcho(false) - .withFirstPrompt(new ConditionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable(), - new HashMap<>()))).withTimeout(3600) + .withFirstPrompt(new ConditionMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable() { + @Override + public void sendRawMessage(@Nullable final UUID uuid, @NotNull final String s) { + } + }, new HashMap<>()))).withTimeout(3600) .withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this); } diff --git a/core/src/main/java/me/pikamug/quests/quests/BukkitQuestFactory.java b/core/src/main/java/me/pikamug/quests/quests/BukkitQuestFactory.java index c83a18d3c..aae488ea6 100644 --- a/core/src/main/java/me/pikamug/quests/quests/BukkitQuestFactory.java +++ b/core/src/main/java/me/pikamug/quests/quests/BukkitQuestFactory.java @@ -45,6 +45,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -72,8 +73,11 @@ public BukkitQuestFactory(final BukkitQuestsPlugin plugin) { this.plugin = plugin; // Ensure to initialize factory last so that 'this' is fully initialized before it is passed this.conversationFactory = new ConversationFactory(plugin).withModality(false).withLocalEcho(false) - .withFirstPrompt(new QuestMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable(), - new HashMap<>()))).withTimeout(3600) + .withFirstPrompt(new QuestMenuPrompt(new ConversationContext(plugin, new BukkitFakeConversable() { + @Override + public void sendRawMessage(@Nullable final UUID uuid, @NotNull final String s) { + } + }, new HashMap<>()))).withTimeout(3600) .withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this); } diff --git a/core/src/main/java/me/pikamug/quests/util/BukkitFakeConversable.java b/core/src/main/java/me/pikamug/quests/util/BukkitFakeConversable.java index 16dea506c..54bfeeb51 100644 --- a/core/src/main/java/me/pikamug/quests/util/BukkitFakeConversable.java +++ b/core/src/main/java/me/pikamug/quests/util/BukkitFakeConversable.java @@ -19,13 +19,15 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Set; +import java.util.UUID; /** * For use when creating a new ConversationContext */ -public class BukkitFakeConversable implements Conversable { +public abstract class BukkitFakeConversable implements Conversable { public String lastSentMessage; public Conversation begunConversation; public Conversation abandonedConverstion; @@ -115,5 +117,7 @@ public boolean isOp() { public void setOp(final boolean value) { } + + public abstract void sendRawMessage(@Nullable UUID uuid, @NotNull String s); } diff --git a/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java b/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java index 3f62e2adc..2a5579fa5 100644 --- a/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java +++ b/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java @@ -23,7 +23,6 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.Potion; import java.util.Arrays; import java.util.HashMap; @@ -178,9 +177,7 @@ public static int compareItems(final ItemStack one, final ItemStack two, final b if (Material.getMaterial("LINGERING_POTION") == null) { if (one.getType().equals(Material.POTION)) { // Bukkit version is below 1.9 - final Potion pot1 = new Potion(one.getDurability()); - final Potion pot2 = new Potion(two.getDurability()); - if (!pot1.getType().equals(pot2.getType())) { + if (one.getDurability() != two.getDurability()) { return -9; } } @@ -698,75 +695,10 @@ public static Enchantment getEnchantmentFromProperName(String properName) { if (e.getName().replace("_", "").equalsIgnoreCase(properName.replace("_", ""))) { return e; } - if (getEnchantmentFromProperLegacyName(properName) != null) { - return e; - } } return null; } - /** - * Gets Enchantment from name as it appears in lang file - * - * @deprecated Use {@link #getEnchantmentFromProperName(String)} - * @param enchant Name to match lang value to - * @return Enchantment or null if invalid - */ - @Deprecated - public static Enchantment getEnchantmentFromProperLegacyName(final String enchant) { - if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_DAMAGE"))) { - return Enchantment.ARROW_DAMAGE; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_FIRE"))) { - return Enchantment.ARROW_FIRE; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_INFINITE"))) { - return Enchantment.ARROW_INFINITE; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_ARROW_KNOCKBACK"))) { - return Enchantment.ARROW_KNOCKBACK; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DAMAGE_ALL"))) { - return Enchantment.DAMAGE_ALL; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DAMAGE_ARTHROPODS"))) { - return Enchantment.DAMAGE_ARTHROPODS; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DAMAGE_UNDEAD"))) { - return Enchantment.DAMAGE_UNDEAD; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DIG_SPEED"))) { - return Enchantment.DIG_SPEED; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_DURABILITY"))) { - return Enchantment.DURABILITY; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_FIRE_ASPECT"))) { - return Enchantment.FIRE_ASPECT; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_KNOCKBACK"))) { - return Enchantment.KNOCKBACK; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LOOT_BONUS_BLOCKS"))) { - return Enchantment.LOOT_BONUS_BLOCKS; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LOOT_BONUS_MOBS"))) { - return Enchantment.LOOT_BONUS_MOBS; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LUCK"))) { - return Enchantment.LOOT_BONUS_MOBS; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_LURE"))) { - return Enchantment.LOOT_BONUS_MOBS; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_OXYGEN"))) { - return Enchantment.OXYGEN; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_ENVIRONMENTAL"))) { - return Enchantment.PROTECTION_ENVIRONMENTAL; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_EXPLOSIONS"))) { - return Enchantment.PROTECTION_EXPLOSIONS; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_FALL"))) { - return Enchantment.PROTECTION_FALL; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_FIRE"))) { - return Enchantment.PROTECTION_FIRE; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_PROTECTION_PROJECTILE"))) { - return Enchantment.PROTECTION_PROJECTILE; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_SILK_TOUCH"))) { - return Enchantment.SILK_TOUCH; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_THORNS"))) { - return Enchantment.THORNS; - } else if (enchant.equalsIgnoreCase(BukkitLang.get("ENCHANTMENT_WATER_WORKER"))) { - return Enchantment.WATER_WORKER; - } else { - return null; - } - } - public static Enchantment getEnchantmentFromPrettyName(String enchant) { if (enchant != null) { if (BukkitMiscUtil.spaceToCapital(enchant) != null) { diff --git a/core/src/main/java/me/pikamug/quests/util/BukkitLang.java b/core/src/main/java/me/pikamug/quests/util/BukkitLang.java index 834d11123..c90cb66c1 100644 --- a/core/src/main/java/me/pikamug/quests/util/BukkitLang.java +++ b/core/src/main/java/me/pikamug/quests/util/BukkitLang.java @@ -67,12 +67,7 @@ public static String get(final Player player, final String key) { if (player == null) { return get(key); } - String locale; - try { - locale = player.getLocale(); - } catch (NoSuchMethodError e) { - locale = player.spigot().getLocale(); - } + String locale= player.getLocale(); final int separator = locale.indexOf("_"); if (separator == -1) { return defaultLang.containsKey(key) ? BukkitFormatToken.convertString(player, defaultLang.get(key)) : "NULL";