示例#1
0
  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));
      }
    }
  }