Fixes 'hide-flags' not working in GUI's

This commit is contained in:
Jules 2024-08-27 18:39:45 -07:00
parent 22e5947112
commit 6d71c775f6
5 changed files with 25 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.api.util; package net.Indyuce.mmocore.api.util;
import com.google.common.collect.MultimapBuilder;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.gson.JsonArray; import io.lumine.mythic.lib.gson.JsonArray;
@ -16,6 +17,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.player.PlayerItemDamageEvent; import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -116,6 +118,18 @@ public class MMOCoreUtils {
return material == Material.PLAYER_HEAD || material == Material.PLAYER_WALL_HEAD; return material == Material.PLAYER_HEAD || material == Material.PLAYER_WALL_HEAD;
} }
public static void addAllItemFlags(@NotNull ItemMeta meta) {
meta.addItemFlags(ItemFlag.values());
// Fix 1.20.6+ Paper bug that sucks. HIDE_ATTRIBUTES no longer works when item attribute list is empty
// TODO refactor with GUI update.
try {
meta.setAttributeModifiers(MultimapBuilder.hashKeys(0).hashSetValues(0).build());
} catch (Exception exception) {
// Not needed
}
}
@NotNull @NotNull
public static ItemStack readIcon(String string) { public static ItemStack readIcon(String string) {
final String[] split = string.split(":"); final String[] split = string.split(":");

View File

@ -21,7 +21,6 @@ import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
@ -71,7 +70,7 @@ public class ClassSelect extends EditableInventory {
public ItemStack display(ProfessSelectionInventory inv, int n) { public ItemStack display(ProfessSelectionInventory inv, int n) {
ItemStack item = n == 0 ? playerClass.getIcon() : super.display(inv, n); ItemStack item = n == 0 ? playerClass.getIcon() : super.display(inv, n);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (hideFlags()) meta.addItemFlags(ItemFlag.values()); if (hideFlags()) MMOCoreUtils.addAllItemFlags(meta);
if (hideTooltip()) meta.setHideTooltip(true); if (hideTooltip()) meta.setHideTooltip(true);
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName())); meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName()));
List<String> lore = new ArrayList<>(this.lore); List<String> lore = new ArrayList<>(this.lore);

View File

@ -8,6 +8,7 @@ import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.ClassOption; import net.Indyuce.mmocore.api.player.profess.ClassOption;
import net.Indyuce.mmocore.api.player.profess.PlayerClass; import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.gui.api.EditableInventory; import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext; import net.Indyuce.mmocore.gui.api.InventoryClickContext;
@ -62,7 +63,7 @@ public class SubclassSelect extends EditableInventory {
public ItemStack display(SubclassSelectionInventory inv, int n) { public ItemStack display(SubclassSelectionInventory inv, int n) {
ItemStack item = n == 0 ? playerClass.getIcon() : super.display(inv, n); ItemStack item = n == 0 ? playerClass.getIcon() : super.display(inv, n);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (hideFlags()) meta.addItemFlags(ItemFlag.values()); if (hideFlags()) MMOCoreUtils.addAllItemFlags(meta);
if (hideTooltip()) meta.setHideTooltip(true); if (hideTooltip()) meta.setHideTooltip(true);
meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName())); meta.setDisplayName(MythicLib.plugin.parseColors(name).replace("{name}", playerClass.getName()));
List<String> lore = new ArrayList<>(this.lore); List<String> lore = new ArrayList<>(this.lore);

View File

@ -1,10 +1,10 @@
package net.Indyuce.mmocore.gui; package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage; import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.player.PlayerActivity; import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.gui.api.EditableInventory; import net.Indyuce.mmocore.gui.api.EditableInventory;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.InventoryClickContext; import net.Indyuce.mmocore.gui.api.InventoryClickContext;
@ -14,12 +14,13 @@ import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.waypoint.Waypoint; import net.Indyuce.mmocore.waypoint.Waypoint;
import net.Indyuce.mmocore.waypoint.WaypointPath; import net.Indyuce.mmocore.waypoint.WaypointPath;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.*; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -151,7 +152,7 @@ public class WaypointViewer extends EditableInventory {
if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName())); if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName()));
if (hideFlags()) meta.addItemFlags(ItemFlag.values()); if (hideFlags()) MMOCoreUtils.addAllItemFlags(meta);
if (hideTooltip()) meta.setHideTooltip(true); if (hideTooltip()) meta.setHideTooltip(true);
// If a player can teleport to another waypoint given his location // If a player can teleport to another waypoint given his location
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n); Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n);

View File

@ -2,13 +2,13 @@ package net.Indyuce.mmocore.gui.api.item;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
@ -157,8 +157,8 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName())); if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName()));
if (hideFlags()) meta.addItemFlags(ItemFlag.values());
if (hideTooltip()) meta.setHideTooltip(true); if (hideTooltip()) meta.setHideTooltip(true);
if (hideFlags()) MMOCoreUtils.addAllItemFlags(meta);
if (hasLore()) { if (hasLore()) {
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();