@Override
 public void setOn(Entity mob, Player owner) {
   if (mob instanceof Skeleton) {
     Skeleton z = (Skeleton) mob;
     if (type != null) z.setSkeletonType(type);
     leData.setOn(mob, owner);
   }
 }
 private void setDefaultEq(LivingEntity mob) {
   if (mob instanceof Skeleton) {
     Skeleton skellie = (Skeleton) mob;
     if (skellie.getSkeletonType() == SkeletonType.WITHER) {
       if (equip == null || equip.hands == null)
         skellie.getEquipment().setItemInHand(new ItemStack(Material.STONE_SWORD));
     } else {
       if (equip == null || equip.hands == null)
         skellie.getEquipment().setItemInHand(new ItemStack(Material.BOW));
     }
   }
 }
 public static Skeleton skeletronBoss(Location boss) {
   Skeleton skeleton = (Skeleton) boss.getWorld().spawn(boss, Skeleton.class);
   skeleton.setCustomName(ChatColor.RED + "Skeletron");
   skeleton.setCustomNameVisible(true);
   skeleton.setMaxHealth(250.0);
   skeleton.setHealth(250.0);
   skeleton.setRemoveWhenFarAway(false);
   return skeleton;
 }
  @SuppressWarnings("deprecation")
  public void setDefaultInventory(LivingEntity e) {
    EntityEquipment ee = e.getEquipment();

    if (ee == null) {
      return;
    }

    switch (e.getType()) {
      case SKELETON:
        Skeleton sk = ((Skeleton) e);
        if (sk.getSkeletonType().getId() == SkeletonType.WITHER.getId()) {
          ee.setItemInHand(new ItemStack(Material.STONE_SWORD));
        } else {
          ee.setItemInHand(new ItemStack(Material.BOW));
        }
        break;
      case PIG_ZOMBIE:
        ee.setItemInHand(new ItemStack(Material.GOLD_SWORD));
        break;
      default:
        break;
    }
  }
示例#5
0
  /**
   * Begins Tree Feller
   *
   * @param player Player using Shake Mob
   * @param mob Targeted entity
   * @param skillLevel Fishing level of the player
   */
  public static void process(Player player, LivingEntity mob, int skillLevel) {
    int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player));

    if (getShakeProbability(skillLevel) <= Misc.getRandom().nextInt(activationChance)) {
      return;
    }

    Map<ItemStack, Integer> possibleDrops = new HashMap<ItemStack, Integer>();

    findPossibleDrops(mob, possibleDrops);

    if (possibleDrops.isEmpty()) {
      return;
    }

    ItemStack drop = chooseDrop(possibleDrops);

    // It's possible that chooseDrop returns null if the sum of probability in possibleDrops is
    // inferior than 100
    if (drop == null) {
      return;
    }

    // Extra processing depending on the mob and drop type
    switch (mob.getType()) {
      case SHEEP:
        Sheep sheep = (Sheep) mob;

        if (drop.getType() == Material.WOOL) {
          if (sheep.isSheared()) {
            return;
          }

          // TODO: Find a cleaner way to do this, maybe by using Sheep.getColor().getWoolData()
          // (available since 1.4.7-R0.1)
          Wool wool = (Wool) drop.getData();

          wool.setColor(sheep.getColor());
          drop.setDurability(wool.getData());
          sheep.setSheared(true);
        }
        break;

      case SKELETON:
        Skeleton skeleton = (Skeleton) mob;

        if (skeleton.getSkeletonType() == SkeletonType.WITHER) {
          switch (drop.getType()) {
            case SKULL_ITEM:
              drop.setDurability((short) 1);
              break;
            case ARROW:
              drop.setType(Material.COAL);
              break;
            default:
              break;
          }
        }

      default:
        break;
    }

    Misc.dropItem(mob.getLocation(), drop);
    CombatTools.dealDamage(mob, 1); // We may want to base the damage on the entity max health
  }
示例#6
0
 public static double getMaxHpByEntity(LivingEntity e) {
   switch (e.getType()) {
     case BLAZE:
       return hpOfBlaze;
     case CAVE_SPIDER:
       return hpOfCaveSpider;
     case CHICKEN:
       return hpOfChicken;
     case COW:
       return hpOfCow;
     case CREEPER:
       return hpOfCreeper;
     case ENDERMAN:
       return hpOfEnderman;
     case ENDER_DRAGON:
       return hpOfEnderDragon;
     case GHAST:
       return hpOfGhast;
     case GIANT:
       return hpOfGiant;
     case IRON_GOLEM:
       return hpOfIronGolem;
     case MAGMA_CUBE:
       int size = ((MagmaCube) e).getSize();
       switch (size) {
         case 1:
           return hpOfMagmaCubeTiny;
         case 2:
           return hpOfMagmaCubeSmall;
         case 3:
         case 4:
           return hpOfMagmaCubeBig;
       }
       if (size >= 3) {
         return hpOfMagmaCubeBig;
       }
       return 0;
     case MUSHROOM_COW:
       return hpOfMooshroom;
     case OCELOT:
       return hpOfOcelot;
     case PIG:
       return hpOfPig;
     case PIG_ZOMBIE:
       return hpOfZombiePigman;
     case SHEEP:
       return hpOfSheep;
     case SILVERFISH:
       return hpOfSilverfish;
     case SKELETON:
       Skeleton sk = (Skeleton) e;
       if (sk.getSkeletonType() == SkeletonType.WITHER) {
         return hpOfWitherSkeleton;
       } else {
         return hpOfSkeleton;
       }
     case WITHER:
       return hpOfWither;
     case SLIME:
       int s = ((Slime) e).getSize();
       switch (s) {
         case 1:
           return hpOfSlimeTiny;
         case 2:
           return hpOfSlimeSmall;
       }
       if (s >= 3) {
         return hpOfSlimeBig;
       }
     case SNOWMAN:
       return hpOfSnowGolem;
     case SPIDER:
       return hpOfSpider;
     case SQUID:
       return hpOfSquid;
     case WITCH:
       return hpOfWitch;
     case HORSE:
       return hpOfHorse;
     case VILLAGER:
       return hpOfVillager;
     case WOLF:
       if (((Wolf) e).isTamed()) {
         return hpOfWolfTamed;
       } else {
         return hpOfWolf;
       }
     case ZOMBIE:
       if (e instanceof Zombie) {
         Zombie z = (Zombie) e;
         if (z.isVillager()) {
           if (z.isBaby()) {
             return hpOfZombieBabyVillager;
           } else {
             return hpOfZombieVillager;
           }
         } else {
           if (z.isBaby()) {
             return hpOfBabyZombie;
           } else {
             return hpOfZombie;
           }
         }
       } else {
         return e.getMaxHealth();
       }
     case BAT:
       return hpOfBat;
     default:
       break;
   }
   return e.getMaxHealth();
 }
示例#7
0
  protected SpellResult alterEntity(Entity entity) {
    EntityType entityType = entity.getType();
    switch (entityType) {
      case PAINTING:
        registerModified(entity);
        Painting painting = (Painting) entity;
        Art[] artValues = Art.values();
        Art oldArt = painting.getArt();
        Art newArt = oldArt;
        int ordinal = (oldArt.ordinal() + 1);
        for (int i = 0; i < artValues.length; i++) {
          newArt = artValues[ordinal++ % artValues.length];
          painting.setArt(newArt);
          newArt = painting.getArt();
          if (oldArt != newArt) {
            break;
          }
        }
        if (oldArt == newArt) {
          return SpellResult.FAIL;
        }
        mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
        break;
      case ITEM_FRAME:
        ItemFrame itemFrame = (ItemFrame) entity;
        ItemStack frameItem = itemFrame.getItem();
        if (frameItem == null || frameItem.getType() != Material.MAP) {
          return SpellResult.NO_TARGET;
        }
        short data = frameItem.getDurability();
        data++;
        MapView mapView = DeprecatedUtils.getMap(data);
        if (mapView == null) {
          data = 0;
          mapView = DeprecatedUtils.getMap(data);
          if (mapView == null) {
            return SpellResult.NO_TARGET;
          }
        }
        registerModified(entity);
        frameItem.setDurability(data);
        itemFrame.setItem(frameItem);
        break;
      case HORSE:
        registerModified(entity);
        Horse horse = (Horse) entity;

        Color color = horse.getColor();
        Color[] colorValues = Color.values();
        color = colorValues[(color.ordinal() + 1) % colorValues.length];

        Variant variant = horse.getVariant();
        Variant[] variantValues = Variant.values();
        variant = variantValues[(variant.ordinal() + 1) % variantValues.length];

        Style horseStyle = horse.getStyle();
        Style[] styleValues = Style.values();
        horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];

        horse.setStyle(horseStyle);
        horse.setColor(color);
        horse.setVariant(variant);
        break;
      case OCELOT:
        registerModified(entity);
        Ocelot ocelot = (Ocelot) entity;
        Type catType = ocelot.getCatType();
        Type[] typeValues = Type.values();
        catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
        ocelot.setCatType(catType);
        break;
      case VILLAGER:
        registerModified(entity);
        Villager villager = (Villager) entity;
        Profession profession = villager.getProfession();
        Profession[] professionValues = Profession.values();
        profession = professionValues[(profession.ordinal() + 1) % professionValues.length];
        villager.setProfession(profession);
        break;
      case WOLF:
        registerModified(entity);
        Wolf wolf = (Wolf) entity;
        DyeColor wolfColor = wolf.getCollarColor();
        DyeColor[] wolfColorValues = DyeColor.values();
        wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
        wolf.setCollarColor(wolfColor);
        break;
      case SHEEP:
        registerModified(entity);
        Sheep sheep = (Sheep) entity;
        DyeColor dyeColor = sheep.getColor();
        DyeColor[] dyeColorValues = DyeColor.values();
        dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
        sheep.setColor(dyeColor);
        break;
      case SKELETON:
        registerModified(entity);
        Skeleton skeleton = (Skeleton) entity;
        SkeletonType skeletonType = skeleton.getSkeletonType();
        SkeletonType[] skeletonTypeValues = SkeletonType.values();
        skeletonType = skeletonTypeValues[(skeletonType.ordinal() + 1) % skeletonTypeValues.length];
        skeleton.setSkeletonType(skeletonType);
        break;
      default:
        return SpellResult.NO_TARGET;
    }
    ;
    registerForUndo();
    return SpellResult.CAST;
  }
示例#8
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));
      }
    }
  }
示例#9
0
  public static String entityName(Entity entity, Player player) {

    if (entity instanceof Bat) {
      return "bat";
    }

    if (entity instanceof Blaze) {
      return "blaze";
    }

    if (entity instanceof Player) {
      return "player";
    }

    if (entity instanceof Chicken) {
      return "chicken";
    }

    if (entity instanceof CaveSpider) {
      return "cavespider";
    }

    if (entity instanceof Cow) {
      if (entity.getType().equals(EntityType.MUSHROOM_COW)) return "mooshroom_cow";
      return "cow";
    }

    if (entity instanceof Creeper) {
      Creeper creeper = (Creeper) entity;
      if (creeper.isPowered()) return "electrifiedcreeper";
      return "creeper";
    }

    if (entity instanceof EnderDragon) {
      return "enderdragon";
    }

    if (entity instanceof Enderman) {
      return "enderman";
    }

    if (entity instanceof Ghast) {
      return "ghast";
    }

    if (entity instanceof Giant) {
      return "giant";
    }

    if (entity instanceof IronGolem) {
      return "irongolem";
    }

    if (entity instanceof MagmaCube) {
      return "magmacube";
    }

    if (entity instanceof Zombie) {
      Zombie zombie = (Zombie) entity;
      if (entity.getType().equals(EntityType.PIG_ZOMBIE)) return "pigzombie";
      if (zombie.isVillager()) return "villagerzombie";
      if (zombie.isBaby()) return "babyzombie";
      return "zombie";
    }

    if (entity instanceof Skeleton) {
      Skeleton skeleton = (Skeleton) entity;
      if ((skeleton.getSkeletonType().equals(Skeleton.SkeletonType.WITHER))
          || (skeleton.getSkeletonType().getId() == 1)) {
        return "witherskeleton";
      }
      return "skeleton";
    }

    if (entity instanceof Silverfish) {
      return "silverfish";
    }

    if (entity instanceof Spider) {
      return "spider";
    }

    if (entity instanceof Witch) {
      return "witch";
    }

    if (entity instanceof Wither) {
      return "wither";
    }

    if (entity instanceof Monster) {
      return "monster";
    }

    if (entity instanceof Ocelot) {
      Ocelot ocelot = (Ocelot) entity;
      if (ocelot.isTamed()) {
        if ((ocelot.getOwner() instanceof Player)
            && ((Player) ocelot.getOwner()).getName().equalsIgnoreCase(player.getName())) {
          return "ocelot_tamed_self";
        } else {
          return "ocelot_tamed";
        }
      }
      return "ocelot_neutral";
    }

    if (entity instanceof Pig) {
      return "pig";
    }

    if (entity instanceof Sheep) {
      return "sheep";
    }

    if (entity instanceof Slime) {
      return "slime";
    }

    if (entity instanceof Snowman) {
      return "snowgolem";
    }

    if (entity instanceof Squid) {
      return "squid";
    }

    if (entity instanceof Villager) {
      return "villager";
    }

    if (entity instanceof Wolf) {
      Wolf wolf = (Wolf) entity;
      if (wolf.isTamed()) {
        if ((wolf.getOwner() instanceof Player)
            && ((Player) wolf.getOwner()).getName().equalsIgnoreCase(player.getName())) {
          return "wolf_self_tamed";
        } else {
          return "wolf_tamed";
        }
      }
      return "wolf_neutral";
    }

    return "";
  }
  @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);
  }
示例#11
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;
    }
示例#12
0
  public DeathDetail(EntityDeathEvent event) {
    player = (Player) event.getEntity();
    entityDeathEvent = event;
    // Support for setHealth(0) which is used by essentials to do a suicide
    try {
      EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause();
      if (damageEvent instanceof EntityDamageByEntityEvent) {
        Entity damager = ((EntityDamageByEntityEvent) damageEvent).getDamager();
        log.debug("damager", damager.toString());
        if (damager instanceof Player) {
          log.debug("Killed by an other player");
          if (((Player) damager).getItemInHand().getType().equals(Material.AIR)) {
            causeOfDeath = DeathEventType.PVP_FISTS;
          } else {
            causeOfDeath = DeathEventType.PVP;
          }
          murderWeapon = ((Player) damager).getItemInHand().getType().toString();
          killer = (Player) damager;
        } else if (damager instanceof Creature || damager instanceof Slime) {
          log.debug("We have a creature or slime");
          if (damager instanceof Tameable && ((Tameable) damager).isTamed()) {
            causeOfDeath = DeathEventType.PVP_TAMED;
            murderWeapon = damager.getType().toString();
            killer = (Player) ((Tameable) damager).getOwner();
          } else {
            try {
              causeOfDeath = DeathEventType.valueOf(damager.getType().toString());
              if (damager instanceof Skeleton) {
                Skeleton skeleton = (Skeleton) damager;
                causeOfDeath =
                    skeleton.getSkeletonType() == SkeletonType.WITHER
                        ? DeathEventType.WITHER_SKELETON
                        : DeathEventType.SKELETON;
              } else if (damager instanceof Zombie) {
                Zombie zombie = (Zombie) damager;
                causeOfDeath =
                    zombie.isVillager() ? DeathEventType.ZOMBIE_VILLAGER : DeathEventType.ZOMBIE;
              }
            } catch (IllegalArgumentException iae) {
              log.severe("Please notify the developer of the following Error:");
              log.severe(
                  "The following damager is not correctly implemented: "
                      + damager.getType().toString());
              causeOfDeath = DeathEventType.UNKNOWN;
            }
            log.debug("and it is: " + causeOfDeath);
          }
        } else if (damager instanceof Projectile) {
          log.debug("this is a projectile");
          log.debug("shooter", ((Projectile) damager).getShooter());
          if (((Projectile) damager).getShooter() instanceof Player) {
            causeOfDeath = DeathEventType.PVP;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
            killer = (Player) ((Projectile) damager).getShooter();
          }
          if (((Projectile) damager).getShooter() == null) {
            // let's assume that null will only be caused by a dispenser!
            causeOfDeath = DeathEventType.DISPENSER;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
          }
          if (((Projectile) damager).getShooter().toString().equalsIgnoreCase("CraftSkeleton")) {
            causeOfDeath = DeathEventType.SKELETON;
            murderWeapon = ((Projectile) damager).toString().replace("Craft", "");
          }

        } else if (damager instanceof TNTPrimed) {
          causeOfDeath = DeathEventType.BLOCK_EXPLOSION;
        } else {
          log.info("unknown enitity damager" + damager);
        }
      } else if (damageEvent != null) {
        log.debug("DamageEvent is not by Entity");
        try {
          causeOfDeath = DeathEventType.valueOf(damageEvent.getCause().toString());
        } catch (IllegalArgumentException e) {
          causeOfDeath = DeathEventType.UNKNOWN;
        }
      }
    } catch (NullPointerException npe) {
      log.debug("normal detection of damageevent failed", npe);
      log.debug("assuming you did use essentials or similar");
      log.debug("which uses setHealth(0) to kill people");
      log.info("Deathcause is being set to SUICIDE!");
      causeOfDeath = DeathEventType.SUICIDE;
      murderWeapon = "Essentials";
    }

    if (causeOfDeath == null) {
      causeOfDeath = DeathEventType.UNKNOWN;
      murderWeapon = "unknown";
    }
    log.debug("causeOfDeath", causeOfDeath);
    log.debug("murderWeapon", murderWeapon);
    log.debug("killer", killer);
  }