public static String getEntityTypeData(final Entity entity) { String data = ""; if (entity instanceof LivingEntity) { data += String.valueOf(((LivingEntity) entity).getHealth()) + ","; data += String.valueOf(((LivingEntity) entity).getMaxHealth()) + ","; data += String.valueOf(((LivingEntity) entity).getCustomName()) + ","; if (entity instanceof Animals) { data += String.valueOf(((Animals) entity).getAge()) + ","; if (entity instanceof Sheep) { data += String.valueOf(((Sheep) entity).isSheared()) + ","; data += ((Sheep) entity).getColor().name() + ","; } else if (entity instanceof Wolf) { data += String.valueOf(((Wolf) entity).isAngry()) + ","; if (((Wolf) entity).isTamed()) { data += ((Tameable) entity).getOwner().getName() + ","; data += String.valueOf(((Wolf) entity).getCollarColor()) + ","; } } else if (entity instanceof Ocelot) { if (((Ocelot) entity).isTamed()) { data += ((Tameable) entity).getOwner().getName() + ","; data += String.valueOf(((Ocelot) entity).getCatType().name()) + ","; } } else if (entity instanceof Pig) { data += String.valueOf(((Pig) entity).hasSaddle()) + ","; } else if (entity instanceof Horse) { data += String.valueOf(((Horse) entity).getVariant().name()) + ","; data += String.valueOf(((Horse) entity).getStyle().name()) + ","; data += String.valueOf(((Horse) entity).getColor().name()) + ","; data += String.valueOf(((Horse) entity).getDomestication()) + ","; data += String.valueOf(((Horse) entity).getMaxDomestication()) + ","; data += String.valueOf(((Horse) entity).getJumpStrength()) + ","; if (((Horse) entity).isTamed()) { data += (((Tameable) entity).getOwner() != null ? ((Tameable) entity).getOwner().getName() : null) + ","; data += ItemStackUtil.itemStackToString(((Horse) entity).getInventory().getSaddle()) + ","; data += ItemStackUtil.itemStackToString(((Horse) entity).getInventory().getArmor()) + ","; if (((Horse) entity).isCarryingChest()) { data += ItemStackUtil.itemStackToString(((Horse) entity).getInventory().getContents()) + ","; } } } } else if (entity instanceof Villager) { data += String.valueOf(((Villager) entity).getProfession().name()) + ","; data += String.valueOf(((Villager) entity).getAge()) + ","; } else if (entity instanceof Creeper) { data += String.valueOf(((Creeper) entity).isPowered()) + ","; } else if (entity instanceof Slime) { data += String.valueOf(((Slime) entity).getSize()) + ","; } else if (entity instanceof Skeleton) { data += String.valueOf(((Skeleton) entity).getSkeletonType().name()) + ","; } } return data; }
public static void setEntityTypeData(final Entity entity, final String data) { if (data == "") return; final String parts[] = data.split(","); if (entity instanceof LivingEntity) { ((LivingEntity) entity).setMaxHealth(Double.parseDouble(parts[1])); ((LivingEntity) entity).setHealth(Double.parseDouble(parts[0])); if (!parts[2].equals("null")) ((LivingEntity) entity).setCustomName(parts[2]); if (entity instanceof Animals) { ((Animals) entity).setAge(Integer.parseInt(parts[3])); if (entity instanceof Sheep) { ((Sheep) entity).setSheared(Boolean.parseBoolean(parts[4])); ((Sheep) entity).setColor(sheepColors.get(parts[5])); } else if (entity instanceof Wolf) { if (Boolean.parseBoolean(parts[4])) { ((Wolf) entity).setAngry(Boolean.parseBoolean(parts[4])); } else if (parts.length > 5) { ((Tameable) entity).setTamed(true); ((Tameable) entity).setOwner(getPlayer(parts[5])); ((Wolf) entity).setCollarColor(DyeColor.valueOf(parts[6])); } } else if (entity instanceof Ocelot) { if (parts.length > 4) { ((Tameable) entity).setTamed(true); ((Tameable) entity).setOwner(getPlayer(parts[4])); ((Ocelot) entity).setCatType(catTypes.get(parts[5])); } } else if (entity instanceof Pig) { ((Pig) entity).setSaddle(Boolean.parseBoolean(parts[4])); } else if (entity instanceof Horse) { ((Horse) entity).setVariant(horseVariants.get(parts[4])); ((Horse) entity).setStyle(horseStyles.get(parts[5])); ((Horse) entity).setColor(horseColors.get(parts[6])); ((Horse) entity).setDomestication(Integer.parseInt(parts[7])); ((Horse) entity).setMaxDomestication(Integer.parseInt(parts[8])); ((Horse) entity).setJumpStrength(Double.parseDouble(parts[9])); if (parts.length > 10) { ((Tameable) entity).setTamed(true); if (!parts[10].equals("null")) ((Tameable) entity).setOwner(getPlayer(parts[10])); ((Horse) entity) .getInventory() .setSaddle(ItemStackUtil.stringToItemStack(parts[11])[0]); ((Horse) entity).getInventory().setArmor(ItemStackUtil.stringToItemStack(parts[12])[0]); if (parts.length > 13) { ((Horse) entity).setCarryingChest(true); ((Horse) entity) .getInventory() .setContents(ItemStackUtil.stringToItemStack(parts[13])); } } } } else if (entity instanceof Villager) { ((Villager) entity).setProfession(villagerProfessions.get(parts[3])); ((Villager) entity).setAge(Integer.parseInt(parts[4])); } else if (entity instanceof Creeper) { ((Creeper) entity).setPowered(Boolean.parseBoolean(parts[3])); } else if (entity instanceof Slime) { ((Slime) entity).setSize(Integer.parseInt(parts[3])); } else if (entity instanceof Skeleton) { ((Skeleton) entity).setSkeletonType(skeletonTypes.get(parts[3])); if (parts[3].equals("0")) { ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW)); } else { ((Skeleton) entity).getEquipment().setItemInHand(new ItemStack(Material.BOW)); } } else if (entity instanceof PigZombie) { ((LivingEntity) entity).getEquipment().setItemInHand(new ItemStack(Material.GOLD_SWORD)); } } }