Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 1 addition & 78 deletions src/main/java/network/palace/show/Show.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<UUID> getNearPlayers() {
if (System.currentTimeMillis() - lastPlayerListUpdate < 10000) {
return new ArrayList<>(nearbyPlayers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/network/palace/show/handlers/ArmorData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
135 changes: 135 additions & 0 deletions src/main/java/network/palace/show/utils/ShowUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
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;
Expand Down Expand Up @@ -327,4 +330,136 @@ 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:<playerTextureResourceHash>;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 {
Comment thread
KyGuy2002 marked this conversation as resolved.
Outdated
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)
Comment thread
KyGuy2002 marked this conversation as resolved.
Outdated
* @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;
}
}