mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-25 19:45:44 +01:00
Refactoring: remove hideAttributes
This commit is contained in:
parent
8f098fc961
commit
9e3f329ca0
@ -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;
|
||||
|
@ -105,15 +105,14 @@ public class AdvancedIconMenu extends BaseIconMenu<AdvancedIcon> {
|
||||
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;
|
||||
|
@ -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<T extends Icon> {
|
||||
|
||||
@ -76,7 +71,7 @@ public class BaseIconMenu<T extends Icon> {
|
||||
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<T extends Icon> {
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user