public void setAgeProps(Ageable a, ISpawnableEntity data) { if (data.getAge(a) == -2) { a.setBaby(); } else if (data.getAge(a) == -1) { a.setAdult(); } else { a.setAge(data.getAge(a)); } }
@Override public void onSpawn() { if (npc.getBukkitEntity() instanceof Ageable) { Ageable entity = (Ageable) npc.getBukkitEntity(); entity.setAge(age); entity.setAgeLock(locked); ageable = entity; } else ageable = null; }
@EventHandler public void onEntityTameEvent(EntityTameEvent event) { /* Get the entity being tamed. */ LivingEntity entity = event.getEntity(); if (StackUtils.hasRequiredData(entity)) { /* Get the new quantity. Current size, less one (One being tamed) */ int newQuantity = StackUtils.getStackSize(entity) - 1; /* Clear the name of the entity that was just tamed. */ entity.setCustomName(""); /* If there are any mobs remaining in the stack, then peel em off to form a new stack. */ if (newQuantity > 0) { LivingEntity newEntity = getPlugin().getStackUtils().peelOffStack(entity, false); /* If there was an age in question, then assign it. */ if (newEntity instanceof Ageable) { ((Ageable) newEntity).setAge(((Ageable) event.getEntity()).getAge()); } /* * Yes I know the following aren't possible, but if someone uses a plugin that allows for taming of other mobs through NMS, * then this will account for that. */ /* If the stack had a colour, assign it. */ if (newEntity instanceof Colorable) { ((Colorable) newEntity).setColor(((Colorable) event.getEntity()).getColor()); } /* If it was a sheep, keep it's sheared status. */ if (newEntity instanceof Sheep) { ((Sheep) newEntity).setSheared(((Sheep) event.getEntity()).isSheared()); } } } }
@Nullable public E spawn(final Location loc) { assert loc != null; try { final E e = loc.getWorld().spawn(loc, getType()); if (e == null) throw new IllegalArgumentException(); if (baby.isTrue() && e instanceof Ageable) ((Ageable) e).setBaby(); set(e); return e; } catch (final IllegalArgumentException e) { if (Skript.testing()) Skript.error("Can't spawn " + getType().getName()); return null; } }
protected Entity setEntity(MageController controller, Entity entity) { this.entity = entity; if (noTarget) { entity.setMetadata("notarget", new FixedMetadataValue(controller.getPlugin(), true)); } if (customName != null) { entity.setCustomName(customName); entity.setCustomNameVisible(true); } if (entity instanceof LivingEntity) { ((LivingEntity) entity).setMaxHealth(1000.0); ((LivingEntity) entity).setHealth(1000.0); } if (entity instanceof Slime) { ((Slime) entity).setSize(1); } if (entity instanceof Ageable) { if (isBaby) { ((Ageable) entity).setBaby(); } else { ((Ageable) entity).setAdult(); } } else if (entity instanceof Zombie) { ((Zombie) entity).setBaby(isBaby); } else if (entity instanceof PigZombie) { ((PigZombie) entity).setBaby(isBaby); } else if (entity instanceof Slime && isBaby) { Slime slime = (Slime) entity; slime.setSize(0); } if (entity instanceof Horse) { Horse.Variant variant = Horse.Variant.UNDEAD_HORSE; if (variantName != null) { try { variant = Horse.Variant.valueOf(variantName.toUpperCase()); } catch (Exception ex) { } } else { variant = Horse.Variant.UNDEAD_HORSE; } ((Horse) entity).setVariant(variant); } if (entity instanceof Ocelot) { Ocelot ocelot = (Ocelot) entity; Ocelot.Type variant = Ocelot.Type.WILD_OCELOT; if (variantName != null) { try { variant = Ocelot.Type.valueOf(variantName.toUpperCase()); } catch (Exception ex) { } } else { variant = Ocelot.Type.WILD_OCELOT; } ocelot.setCatType(variant); } if (entity instanceof Sheep) { Sheep sheep = (Sheep) entity; DyeColor color = DyeColor.WHITE; if (variantName != null) { try { color = DyeColor.valueOf(variantName.toUpperCase()); } catch (Exception ex) { } } sheep.setColor(color); } if (entity instanceof Wolf) { Wolf wolf = (Wolf) entity; if (variantName != null) { // Only set collar color if a variant is set.. // this makes it a dog, versus a wolf. Technically. DyeColor color = DyeColor.RED; try { color = DyeColor.valueOf(variantName.toUpperCase()); wolf.setTamed(true); } catch (Exception ex) { } wolf.setCollarColor(color); } } targeting.ignoreEntity(entity); return entity; }
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; }
@Override public boolean toggle() { locked = !locked; if (isAgeable()) ageable.setAgeLock(locked); return locked; }
public void setAge(int age) { this.age = age; if (isAgeable()) { ageable.setAge(age); } }
@Override public void run() { if (!locked && isAgeable()) { age = ageable.getAge(); } }