Esempio n. 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));
      }
    }
  }
Esempio n. 2
0
    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;
    }