Fixed 1.21 UI bug due to InventoryViews

This commit is contained in:
Jules 2024-07-25 15:00:03 -07:00
parent 7877dc4f8c
commit e9dcbbdda2
6 changed files with 24 additions and 14 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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();

View File

@ -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<Integer, ItemStack> 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 {