From b6b3ce8c76c0809b76118e568aba5759d327219b Mon Sep 17 00:00:00 2001 From: Aria Date: Fri, 29 Nov 2019 18:55:27 +0100 Subject: [PATCH] Fixed certain items not being able to use custom texture values --- .../net/Indyuce/mmocore/gui/ClassSelect.java | 2 +- .../net/Indyuce/mmocore/gui/QuestViewer.java | 2 +- .../net/Indyuce/mmocore/gui/SkillList.java | 4 +-- .../api/item/InventoryPlaceholderItem.java | 25 +++++++++++++------ .../gui/api/item/NoPlaceholderItem.java | 6 ++--- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java b/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java index 75f32d9b..8e047b39 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java +++ b/src/main/java/net/Indyuce/mmocore/gui/ClassSelect.java @@ -46,7 +46,7 @@ public class ClassSelect extends EditableInventory { private final List lore; public ClassItem(ConfigurationSection config) { - super(Material.BARRIER, config); + super(new ItemStack(Material.BARRIER), config); this.name = config.getString("name"); this.lore = config.getStringList("lore"); diff --git a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java index 0fd85610..8eaed1fe 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java +++ b/src/main/java/net/Indyuce/mmocore/gui/QuestViewer.java @@ -134,7 +134,7 @@ public class QuestViewer extends EditableInventory { /* * generate item */ - ItemStack item = new ItemStack(getMaterial()); + ItemStack item = new ItemStack(getStack()); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(holders.apply(inv.getPlayer(), getName())); meta.addItemFlags(ItemFlag.values()); diff --git a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index f96b64f1..f32de116 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -170,7 +170,7 @@ public class SkillList extends EditableInventory { for (int j = 0; j < lore.size(); j++) lore.set(j, ChatColor.GRAY + ChatColor.translateAlternateColorCodes('&', lore.get(j))); - ItemStack item = new ItemStack(getMaterial()); + ItemStack item = new ItemStack(getStack()); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', getName().replace("{skill}", skill.getSkill().getName()).replace("{roman}", MMOCoreUtils.intToRoman(skillLevel)).replace("{level}", "" + skillLevel))); meta.addItemFlags(ItemFlag.values()); @@ -195,7 +195,7 @@ public class SkillList extends EditableInventory { private final int selectedSkillSlot; public SkillItem(ConfigurationSection config) { - super(Material.BARRIER, config); + super(new ItemStack(Material.BARRIER), config); selectedSkillSlot = config.getInt("selected-slot"); } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/item/InventoryPlaceholderItem.java b/src/main/java/net/Indyuce/mmocore/gui/api/item/InventoryPlaceholderItem.java index c56ee144..5e12f6f6 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/item/InventoryPlaceholderItem.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/item/InventoryPlaceholderItem.java @@ -7,7 +7,6 @@ import java.util.UUID; import java.util.logging.Level; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -18,32 +17,35 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.MMOCoreUtils; import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.PluginInventory; public abstract class InventoryPlaceholderItem extends InventoryItem { - private final Material material; + private final ItemStack stack; private final String name, texture; private final List lore; + private final int modelData; private final boolean placeholders, hideFlags; public InventoryPlaceholderItem(ConfigurationSection config) { - this(Material.valueOf(config.getString("item")), config); + this(MMOCoreUtils.readIcon(config.getString("item")), config); } - public InventoryPlaceholderItem(Material material, ConfigurationSection config) { + public InventoryPlaceholderItem(ItemStack stack, ConfigurationSection config) { super(config); - this.material = material; + this.stack = stack; this.name = config.getString("name"); this.lore = config.getStringList("lore"); this.hideFlags = config.getBoolean("hide-flags"); this.texture = config.getString("texture"); this.placeholders = config.getBoolean("placeholders"); + this.modelData = config.getInt("custom-model-data"); } - public Material getMaterial() { - return material; + public ItemStack getStack() { + return stack; } public boolean hideFlags() { @@ -66,6 +68,10 @@ public abstract class InventoryPlaceholderItem extends InventoryItem { return lore; } + public int getModelData() { + return modelData; + } + public boolean supportPlaceholders() { return placeholders; } @@ -85,7 +91,7 @@ public abstract class InventoryPlaceholderItem extends InventoryItem { public ItemStack display(GeneratedInventory inv, int n) { Placeholders placeholders = getPlaceholders(inv, n); - ItemStack item = new ItemStack(getMaterial()); + ItemStack item = getStack(); ItemMeta meta = item.getItemMeta(); if (texture != null && meta instanceof SkullMeta) @@ -103,6 +109,9 @@ public abstract class InventoryPlaceholderItem extends InventoryItem { meta.setLore(lore); } + if (MMOCore.plugin.version.isStrictlyHigher(1, 13)) + meta.setCustomModelData(getModelData()); + item.setItemMeta(meta); return item; } diff --git a/src/main/java/net/Indyuce/mmocore/gui/api/item/NoPlaceholderItem.java b/src/main/java/net/Indyuce/mmocore/gui/api/item/NoPlaceholderItem.java index 4e31fe95..1c3d9aef 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/api/item/NoPlaceholderItem.java +++ b/src/main/java/net/Indyuce/mmocore/gui/api/item/NoPlaceholderItem.java @@ -1,7 +1,7 @@ package net.Indyuce.mmocore.gui.api.item; -import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.inventory.ItemStack; import net.Indyuce.mmocore.gui.api.PluginInventory; @@ -10,8 +10,8 @@ public class NoPlaceholderItem extends InventoryPlaceholderItem { super(config); } - public NoPlaceholderItem(Material material, ConfigurationSection config) { - super(material, config); + public NoPlaceholderItem(ItemStack stack, ConfigurationSection config) { + super(stack, config); } @Override