adds custom model data support to crafting stations guis

This commit is contained in:
Ethan 2020-08-30 04:47:49 -04:00
parent dd591069ce
commit f5a1c37fb9
2 changed files with 31 additions and 28 deletions

View File

@ -1,32 +1,25 @@
package net.Indyuce.mmoitems; package net.Indyuce.mmoitems;
import java.lang.reflect.Field; import com.mojang.authlib.GameProfile;
import java.util.ArrayList; import com.mojang.authlib.properties.Property;
import java.util.Collection; import net.mmogroup.mmolib.MMOLib;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
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.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.mojang.authlib.GameProfile; import javax.annotation.Nullable;
import com.mojang.authlib.properties.Property; import java.lang.reflect.Field;
import java.util.ArrayList;
import net.mmogroup.mmolib.MMOLib; import java.util.Collection;
import java.util.List;
public class MMOUtils { public class MMOUtils {
public static String getSkullTextureURL(ItemStack item) { public static String getSkullTextureURL(ItemStack item) {
@ -302,4 +295,10 @@ public class MMOUtils {
return entities; 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);
}
} }

View File

@ -1,9 +1,12 @@
package net.Indyuce.mmoitems.api.item.util; package net.Indyuce.mmoitems.api.item.util;
import java.util.ArrayList; import net.Indyuce.mmoitems.MMOUtils;
import java.util.Arrays; import net.Indyuce.mmoitems.api.item.util.crafting.CraftingRecipeDisplay;
import java.util.List; 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.apache.commons.lang.Validate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -12,16 +15,14 @@ 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 net.Indyuce.mmoitems.api.item.util.crafting.CraftingRecipeDisplay; import java.util.ArrayList;
import net.Indyuce.mmoitems.api.item.util.crafting.QueueItemDisplay; import java.util.Arrays;
import net.Indyuce.mmoitems.api.item.util.crafting.UpgradingRecipeDisplay; import java.util.List;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.ItemTag;
import net.mmogroup.mmolib.version.VersionMaterial;
public class ConfigItem { public class ConfigItem {
private final String id; private final String id;
private final Material material; private final Material material;
private final ItemStack icon;
// updated when the plugin reloads // updated when the plugin reloads
private String name; private String name;
@ -64,6 +65,7 @@ public class ConfigItem {
this.id = id; this.id = id;
this.material = material; this.material = material;
this.icon = new ItemStack(material);
this.name = name; this.name = name;
this.lore = Arrays.asList(lore); this.lore = Arrays.asList(lore);
} }
@ -76,8 +78,10 @@ public class ConfigItem {
id = config.getName(); id = config.getName();
Validate.isTrue(config.contains("material"), "Could not find material"); 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", ""); name = config.getString("name", "");
lore = config.getStringList("lore"); lore = config.getStringList("lore");
@ -102,7 +106,7 @@ public class ConfigItem {
} }
public void updateItem() { public void updateItem() {
setItem(new ItemStack(material)); setItem(icon);
if (material == Material.AIR) if (material == Material.AIR)
return; return;