From 9e3f329ca0142c8853427e3f101a442c12ccfcde Mon Sep 17 00:00:00 2001 From: filoghost Date: Mon, 15 Jun 2020 21:14:34 +0200 Subject: [PATCH] Refactoring: remove hideAttributes --- .../api/impl/ConfigurableIconImpl.java | 7 +++++++ .../chestcommands/menu/AdvancedIconMenu.java | 9 ++++---- .../chestcommands/menu/BaseIconMenu.java | 21 +------------------ 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java index f50f2fb..5ec1faf 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/api/impl/ConfigurableIconImpl.java @@ -31,6 +31,7 @@ import org.bukkit.block.banner.Pattern; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.ItemMeta; @@ -332,6 +333,11 @@ public class ConfigurableIconImpl implements ConfigurableIcon { ((BannerMeta) itemMeta).setPatterns(bannerPatterns); } } + + // Hide all text details (damage, enchantments, potions, etc,) + if (Utils.isNullOrEmpty(itemMeta.getItemFlags())) { + itemMeta.addItemFlags(ItemFlag.values()); + } itemStack.setItemMeta(itemMeta); @@ -341,6 +347,7 @@ public class ConfigurableIconImpl implements ConfigurableIcon { } } + if (!this.hasVariables()) { // If there are no variables, cache the item cachedItem = itemStack; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java index c1514fa..dc7e0b3 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/AdvancedIconMenu.java @@ -105,15 +105,14 @@ public class AdvancedIconMenu extends BaseIconMenu { private ItemStack refreshIcon(Player player, AdvancedIcon icon, ItemStack currentItem) { if (icon.canViewIcon(player)) { if (currentItem == null) { - return hideAttributes(icon.createItemStack(player)); + return icon.createItemStack(player); } else { // Performance, only update name and lore - ItemStack oldItem = hideAttributes(currentItem); - ItemMeta meta = oldItem.getItemMeta(); + ItemMeta meta = currentItem.getItemMeta(); meta.setDisplayName(icon.calculateName(player)); meta.setLore(icon.calculateLore(player)); - oldItem.setItemMeta(meta); - return oldItem; + currentItem.setItemMeta(meta); + return currentItem; } } else { return null; diff --git a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java index 7f372a7..c794149 100644 --- a/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java +++ b/Plugin/src/main/java/me/filoghost/chestcommands/menu/BaseIconMenu.java @@ -17,15 +17,10 @@ package me.filoghost.chestcommands.menu; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - import me.filoghost.chestcommands.api.Icon; import me.filoghost.chestcommands.menu.inventory.Grid; import me.filoghost.chestcommands.menu.inventory.MenuInventoryHolder; import me.filoghost.chestcommands.util.Preconditions; -import me.filoghost.chestcommands.util.Utils; public class BaseIconMenu { @@ -76,7 +71,7 @@ public class BaseIconMenu { for (int i = 0; i < inventoryGrid.getSize(); i++) { T icon = inventoryGrid.getElementAtIndex(i); if (icon != null && canViewIcon(player, icon)) { - inventory.setItem(i, hideAttributes(icon.createItemStack(player))); + inventory.setItem(i, icon.createItemStack(player)); } } @@ -86,20 +81,6 @@ public class BaseIconMenu { protected boolean canViewIcon(Player player, T icon) { return true; } - - protected ItemStack hideAttributes(ItemStack item) { - if (item == null) { - return null; - } - - ItemMeta meta = item.getItemMeta(); - if (Utils.isNullOrEmpty(meta.getItemFlags())) { - // Add them only if no flag was already set - meta.addItemFlags(ItemFlag.values()); - item.setItemMeta(meta); - } - return item; - } @Override public String toString() {