From e9dcbbdda205199bca397a0d98944c57a2ab0514 Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 25 Jul 2024 15:00:03 -0700 Subject: [PATCH] Fixed 1.21 UI bug due to InventoryViews --- .../api/crafting/recipe/CustomSmithingRecipe.java | 5 +++-- .../mmoitems/gui/edition/recipe/RecipeListGUI.java | 5 +++-- .../mmoitems/gui/edition/recipe/RecipeTypeListGUI.java | 7 ++++--- .../mmoitems/gui/edition/recipe/gui/RecipeEditorGUI.java | 5 +++-- .../java/net/Indyuce/mmoitems/listener/ItemListener.java | 7 +++++-- .../mmoitems/listener/option/SoulboundNoDrop.java | 9 ++++++--- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/CustomSmithingRecipe.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/CustomSmithingRecipe.java index c5fc2d23..31bbbc37 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/CustomSmithingRecipe.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/api/crafting/recipe/CustomSmithingRecipe.java @@ -12,6 +12,7 @@ import io.lumine.mythic.lib.api.util.Ref; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; +import io.lumine.mythic.lib.version.VersionUtils; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.interaction.GemStone; @@ -284,7 +285,7 @@ public class CustomSmithingRecipe extends MythicRecipeOutput { if (!(eventTrigger.getWhoClicked() instanceof Player)) { return mythicRecipeInventory.getResultInventory(); } // Get the two combinant items - MythicBlueprintInventory original = mapping.extractFrom(eventTrigger.getView().getTopInventory()); + MythicBlueprintInventory original = mapping.extractFrom(VersionUtils.getView(eventTrigger).getTopInventory()); ItemStack item = original.getMainInventory().getFirst(); ItemStack ingot = firstFromFirstSide(original); @@ -401,7 +402,7 @@ public class CustomSmithingRecipe extends MythicRecipeOutput { map.applyToResultInventory(eventTrigger.getInventory(), resultInventory, false); // Apply result to the cursor - eventTrigger.getView().setCursor(actualCursor); + VersionUtils.getView(eventTrigger).setCursor(actualCursor); // Consume ingredients consumeIngredients(otherInventories, cache, eventTrigger.getInventory(), map, 1); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListGUI.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListGUI.java index 6f8f654f..3206d965 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListGUI.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeListGUI.java @@ -1,7 +1,8 @@ package net.Indyuce.mmoitems.gui.edition.recipe; -import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.api.util.ItemFactory; +import io.lumine.mythic.lib.api.util.ui.SilentNumbers; +import io.lumine.mythic.lib.version.VersionUtils; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.gui.edition.EditionInventory; @@ -163,7 +164,7 @@ public class RecipeListGUI extends EditionInventory { @Override public void whenClicked(InventoryClickEvent event) { // Clicked inventory was not the observed inventory? Not our business - if ((event.getView().getTopInventory() != event.getClickedInventory())) { return; } + if ((VersionUtils.getView(event).getTopInventory() != event.getClickedInventory())) { return; } // Disallow any clicking. event.setCancelled(true); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeTypeListGUI.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeTypeListGUI.java index f4038432..c37770d2 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeTypeListGUI.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/RecipeTypeListGUI.java @@ -1,12 +1,13 @@ package net.Indyuce.mmoitems.gui.edition.recipe; -import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.api.util.ItemFactory; +import io.lumine.mythic.lib.api.util.ui.SilentNumbers; +import io.lumine.mythic.lib.version.VersionUtils; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.gui.edition.EditionInventory; import net.Indyuce.mmoitems.gui.edition.recipe.registry.*; -import net.Indyuce.mmoitems.gui.edition.recipe.registry.burninglegacy.*; +import net.Indyuce.mmoitems.gui.edition.recipe.registry.burninglegacy.CraftingType; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; @@ -159,7 +160,7 @@ public class RecipeTypeListGUI extends EditionInventory { public void whenClicked(InventoryClickEvent event) { // Clicked inventory was not the observed inventory? Not our business - if ((event.getView().getTopInventory() != event.getClickedInventory())) { return; } + if ((VersionUtils.getView(event).getTopInventory() != event.getClickedInventory())) { return; } // Disallow any clicking. event.setCancelled(true); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/gui/RecipeEditorGUI.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/gui/RecipeEditorGUI.java index 26429c44..bd6d386e 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/gui/RecipeEditorGUI.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/recipe/gui/RecipeEditorGUI.java @@ -10,15 +10,16 @@ import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; import io.lumine.mythic.lib.api.util.ui.QuickNumberRange; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.mythic.lib.util.AdventureUtils; +import io.lumine.mythic.lib.version.VersionUtils; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.edition.StatEdition; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.gui.edition.EditionInventory; -import net.Indyuce.mmoitems.gui.edition.recipe.interpreter.RMG_RecipeInterpreter; import net.Indyuce.mmoitems.gui.edition.recipe.button.RBA_AmountOutput; import net.Indyuce.mmoitems.gui.edition.recipe.button.RecipeButtonAction; +import net.Indyuce.mmoitems.gui.edition.recipe.interpreter.RMG_RecipeInterpreter; import net.Indyuce.mmoitems.gui.edition.recipe.registry.RecipeRegistry; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -404,7 +405,7 @@ public abstract class RecipeEditorGUI extends EditionInventory { public void whenClicked(InventoryClickEvent event) { // Clicked inventory was not the observed inventory? Not our business - if (event.getView().getTopInventory() != event.getClickedInventory()) { + if (VersionUtils.getView(event).getTopInventory() != event.getClickedInventory()) { return; } diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java index 802f8003..e6a4ae5b 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java @@ -3,6 +3,8 @@ package net.Indyuce.mmoitems.listener; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; +import io.lumine.mythic.lib.version.VInventoryView; +import io.lumine.mythic.lib.version.VersionUtils; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem; @@ -54,10 +56,11 @@ public class ItemListener implements Listener { @EventHandler private void onItemCraftRepair(PrepareItemCraftEvent event) { - if (!(event.getView().getPlayer() instanceof Player) || !event.isRepair()) + final VInventoryView view = VersionUtils.getView(event); + if (!(view.getPlayer() instanceof Player) || !event.isRepair()) return; - final Player player = (Player) event.getView().getPlayer(); + final Player player = (Player) view.getPlayer(); final CraftingInventory inv = event.getInventory(); final ItemStack air = new ItemStack(Material.AIR); final ItemStack originalResult = inv.getResult(); diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/option/SoulboundNoDrop.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/option/SoulboundNoDrop.java index 7ddcebfd..0499d199 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/option/SoulboundNoDrop.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/option/SoulboundNoDrop.java @@ -1,6 +1,8 @@ package net.Indyuce.mmoitems.listener.option; import io.lumine.mythic.lib.api.item.NBTItem; +import io.lumine.mythic.lib.version.VInventoryView; +import io.lumine.mythic.lib.version.VersionUtils; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; @@ -34,10 +36,11 @@ public class SoulboundNoDrop implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void cannotDragAround(InventoryDragEvent event) { - if (event.getView().getType() == InventoryType.CRAFTING) return; + final VInventoryView view = VersionUtils.getView(event); + if (view.getType() == InventoryType.CRAFTING) return; // This easily allows to check if the item was dragged in or out of the player's inventory - final int topInventorySize = event.getView().getTopInventory().getContents().length; + final int topInventorySize = view.getTopInventory().getContents().length; for (Map.Entry entry : event.getNewItems().entrySet()) if (entry.getKey() < topInventorySize && isBound(entry.getValue(), event.getWhoClicked())) { event.setCancelled(true); @@ -49,7 +52,7 @@ public class SoulboundNoDrop implements Listener { public void cannotMoveAround(InventoryClickEvent event) { // Can only move around in - if (event.getView().getType() == InventoryType.CRAFTING) return; + if (VersionUtils.getView(event).getType() == InventoryType.CRAFTING) return; try {