From 8a146eaa3811f99d998050985fe509f78b9faaf3 Mon Sep 17 00:00:00 2001 From: KyGuy2002 Date: Wed, 20 Apr 2022 14:40:07 -0700 Subject: [PATCH 1/4] Armorstand armor parsing now works with modern material names, offhand is supported, and legacy block ids no long work with a ShowParseException --- src/main/java/network/palace/show/Show.java | 79 +--------- .../show/actions/armor/ArmorStandSpawn.java | 3 + .../palace/show/handlers/ArmorData.java | 3 +- .../network/palace/show/utils/ShowUtil.java | 137 ++++++++++++++++++ 4 files changed, 143 insertions(+), 79 deletions(-) diff --git a/src/main/java/network/palace/show/Show.java b/src/main/java/network/palace/show/Show.java index b7d8a3b..2731110 100644 --- a/src/main/java/network/palace/show/Show.java +++ b/src/main/java/network/palace/show/Show.java @@ -169,8 +169,7 @@ public boolean add(ShowAction mt) { continue; } boolean small = Boolean.parseBoolean(args[2]); - //ArmorStand 0 false skull:myHash;299(234,124,41);300;301 - ArmorData armorData = parseArmorData(args[3]); + ArmorData armorData = ShowUtil.parseArmorData(args[3]); ShowStand stand = new ShowStand(id, small, armorData); standmap.put(id, stand); continue; @@ -393,82 +392,6 @@ private double rad(double v) { return (v * Math.PI) / 180; } - private ArmorData parseArmorData(String s) throws Exception { - String[] list = s.split(";"); - ItemStack head = new ItemStack(Material.AIR); - ItemStack chestplate = new ItemStack(Material.AIR); - ItemStack leggings = new ItemStack(Material.AIR); - ItemStack boots = new ItemStack(Material.AIR); - ItemStack itemInMainHand = new ItemStack(Material.AIR); - int i = 0; - if (list.length >= 4) { - for (String st : list) { - i++; - if (i == 1) { - if (st.startsWith("skull")) { - head = HeadUtil.getPlayerHead(st.split(":")[1]); - continue; - } - } - if (st.contains("(")) { - String[] color = st.split("\\("); - String[] l = color[0].split(":"); - int id = Integer.parseInt(l[0]); - byte dam = l.length > 1 ? Byte.parseByte(l[1]) : 0; - Material type = Material.getMaterial(ShowUtil.convertMaterialNoData(id).name()); - if (!type.name().toLowerCase().contains("leather")) { - continue; - } - ItemStack temp = new ItemStack(type, 1, dam); - LeatherArmorMeta lam = (LeatherArmorMeta) temp.getItemMeta(); - String[] cls = color[1].replaceAll("[()]", "").split(","); - lam.setColor(Color.fromRGB(Integer.parseInt(cls[0]), Integer.parseInt(cls[1]), - Integer.parseInt(cls[2]))); - temp.setItemMeta(lam); - switch (i) { - case 1: - head = temp; - continue; - case 2: - chestplate = temp; - continue; - case 3: - leggings = temp; - continue; - case 4: - boots = temp; - continue; - case 5: - itemInMainHand = temp; - continue; - } - continue; - } - String[] l = st.split(":"); - int id = Integer.parseInt(l[0]); - byte dam = l.length > 1 ? Byte.parseByte(l[1]) : 0; - ItemStack temp = new ItemStack(Material.getMaterial(ShowUtil.convertMaterialNoData(id).name()), 1, dam); - switch (i) { - case 1: - head = temp; - continue; - case 2: - chestplate = temp; - continue; - case 3: - leggings = temp; - continue; - case 4: - boots = temp; - continue; - case 5: - itemInMainHand = temp; - } - } - } - return new ArmorData(head, chestplate, leggings, boots, itemInMainHand); - } - public List getNearPlayers() { if (System.currentTimeMillis() - lastPlayerListUpdate < 10000) { return new ArrayList<>(nearbyPlayers); diff --git a/src/main/java/network/palace/show/actions/armor/ArmorStandSpawn.java b/src/main/java/network/palace/show/actions/armor/ArmorStandSpawn.java index 9f093b4..68076be 100644 --- a/src/main/java/network/palace/show/actions/armor/ArmorStandSpawn.java +++ b/src/main/java/network/palace/show/actions/armor/ArmorStandSpawn.java @@ -58,6 +58,9 @@ public void play(Player[] nearPlayers) { if (data.getItemInMainHand() != null) { armor.setItemInHand(data.getItemInMainHand()); } + if (data.getItemInOffHand() != null) { + armor.getEquipment().setItemInOffHand(data.getItemInOffHand()); + } } stand.setStand(armor); } diff --git a/src/main/java/network/palace/show/handlers/ArmorData.java b/src/main/java/network/palace/show/handlers/ArmorData.java index ede7fd4..7175f28 100644 --- a/src/main/java/network/palace/show/handlers/ArmorData.java +++ b/src/main/java/network/palace/show/handlers/ArmorData.java @@ -15,9 +15,10 @@ public class ArmorData { private ItemStack leggings; private ItemStack boots; private ItemStack itemInMainHand; + private ItemStack itemInOffHand; @Override public String toString() { - return head.toString() + " " + chestplate.toString() + " " + leggings.toString() + " " + boots.toString() + " " + itemInMainHand.toString(); + return head.toString() + " " + chestplate.toString() + " " + leggings.toString() + " " + boots.toString() + " " + itemInMainHand.toString() + " " + itemInOffHand.toString(); } } diff --git a/src/main/java/network/palace/show/utils/ShowUtil.java b/src/main/java/network/palace/show/utils/ShowUtil.java index 9ffda0c..1421cee 100644 --- a/src/main/java/network/palace/show/utils/ShowUtil.java +++ b/src/main/java/network/palace/show/utils/ShowUtil.java @@ -3,13 +3,17 @@ import network.palace.show.Show; import network.palace.show.ShowPlugin; import network.palace.show.exceptions.ShowParseException; +import network.palace.show.handlers.ArmorData; import network.palace.show.handlers.BlockData; import network.palace.show.handlers.TitleType; import network.palace.show.sequence.ShowSequence; import org.bukkit.*; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.material.MaterialData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import scala.Int; import java.text.DecimalFormat; import java.util.ArrayList; @@ -327,4 +331,137 @@ public static void logDebug(String showName, String message) { Show s = ShowPlugin.getInstance().getShows().get(showName); if (s != null) s.debug(); } + + /* + Input: + LEATHER_HELMET;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING + skull:;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING + LEATHER_HELMET;LEATHER_CHESTPLATE:(5,5,5);LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING + */ + + /** + * Parses the armor data from the string. + * @param s Input string. Format: head;chest;leg;boot;hand;offhand + * @return The armor data + * @throws Exception If there was an error parsing data + */ + public static ArmorData parseArmorData(String s) throws Exception { + String[] list = s.split(";"); + ItemStack head = new ItemStack(Material.AIR); + ItemStack chestplate = new ItemStack(Material.AIR); + ItemStack leggings = new ItemStack(Material.AIR); + ItemStack boots = new ItemStack(Material.AIR); + ItemStack itemInMainHand = new ItemStack(Material.AIR); + ItemStack itemInOffHand = new ItemStack(Material.AIR); + + // Get itemstack from string + int slot = -1; + for (String data : list) { + slot++; + + switch (slot) { + + case 0: { // Head + System.out.println("data: " + data); + + // Try to parse skull + if (data.startsWith("skull")) { + head = HeadUtil.getPlayerHead(data.split(":")[1]); + continue; + } + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + head = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + head = new ItemStack(Material.valueOf(data)); // Get material + } + case 1: { // Chestplate + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + chestplate = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + chestplate = new ItemStack(Material.valueOf(data)); // Get material + + } + case 2: { // Leggings + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + leggings = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + leggings = new ItemStack(Material.valueOf(data)); // Get material + } + case 3: { // Boots + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + boots = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + boots = new ItemStack(Material.valueOf(data)); // Get material + } + case 4: { // Main Hand + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + itemInMainHand = new ItemStack(Material.valueOf(data)); // Get material + } + case 5: { // Off Hand + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + itemInOffHand = new ItemStack(Material.valueOf(data)); // Get material + } + + } + + } + + return new ArmorData(head, chestplate, leggings, boots, itemInMainHand, itemInOffHand); + } + + /** + * Tries to get a piece of leather armor with color values. + * @param data Armor and color data. Format: LEATHER_HELMET:data(r,g,b) + * @return Colored item + */ + private static ItemStack parseColoredArmor(String data) throws Exception { + String colors = data.split(":")[1]; // should get "data(r,g,b)" + colors = colors.replaceFirst("data", ""); // should get "(r,g,b)" + colors = colors.replaceAll("\\)", ""); + colors = colors.replaceAll("\\(", ""); // should get "r,g,b" + + int red = Integer.parseInt(colors.split(",")[0]); + int green = Integer.parseInt(colors.split(",")[1]); + int blue = Integer.parseInt(colors.split(",")[2]); + + if (MiscUtil.checkIfInt(data.split(":")[0])) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + Material mat = Material.valueOf(data.split(":")[0]); // Get material + + // If can't be colored, throw exception + if (!mat.toString().toLowerCase().contains("leather")) { + throw new ShowParseException("Material (" + mat + ") cannot be colored."); + } + + // Apply colors + ItemStack temp = new ItemStack(mat, 1); + LeatherArmorMeta lam = (LeatherArmorMeta) temp.getItemMeta(); + lam.setColor(Color.fromRGB(red, green, blue)); + temp.setItemMeta(lam); + + return temp; + } } From 3fec4fad180b84e5ce7ceb2c6252ca7caeb34dbe Mon Sep 17 00:00:00 2001 From: KyGuy2002 Date: Wed, 20 Apr 2022 14:52:38 -0700 Subject: [PATCH 2/4] removed debug and import --- src/main/java/network/palace/show/utils/ShowUtil.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/network/palace/show/utils/ShowUtil.java b/src/main/java/network/palace/show/utils/ShowUtil.java index 1421cee..a3e869a 100644 --- a/src/main/java/network/palace/show/utils/ShowUtil.java +++ b/src/main/java/network/palace/show/utils/ShowUtil.java @@ -13,7 +13,6 @@ import org.bukkit.material.MaterialData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import scala.Int; import java.text.DecimalFormat; import java.util.ArrayList; @@ -362,7 +361,6 @@ public static ArmorData parseArmorData(String s) throws Exception { switch (slot) { case 0: { // Head - System.out.println("data: " + data); // Try to parse skull if (data.startsWith("skull")) { From 0e0589c20b697f2676934cc781634389f4113a57 Mon Sep 17 00:00:00 2001 From: KyGuy2002 Date: Fri, 22 Apr 2022 10:29:37 -0700 Subject: [PATCH 3/4] Moved parseArmorData from utils back to show --- src/main/java/network/palace/show/Show.java | 135 +++++++++++++++++- .../network/palace/show/utils/ShowUtil.java | 132 ----------------- 2 files changed, 134 insertions(+), 133 deletions(-) diff --git a/src/main/java/network/palace/show/Show.java b/src/main/java/network/palace/show/Show.java index 2731110..18b1b08 100644 --- a/src/main/java/network/palace/show/Show.java +++ b/src/main/java/network/palace/show/Show.java @@ -16,6 +16,7 @@ import network.palace.show.sequence.light.LightSequence; import network.palace.show.sequence.particle.ParticleSequence; import network.palace.show.utils.HeadUtil; +import network.palace.show.utils.MiscUtil; import network.palace.show.utils.ShowUtil; import network.palace.show.utils.WorldUtil; import org.bukkit.*; @@ -169,7 +170,7 @@ public boolean add(ShowAction mt) { continue; } boolean small = Boolean.parseBoolean(args[2]); - ArmorData armorData = ShowUtil.parseArmorData(args[3]); + ArmorData armorData = parseArmorData(args[3]); ShowStand stand = new ShowStand(id, small, armorData); standmap.put(id, stand); continue; @@ -392,6 +393,138 @@ private double rad(double v) { return (v * Math.PI) / 180; } + /* + Input: + LEATHER_HELMET;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING + skull:;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING + LEATHER_HELMET;LEATHER_CHESTPLATE:(5,5,5);LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING + */ + + /** + * Parses the armor data from the string. + * @param s Input string. Format: head;chest;leg;boot;hand;offhand + * @return The armor data + * @throws Exception If there was an error parsing data + */ + private ArmorData parseArmorData(String s) throws Exception { + String[] list = s.split(";"); + ItemStack head = new ItemStack(Material.AIR); + ItemStack chestplate = new ItemStack(Material.AIR); + ItemStack leggings = new ItemStack(Material.AIR); + ItemStack boots = new ItemStack(Material.AIR); + ItemStack itemInMainHand = new ItemStack(Material.AIR); + ItemStack itemInOffHand = new ItemStack(Material.AIR); + + // Get itemstack from string + int slot = -1; + for (String data : list) { + slot++; + + switch (slot) { + + case 0: { // Head + + // Try to parse skull + if (data.startsWith("skull")) { + head = HeadUtil.getPlayerHead(data.split(":")[1]); + continue; + } + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + head = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + head = new ItemStack(Material.valueOf(data)); // Get material + } + case 1: { // Chestplate + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + chestplate = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + chestplate = new ItemStack(Material.valueOf(data)); // Get material + + } + case 2: { // Leggings + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + leggings = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + leggings = new ItemStack(Material.valueOf(data)); // Get material + } + case 3: { // Boots + + // Try to color leather armor + if (data.endsWith(")")) { + // Returns colored leather, or whatever item was passed in if not leather + boots = parseColoredArmor(data); + continue; + } + + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + boots = new ItemStack(Material.valueOf(data)); // Get material + } + case 4: { // Main Hand + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + itemInMainHand = new ItemStack(Material.valueOf(data)); // Get material + } + case 5: { // Off Hand + if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + itemInOffHand = new ItemStack(Material.valueOf(data)); // Get material + } + + } + + } + + return new ArmorData(head, chestplate, leggings, boots, itemInMainHand, itemInOffHand); + } + + /** + * Tries to get a piece of leather armor with color values. + * @param data Armor and color data. Format: LEATHER_HELMET:data(r,g,b) + * @return Colored item + */ + private ItemStack parseColoredArmor(String data) throws Exception { + String colors = data.split(":")[1]; // should get "data(r,g,b)" + colors = colors.replaceFirst("data", ""); // should get "(r,g,b)" + colors = colors.replaceAll("\\)", ""); + colors = colors.replaceAll("\\(", ""); // should get "r,g,b" + + int red = Integer.parseInt(colors.split(",")[0]); + int green = Integer.parseInt(colors.split(",")[1]); + int blue = Integer.parseInt(colors.split(",")[2]); + + if (MiscUtil.checkIfInt(data.split(":")[0])) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); + Material mat = Material.valueOf(data.split(":")[0]); // Get material + + // If can't be colored, throw exception + if (!mat.toString().toLowerCase().contains("leather")) { + throw new ShowParseException("Material (" + mat + ") cannot be colored."); + } + + // Apply colors + ItemStack temp = new ItemStack(mat, 1); + LeatherArmorMeta lam = (LeatherArmorMeta) temp.getItemMeta(); + lam.setColor(Color.fromRGB(red, green, blue)); + temp.setItemMeta(lam); + + return temp; + } + public List getNearPlayers() { if (System.currentTimeMillis() - lastPlayerListUpdate < 10000) { return new ArrayList<>(nearbyPlayers); diff --git a/src/main/java/network/palace/show/utils/ShowUtil.java b/src/main/java/network/palace/show/utils/ShowUtil.java index a3e869a..06e8beb 100644 --- a/src/main/java/network/palace/show/utils/ShowUtil.java +++ b/src/main/java/network/palace/show/utils/ShowUtil.java @@ -330,136 +330,4 @@ public static void logDebug(String showName, String message) { Show s = ShowPlugin.getInstance().getShows().get(showName); if (s != null) s.debug(); } - - /* - Input: - LEATHER_HELMET;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING - skull:;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING - LEATHER_HELMET;LEATHER_CHESTPLATE:(5,5,5);LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING - */ - - /** - * Parses the armor data from the string. - * @param s Input string. Format: head;chest;leg;boot;hand;offhand - * @return The armor data - * @throws Exception If there was an error parsing data - */ - public static ArmorData parseArmorData(String s) throws Exception { - String[] list = s.split(";"); - ItemStack head = new ItemStack(Material.AIR); - ItemStack chestplate = new ItemStack(Material.AIR); - ItemStack leggings = new ItemStack(Material.AIR); - ItemStack boots = new ItemStack(Material.AIR); - ItemStack itemInMainHand = new ItemStack(Material.AIR); - ItemStack itemInOffHand = new ItemStack(Material.AIR); - - // Get itemstack from string - int slot = -1; - for (String data : list) { - slot++; - - switch (slot) { - - case 0: { // Head - - // Try to parse skull - if (data.startsWith("skull")) { - head = HeadUtil.getPlayerHead(data.split(":")[1]); - continue; - } - - // Try to color leather armor - if (data.endsWith(")")) { - // Returns colored leather, or whatever item was passed in if not leather - head = parseColoredArmor(data); - continue; - } - - if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); - head = new ItemStack(Material.valueOf(data)); // Get material - } - case 1: { // Chestplate - - // Try to color leather armor - if (data.endsWith(")")) { - // Returns colored leather, or whatever item was passed in if not leather - chestplate = parseColoredArmor(data); - continue; - } - - if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); - chestplate = new ItemStack(Material.valueOf(data)); // Get material - - } - case 2: { // Leggings - - // Try to color leather armor - if (data.endsWith(")")) { - // Returns colored leather, or whatever item was passed in if not leather - leggings = parseColoredArmor(data); - continue; - } - - if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); - leggings = new ItemStack(Material.valueOf(data)); // Get material - } - case 3: { // Boots - - // Try to color leather armor - if (data.endsWith(")")) { - // Returns colored leather, or whatever item was passed in if not leather - boots = parseColoredArmor(data); - continue; - } - - if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); - boots = new ItemStack(Material.valueOf(data)); // Get material - } - case 4: { // Main Hand - if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); - itemInMainHand = new ItemStack(Material.valueOf(data)); // Get material - } - case 5: { // Off Hand - if (MiscUtil.checkIfInt(data)) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); - itemInOffHand = new ItemStack(Material.valueOf(data)); // Get material - } - - } - - } - - return new ArmorData(head, chestplate, leggings, boots, itemInMainHand, itemInOffHand); - } - - /** - * Tries to get a piece of leather armor with color values. - * @param data Armor and color data. Format: LEATHER_HELMET:data(r,g,b) - * @return Colored item - */ - private static ItemStack parseColoredArmor(String data) throws Exception { - String colors = data.split(":")[1]; // should get "data(r,g,b)" - colors = colors.replaceFirst("data", ""); // should get "(r,g,b)" - colors = colors.replaceAll("\\)", ""); - colors = colors.replaceAll("\\(", ""); // should get "r,g,b" - - int red = Integer.parseInt(colors.split(",")[0]); - int green = Integer.parseInt(colors.split(",")[1]); - int blue = Integer.parseInt(colors.split(",")[2]); - - if (MiscUtil.checkIfInt(data.split(":")[0])) throw new ShowParseException("Legacy (1.12) numeric IDs are no longer supported. Please convert to modern names."); - Material mat = Material.valueOf(data.split(":")[0]); // Get material - - // If can't be colored, throw exception - if (!mat.toString().toLowerCase().contains("leather")) { - throw new ShowParseException("Material (" + mat + ") cannot be colored."); - } - - // Apply colors - ItemStack temp = new ItemStack(mat, 1); - LeatherArmorMeta lam = (LeatherArmorMeta) temp.getItemMeta(); - lam.setColor(Color.fromRGB(red, green, blue)); - temp.setItemMeta(lam); - - return temp; - } } From 134aa0053ce38faf9146d9eed248d3ae422fd539 Mon Sep 17 00:00:00 2001 From: KyGuy2002 Date: Fri, 22 Apr 2022 10:54:05 -0700 Subject: [PATCH 4/4] Colored armor parsing now supports both formats: "ITEM_NAME:data(r,g,b)" and "ITEM_NAME:(r,g,b)" --- src/main/java/network/palace/show/Show.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/network/palace/show/Show.java b/src/main/java/network/palace/show/Show.java index 18b1b08..b2206d9 100644 --- a/src/main/java/network/palace/show/Show.java +++ b/src/main/java/network/palace/show/Show.java @@ -397,7 +397,7 @@ private double rad(double v) { Input: LEATHER_HELMET;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING skull:;LEATHER_CHESTPLATE;LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING - LEATHER_HELMET;LEATHER_CHESTPLATE:(5,5,5);LEATHER_LEGGINGS;LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING + LEATHER_HELMET;LEATHER_CHESTPLATE:(5,5,5);LEATHER_LEGGINGS:data(7,7,7);LEATHER_BOOTS;WOOD_SWORD;TOTEM_OF_UNDYING */ /** @@ -499,8 +499,8 @@ private ArmorData parseArmorData(String s) throws Exception { * @return Colored item */ private ItemStack parseColoredArmor(String data) throws Exception { - String colors = data.split(":")[1]; // should get "data(r,g,b)" - colors = colors.replaceFirst("data", ""); // should get "(r,g,b)" + String colors = data.split(":")[1]; // should get "data(r,g,b)" or "(r,g,b)" + if (colors.toLowerCase().contains("data")) colors = colors.replaceFirst("data", ""); // should get "(r,g,b)" colors = colors.replaceAll("\\)", ""); colors = colors.replaceAll("\\(", ""); // should get "r,g,b"