diff --git a/src/main/java/net/Indyuce/mmoitems/MMOUtils.java b/src/main/java/net/Indyuce/mmoitems/MMOUtils.java index e11195ef..fe13a8f6 100644 --- a/src/main/java/net/Indyuce/mmoitems/MMOUtils.java +++ b/src/main/java/net/Indyuce/mmoitems/MMOUtils.java @@ -1,32 +1,25 @@ package net.Indyuce.mmoitems; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.annotation.Nullable; - +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import net.mmogroup.mmolib.MMOLib; import org.apache.commons.codec.binary.Base64; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.attribute.Attribute; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; +import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; -import com.mojang.authlib.GameProfile; -import com.mojang.authlib.properties.Property; - -import net.mmogroup.mmolib.MMOLib; +import javax.annotation.Nullable; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; public class MMOUtils { public static String getSkullTextureURL(ItemStack item) { @@ -302,4 +295,10 @@ public class MMOUtils { return entities; } + + public static ItemStack readIcon(String string) throws IllegalArgumentException { + String[] split = string.split("\\:"); + Material material = Material.valueOf(split[0].toUpperCase().replace("-", "_").replace(" ", "_")); + return split.length > 1 ? MMOLib.plugin.getVersion().getWrapper().textureItem(material, Integer.parseInt(split[1])) : new ItemStack(material); + } } diff --git a/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java b/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java index ee7f6bbc..86e255af 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java +++ b/src/main/java/net/Indyuce/mmoitems/api/item/util/ConfigItem.java @@ -1,9 +1,12 @@ package net.Indyuce.mmoitems.api.item.util; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - +import net.Indyuce.mmoitems.MMOUtils; +import net.Indyuce.mmoitems.api.item.util.crafting.CraftingRecipeDisplay; +import net.Indyuce.mmoitems.api.item.util.crafting.QueueItemDisplay; +import net.Indyuce.mmoitems.api.item.util.crafting.UpgradingRecipeDisplay; +import net.mmogroup.mmolib.MMOLib; +import net.mmogroup.mmolib.api.item.ItemTag; +import net.mmogroup.mmolib.version.VersionMaterial; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -12,16 +15,14 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import net.Indyuce.mmoitems.api.item.util.crafting.CraftingRecipeDisplay; -import net.Indyuce.mmoitems.api.item.util.crafting.QueueItemDisplay; -import net.Indyuce.mmoitems.api.item.util.crafting.UpgradingRecipeDisplay; -import net.mmogroup.mmolib.MMOLib; -import net.mmogroup.mmolib.api.item.ItemTag; -import net.mmogroup.mmolib.version.VersionMaterial; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; public class ConfigItem { private final String id; private final Material material; + private final ItemStack icon; // updated when the plugin reloads private String name; @@ -64,6 +65,7 @@ public class ConfigItem { this.id = id; this.material = material; + this.icon = new ItemStack(material); this.name = name; this.lore = Arrays.asList(lore); } @@ -76,8 +78,10 @@ public class ConfigItem { id = config.getName(); Validate.isTrue(config.contains("material"), "Could not find material"); - material = Material.valueOf(config.getString("material").toUpperCase().replace("-", "_").replace(" ", "_")); + icon = MMOUtils.readIcon(config.getString("material")); + + material = icon.getType(); name = config.getString("name", ""); lore = config.getStringList("lore"); @@ -102,7 +106,7 @@ public class ConfigItem { } public void updateItem() { - setItem(new ItemStack(material)); + setItem(icon); if (material == Material.AIR) return;