public void update(Boss boss, IronGolem g) {
   boss.setHealth((int) g.getHealth());
   g.setCustomName(
       ChatColor.translateAlternateColorCodes(
           '&', boss.getBossName() + " &8» &a" + (int) boss.getHealth() + " HP"));
   bossNames.put(g.getCustomName(), boss);
   bosses.put(boss.getConfigName(), boss);
 }
  @SuppressWarnings("deprecation")
  public void spawn(Boss b) {
    Location spawn = b.getSpawn();

    if (spawn != null && spawn.getWorld() != null) {
      IronGolem boss = (IronGolem) spawn.getWorld().spawnCreature(spawn, EntityType.IRON_GOLEM);
      boss.setMaxHealth(b.getHealth());
      boss.setHealth(b.getHealth());
      boss.setCanPickupItems(false);
      boss.setPlayerCreated(false);
      boss.setRemoveWhenFarAway(false);
      boss.setCustomNameVisible(true);
      boss.setCustomName(
          ChatColor.translateAlternateColorCodes(
              '&', b.getBossName() + " &8» &a" + (int) b.getHealth() + " HP"));
      bossNames.put(boss.getCustomName(), b);
      Util.spawnFirework(b.getSpawn());
      Util.spawnFirework(b.getSpawn());
      Util.spawnFirework(b.getSpawn());
    }
  }
  @SuppressWarnings("deprecation")
  public void assignMobProps(Entity baseEntity, ISpawnableEntity data) {

    // This needs to be before everything else!
    if (data.getRider() != null) {
      addRider(baseEntity, data.getRider());
    }

    Vector v1 = data.getVelocity(baseEntity);
    Vector v2 = data.getVelocity2(baseEntity);
    if (v2.getX() == 0 && v2.getY() == 0 && v2.getZ() == 0) {
      baseEntity.setVelocity(data.getVelocity(baseEntity).clone());
    } else {
      Vector v3 = randomVector(v1, v2);
      baseEntity.setVelocity(v3.clone());
    }
    baseEntity.setFireTicks(data.getFireTicks(baseEntity));

    if (baseEntity instanceof LivingEntity) {
      LivingEntity entity = (LivingEntity) baseEntity;
      setBasicProps(entity, data);

      if (data.showCustomName()) {
        setCustomName(entity, data);
      }

      if (entity instanceof Ageable) {
        Ageable a = (Ageable) entity;
        setAgeProps(a, data);
      }

      if (entity instanceof Animals) {
        Animals animal = (Animals) entity;

        // Setting animal specific properties
        if (animal instanceof Pig) {
          Pig p = (Pig) animal;
          p.setSaddle(data.isSaddled());
        } else if (animal instanceof Sheep) {
          Sheep s = (Sheep) animal;
          DyeColor color = DyeColor.valueOf(data.getColor());
          s.setColor(color);
        } else if (animal instanceof Wolf) {
          Wolf w = (Wolf) animal;
          w.setAngry(data.isAngry());
          w.setTamed(data.isTamed());
          if (data.isTamed()) {

            ArrayList<Player> nearPlayers = getNearbyPlayers(w.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              w.setOwner(nearPlayers.get(index));
            }

            w.setSitting(data.isSitting());
          }
        } else if (animal instanceof Ocelot) {
          Ocelot o = (Ocelot) animal;
          o.setTamed(data.isTamed());
          if (data.isTamed()) {
            Ocelot.Type catType = Ocelot.Type.valueOf(data.getCatType());
            o.setCatType(catType);

            ArrayList<Player> nearPlayers = getNearbyPlayers(o.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              o.setOwner(nearPlayers.get(index));
            }

            o.setSitting(data.isSitting());
          }
        }
      } else if (entity instanceof Villager) {
        Villager v = (Villager) entity;
        v.setAge(data.getAge(baseEntity));
        v.setProfession(data.getProfession());
      } else if (entity instanceof Monster) {
        Monster monster = (Monster) entity;

        // Setting monster specific properties.
        if (monster instanceof Enderman) {
          Enderman e = (Enderman) monster;
          e.setCarriedMaterial(data.getEndermanBlock());
        } else if (monster instanceof Creeper) {
          Creeper c = (Creeper) monster;
          c.setPowered(data.isCharged());
        } else if (monster instanceof PigZombie) {
          PigZombie p = (PigZombie) monster;
          if (data.isAngry()) {
            p.setAngry(true);
          }
          p.setBaby((data.getAge(baseEntity) < -1) ? true : false);
        } else if (monster instanceof Spider) {
          Spider s = (Spider) monster;
          if (data.isJockey()) {
            makeJockey(s, data);
          }
        } else if (monster instanceof Zombie) {
          Zombie z = (Zombie) monster;
          boolean isVillager = false;
          if (data.hasProp("zombie")) {
            isVillager = (Boolean) (data.getProp("zombie"));
          }
          z.setBaby((data.getAge(baseEntity) < -1) ? true : false);
          z.setVillager(isVillager);
        } else if (monster instanceof Skeleton) {
          Skeleton sk = (Skeleton) monster;
          SkeletonType skType = SkeletonType.NORMAL;

          if (data.hasProp("wither")) {
            skType =
                ((Boolean) (data.getProp("wither")) == true)
                    ? SkeletonType.WITHER
                    : SkeletonType.NORMAL;
          }

          sk.setSkeletonType(skType);
        }
      } else if (entity instanceof Golem) {
        Golem golem = (Golem) entity;

        if (golem instanceof IronGolem) {
          IronGolem i = (IronGolem) golem;
          if (data.isAngry()) {
            ArrayList<Player> nearPlayers = getNearbyPlayers(i.getLocation(), 16);
            int index = (int) Math.round(Math.rint(nearPlayers.size() - 1));
            if (nearPlayers != null) {
              i.setPlayerCreated(false);
              i.damage(0, nearPlayers.get(index));
              i.setTarget(nearPlayers.get(index));
            }
          }
        }
        // Some are not classified as animals or monsters
      } else if (entity instanceof Slime) {
        Slime s = (Slime) entity;
        s.setSize(data.getSlimeSize());
      } else if (entity instanceof MagmaCube) {
        MagmaCube m = (MagmaCube) entity;
        m.setSize(data.getSlimeSize());
      }

    } else if (baseEntity instanceof Projectile) {
      Projectile pro = (Projectile) baseEntity;

      // Eventually add explosive arrows and such :D

      if (pro instanceof Fireball) {
        Fireball f = (Fireball) pro;
        setExplosiveProps(f, data);
        f.setVelocity(new Vector(0, 0, 0));
        f.setDirection(data.getVelocity(baseEntity));
      } else if (pro instanceof SmallFireball) {
        SmallFireball f = (SmallFireball) pro;
        setExplosiveProps(f, data);
        f.setVelocity(new Vector(0, 0, 0));
        f.setDirection(data.getVelocity(baseEntity));
      }

    } else if (baseEntity instanceof Explosive) {

      Explosive ex = (Explosive) baseEntity;

      if (ex instanceof TNTPrimed) {
        TNTPrimed tnt = (TNTPrimed) ex;
        setExplosiveProps(tnt, data);
        tnt.setFuseTicks(data.getFuseTicks(baseEntity));
      }

    } else if (baseEntity instanceof Firework) {

      Firework f = (Firework) baseEntity;
      ItemMeta meta = data.getItemType().getItemMeta();
      if (meta != null) {
        if (meta instanceof FireworkMeta) {
          FireworkMeta fMeta = (FireworkMeta) meta;
          if (fMeta != null) {
            f.setFireworkMeta(fMeta);
          }
        }
      }

    } else if (baseEntity instanceof Minecart) {

      Minecart m = (Minecart) baseEntity;
      if (data.hasProp("minecartSpeed")) {
        m.setMaxSpeed((Double) data.getProp("minecartSpeed"));
      }

    } else if (baseEntity instanceof ExperienceOrb) {
      ExperienceOrb o = (ExperienceOrb) baseEntity;
      o.setExperience(data.getDroppedExp(baseEntity));
    }

    setNBT(baseEntity, data);
  }
    public List<LivingEntity> spawn(Location location, Player player) {
      List<LivingEntity> entities = new ArrayList<LivingEntity>(this.num);
      World world = location.getWorld();

      for (int num = 0; num < this.num; num++) {
        if (spread > 0) {
          int minX = location.getBlockX() - spread / 2;
          int minY = location.getBlockY() - spread / 2;
          int minZ = location.getBlockZ() - spread / 2;
          int maxX = location.getBlockX() + spread / 2;
          int maxY = location.getBlockY() + spread / 2;
          int maxZ = location.getBlockZ() + spread / 2;

          int tries = spread * 10;
          boolean found = false;

          while (tries-- > 0) {
            int x = minX + RecipeManager.random.nextInt(maxX - minX);
            int z = minZ + RecipeManager.random.nextInt(maxZ - minZ);
            int y = 0;

            for (y = maxY; y >= minY; y--) {
              if (!Material.getMaterial(world.getBlockTypeIdAt(x, y, z)).isSolid()) {
                found = true;
                break;
              }
            }

            if (found) {
              location.setX(x);
              location.setY(y);
              location.setZ(z);
              break;
            }
          }

          if (!found) {
            Messages.debug(
                "Couldn't find suitable location after " + (spread * 10) + " tries, using center.");
          }

          location.add(0.5, 0, 0.5);
        }

        LivingEntity ent = (LivingEntity) world.spawnEntity(location, type);
        entities.add(ent);

        if (!noEffect) {
          world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 20);
        }

        if (name != null) {
          ent.setCustomName(name);
          ent.setCustomNameVisible(noHideName);
        }

        if (onFire > 0.0f) {
          ent.setFireTicks((int) Math.ceil(onFire * 20.0));
        }

        if (pickup != null) {
          ent.setCanPickupItems(pickup);
        }

        if (pet && ent instanceof Tameable) {
          Tameable npc = (Tameable) ent;
          npc.setOwner(player);
          npc.setTamed(true);
        }

        if (ent instanceof Wolf) {
          Wolf npc = (Wolf) ent;

          if (pet) {
            if (noSit) {
              npc.setSitting(false);
            }

            if (color != null) {
              npc.setCollarColor(color);
            }
          } else if (angry) {
            npc.setAngry(true);
          }
        }

        if (ent instanceof Ocelot) {
          Ocelot npc = (Ocelot) ent;

          if (pet && noSit) {
            npc.setSitting(false);
          }

          if (cat != null) {
            npc.setCatType(cat);
          }
        }

        if (hp > 0) {
          ent.setHealth(hp);

          if (maxHp > 0) {
            ent.setMaxHealth(maxHp);
          }
        }

        if (ent instanceof Ageable) {
          Ageable npc = (Ageable) ent;

          if (baby) {
            npc.setBaby();
          }

          if (ageLock) {
            npc.setAgeLock(true);
          }

          if (noBreed) {
            npc.setBreed(false);
          }
        }

        if (saddle && ent instanceof Pig) {
          Pig npc = (Pig) ent;
          npc.setSaddle(true);

          if (mount) {
            npc.setPassenger(player);
          }
        }

        if (ent instanceof Zombie) {
          Zombie npc = (Zombie) ent;

          if (baby) {
            npc.setBaby(true);
          }

          if (zombieVillager) {
            npc.setVillager(true);
          }
        }

        if (villager != null && ent instanceof Villager) {
          Villager npc = (Villager) ent;
          npc.setProfession(villager);
        }

        if (poweredCreeper && ent instanceof Creeper) {
          Creeper npc = (Creeper) ent;
          npc.setPowered(true);
        }

        if (playerIronGolem && ent instanceof IronGolem) {
          IronGolem npc = (IronGolem) ent;
          npc.setPlayerCreated(true); // TODO what exacly does this do ?
        }

        if (shearedSheep && ent instanceof Sheep) {
          Sheep npc = (Sheep) ent;
          npc.setSheared(true);
        }

        if (color != null && ent instanceof Colorable) {
          Colorable npc = (Colorable) ent;
          npc.setColor(color);
        }

        if (skeleton != null && ent instanceof Skeleton) {
          Skeleton npc = (Skeleton) ent;
          npc.setSkeletonType(skeleton);
        }

        if (target && ent instanceof Creature) {
          Creature npc = (Creature) ent;
          npc.setTarget(player);
        }

        if (pigAnger > 0 && ent instanceof PigZombie) {
          PigZombie npc = (PigZombie) ent;
          npc.setAnger(pigAnger);
        }

        if (hit) {
          ent.damage(0, player);
          ent.setVelocity(new Vector());
        }

        if (!potions.isEmpty()) {
          for (PotionEffect effect : potions) {
            ent.addPotionEffect(effect, true);
          }
        }

        ent.setRemoveWhenFarAway(!noRemove);

        EntityEquipment eq = ent.getEquipment();

        for (int i = 0; i < equip.length; i++) {
          ItemStack item = equip[i];

          if (item == null) {
            continue;
          }

          switch (i) {
            case 0:
              eq.setHelmet(item);
              eq.setHelmetDropChance(drop[i]);
              break;

            case 1:
              eq.setChestplate(item);
              eq.setChestplateDropChance(drop[i]);
              break;

            case 2:
              eq.setLeggings(item);
              eq.setLeggingsDropChance(drop[i]);
              break;

            case 3:
              eq.setBoots(item);
              eq.setBootsDropChance(drop[i]);
              break;

            case 4:
              {
                if (ent instanceof Enderman) {
                  Enderman npc = (Enderman) ent;
                  npc.setCarriedMaterial(item.getData());
                } else {
                  eq.setItemInHand(item);
                  eq.setItemInHandDropChance(drop[i]);
                }

                break;
              }
          }
        }
      }

      return entities;
    }