@Override protected void execute(Event e) { if (entity != null) { if (marker == 1) { if (Ageable.class.isAssignableFrom(entity.getSingle(e).getClass())) { ((Ageable)entity.getSingle(e)).setBaby(); } else if (Zombie.class.isAssignableFrom(entity.getSingle(e).getClass())) { ((Zombie)entity.getSingle(e)).setBaby(true); } } else { if (Ageable.class.isAssignableFrom(entity.getSingle(e).getClass())) { ((Ageable)entity.getSingle(e)).setAdult(); } else if (Zombie.class.isAssignableFrom(entity.getSingle(e).getClass())) { ((Zombie)entity.getSingle(e)).setBaby(false); } } } }
public boolean check(Event e) { if (entity.getSingle(e) instanceof Ageable) { if (((Ageable)entity.getSingle(e)).isAdult()) { return isNegated(); } else { return !isNegated(); } } else if (entity.getSingle(e) instanceof Zombie) { if (((Zombie)entity.getSingle(e)).isBaby()) { return !isNegated(); } else { return isNegated(); } } return false; }
/** * {@inheritDoc} */ public BabyMenu(Plot plot, Entity entity) { super(plot, entity); ItemStack baby = new ItemStack(Material.EGG); ItemMeta babyMeta = baby.getItemMeta(); babyMeta.setDisplayName(ChatColor.GREEN + "Change to baby/adult"); baby.setItemMeta(babyMeta); insertItem(baby, event -> { if (entity instanceof Ageable) { Ageable ageable = (Ageable) entity; if (ageable.isAdult()) ageable.setBaby(); else ageable.setAdult(); } else if (entity instanceof Zombie) { Zombie zombie = (Zombie) entity; zombie.setBaby(!zombie.isBaby()); } event.setCancelled(true); }, 0); }
protected void tick(Block b) throws Exception { for (Entity n: me.mrCookieSlime.Slimefun.holograms.AnimalGrowthAccelerator.getArmorStand(b).getNearbyEntities(3D, 3D, 3D)) { if (n instanceof Ageable && !((Ageable) n).isAdult()) { for (int slot: getInputSlots()) { if (SlimefunManager.isItemSimiliar(BlockStorage.getInventory(b).getItemInSlot(slot), SlimefunItems.ORGANIC_FOOD, false)) { if (ChargableBlock.getCharge(b) < getEnergyConsumption()) return; ChargableBlock.addCharge(b, -getEnergyConsumption()); BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1)); ((Ageable) n).setAge(((Ageable) n).getAge() + 2000); if (((Ageable) n).getAge() > 0) ((Ageable) n).setAge(0); ParticleEffect.VILLAGER_HAPPY.display(((LivingEntity) n).getEyeLocation(), 0.2F, 0.2F, 0.2F, 0, 8); return; } } } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) { Entity damager = event.getDamager(); Location l = BukkitUtil.getLocation(damager); if (!PS.get().hasPlotArea(l.getWorld())) { return; } Entity victim = event.getEntity(); if (!entityDamage(damager, victim)) { if (event.isCancelled()) { if (victim instanceof Ageable) { Ageable ageable = (Ageable) victim; if (ageable.getAge() == -24000) { ageable.setAge(0); ageable.setAdult(); } } } event.setCancelled(true); } }
@Override public void applyMountData(Entity entity) { super.applyMountData(entity); if (!(entity instanceof Ageable)) { return; } Ageable ageable = (Ageable) entity; if (adult) { ageable.setAdult(); } else { ageable.setBaby(); } ageable.setAgeLock(true); }
protected void tick(Block b) throws Exception { for(Iterator iterator = me.mrCookieSlime.Slimefun.holograms.AnimalGrowthAccelerator.getArmorStand(b).getNearbyEntities(3D, 3D, 3D).iterator(); iterator.hasNext();) { Entity n = (Entity)iterator.next(); if((n instanceof Ageable) && !((Ageable)n).isAdult()) { int ai[]; int j = (ai = getInputSlots()).length; for(int i = 0; i < j; i++) { int slot = ai[i]; if(SlimefunManager.isItemSimiliar(BlockStorage.getInventory(b).getItemInSlot(slot), SlimefunItems.ORGANIC_FOOD, false)) { if(ChargableBlock.getCharge(b) < getEnergyConsumption()) return; ChargableBlock.addCharge(b, -getEnergyConsumption()); BlockStorage.getInventory(b).replaceExistingItem(slot, InvUtils.decreaseItem(BlockStorage.getInventory(b).getItemInSlot(slot), 1)); ((Ageable)n).setAge(((Ageable)n).getAge() + 2000); if(((Ageable)n).getAge() > 0) ((Ageable)n).setAge(0); ParticleEffect.VILLAGER_HAPPY.display(((LivingEntity)n).getEyeLocation(), 0.2F, 0.2F, 0.2F, 0.0F, 8); return; } } } } }
public void update() { if (entity != null) { //((CraftEntity) entity).getHandle().setEquipment(4, new net.minecraft.server.v1_5_R2.ItemStack(Item.DIAMOND_HELMET)); //Chat.server(((CraftEntity) entity).getHandle().getEquipment().toString()); Player owner = Bukkit.getPlayerExact(this.owner); if (owner == null) return; entity.setCustomName(nameColor + name); entity.setCustomNameVisible(true); if (entity instanceof Tameable) { tamed = true; ((Tameable) entity).setTamed(true); ((Tameable) entity).setOwner(owner); } if (entity instanceof Ageable && age != null) { if (getAge() == Age.BABY) ((Ageable) entity).setBaby(); ((Ageable) entity).setAgeLock(true); } if (entity instanceof Zombie && age != null) { if (getAge() == Age.BABY) ((Zombie) entity).setBaby(true); } if (entity instanceof Sheep && color != null) { ((Sheep) entity).setColor(getColor()); } } }
@SuppressWarnings("unchecked") public final boolean isInstance(final @Nullable Entity e) { if (e == null) return false; if (!baby.isUnknown() && e instanceof Ageable && ((Ageable) e).isAdult() != baby.isFalse()) return false; return getType().isInstance(e) && match((E) e); }
public static boolean isFeedable(Entity n) throws Exception { if (!(n instanceof org.bukkit.entity.Animals && ((Ageable) n).isAdult() && ((Ageable) n).canBreed())) return false; Object handle = ReflectionUtils.getHandle(CraftObject.ANIMALS, n); Field f = ReflectionUtils.tryField(ReflectionUtils.getClass(PackageName.NMS, "EntityAnimal"), "bv", "bw","bx"); f.setAccessible(true); return f.getInt(handle) < 1; }
@Override @Nullable protected Boolean[] get(Event e) { if (entity.getSingle(e) instanceof Ageable) { if (entity != null) { return new Boolean[]{((Ageable)entity.getSingle(e)).getAgeLock()}; } } return null; }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode){ if (mode == ChangeMode.SET) { if (entity.getSingle(e) instanceof Ageable) { if (entity != null) { ((Ageable)entity.getSingle(e)).setAgeLock((Boolean)delta[0]); } } } }
@Override @Nullable protected Number[] get(Event e) { if (entity.getSingle(e) instanceof Ageable) { if (entity != null) { return new Number[]{((Ageable)entity.getSingle(e)).getAge()}; } } return null; }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode){ if (mode == ChangeMode.SET) { if (entity.getSingle(e) instanceof Ageable) { if (entity != null) { Number age = (Number)delta[0]; ((Ageable)entity.getSingle(e)).setAge(age.intValue()); } } } }
public boolean check(Event e) { if (entity.getSingle(e) instanceof Ageable) { if (((Ageable)entity.getSingle(e)).canBreed()) { return isNegated(); } else { return !isNegated(); } } return false; }
public int getAge() { if (getHandle() instanceof net.canarymod.api.entity.living.Ageable) { return ((net.canarymod.api.entity.living.Ageable) getHandle()).getGrowingAge(); } else { return 0; } }
private void restoreAgeable(final Ageable entity) { if (!this.aged.adult) { entity.setBaby(); } if (this.aged.locked) { entity.setAgeLock(this.aged.locked); } entity.setAge(this.aged.age); }
private void restoreAgeable(Ageable entity) { if (!this.aged.adult) { entity.setBaby(); } entity.setAgeLock(this.aged.locked); if (this.aged.age > 0) { entity.setAge(this.aged.age); } }
public AgeableAnimal(Entity entity) { PreCon.notNull(entity); PreCon.isValid(entity instanceof Ageable, "org.bukkit.entity.Ageable expected."); Ageable ageable = (Ageable)entity; _age = ageable.getAge(); _ageLock = ageable.getAgeLock(); }
@Override public boolean apply(Entity entity) { PreCon.notNull(entity); PreCon.isValid(entity instanceof Ageable, "org.bukkit.entity.Ageable expected."); Ageable ageable = (Ageable)entity; ageable.setAge(_age); ageable.setAgeLock(_ageLock); return true; }
@Override protected Entity spawnGuest(EntityType type) { Entity guest = super.spawnGuest(type); if (guest instanceof Ageable && guestBabyCount > 0) { Ageable baby = (Ageable) guest; baby.setBaby(); --guestBabyCount; } return guest; }
@Override public Ageable getBukkitEntity() { return (Ageable) super.getBukkitEntity(); }
@Override @Nullable protected Boolean[] get(Event e) { return new Boolean[]{((Ageable)entity.getSingle(e)).canBreed()}; }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode){ if (mode == ChangeMode.SET) { ((Ageable)entity.getSingle(e)).setBreed((Boolean)delta[0]); } }
public void setAge(int age) { if (getHandle() instanceof net.canarymod.api.entity.living.Ageable) { ((net.canarymod.api.entity.living.Ageable) getHandle()).setGrowingAge(age); } }
/** * Assembles an ArrayList of the properties for the specified Entity that * is to be used for a spawn egg. All instanceof checks are done internally * by the LorePackager, so no type checking is required prior to calling * this method. Null Entities will throw an IllegalArgumentException. <b>The * actual ArrayList is returned by {@link #getLore() LorePacker.getLore()}. * </b> * @param livingEntity - The Entity to assemble a lore for. * @return An ArrayList of Strings * @throws IllegalArgumentException If entity parameter is null */ public LorePacker(LivingEntity livingEntity) throws IllegalArgumentException { if (livingEntity == null) { throw new IllegalArgumentException("Can't assemble lore for a null entity!"); } lore = new ArrayList<String>(); // This needs to always be on top of an egg's lore lore.add("Identifier: SimpleEgg." + livingEntity.getType().getEntityClass().getSimpleName() + "." + Main.getSelf().getDescription().getVersion()); lore.addAll(livingEntity(livingEntity)); if (livingEntity instanceof Ageable) { lore.addAll(ageable((Ageable) livingEntity)); if (livingEntity instanceof Sheep) { lore.addAll(sheep((Sheep) livingEntity)); } else if (livingEntity instanceof Pig) { lore.addAll(pig((Pig) livingEntity)); } else if (livingEntity instanceof Rabbit) { lore.addAll(rabbit((Rabbit) livingEntity)); } else if (livingEntity instanceof Villager) { lore.addAll(villager((Villager) livingEntity)); } else if (livingEntity instanceof Tameable) { lore.addAll(tameable((Tameable) livingEntity)); if (livingEntity instanceof AbstractHorse) { lore.addAll(abstractHorse((AbstractHorse) livingEntity)); if (livingEntity instanceof Horse) { lore.addAll(horse((Horse) livingEntity)); } else if (livingEntity instanceof ChestedHorse) { lore.addAll(chestedHorse((ChestedHorse) livingEntity)); if (livingEntity instanceof Llama) { lore.addAll(llama((Llama) livingEntity)); } } } else if (livingEntity instanceof Sittable) { lore.addAll(sittable((Sittable) livingEntity)); if (livingEntity instanceof Wolf) { lore.addAll(wolf((Wolf) livingEntity)); } else if (livingEntity instanceof Ocelot) { lore.addAll(ocelot((Ocelot) livingEntity)); } else if (livingEntity instanceof Parrot) { lore.addAll(parrot((Parrot) livingEntity)); } } } } else if (livingEntity instanceof Slime) { lore.addAll(slime((Slime) livingEntity)); } else if (livingEntity instanceof Creeper) { lore.addAll(creeper((Creeper) livingEntity)); } else if (livingEntity instanceof Zombie) { lore.addAll(zombie((Zombie) livingEntity)); if (livingEntity instanceof PigZombie) { lore.addAll(pigZombie((PigZombie) livingEntity)); } else if (livingEntity instanceof ZombieVillager) { lore.addAll(zombieVillager((ZombieVillager) livingEntity)); } } else if (livingEntity instanceof Spellcaster) { lore.addAll(spellCaster((Spellcaster) livingEntity)); } else if (livingEntity instanceof IronGolem) { lore.addAll(ironGolem((IronGolem) livingEntity)); } else if (livingEntity instanceof Snowman) { lore.addAll(snowman((Snowman) livingEntity)); } }
public void storeAgeable(final Ageable aged) { this.aged = new AgeableStats(); this.aged.age = aged.getAge(); this.aged.locked = aged.getAgeLock(); this.aged.adult = aged.isAdult(); }
public void storeAgeable(Ageable aged) { this.aged = new AgeableStats(); this.aged.age = aged.getAge(); this.aged.locked = aged.getAgeLock(); this.aged.adult = aged.isAdult(); }
@Override public boolean spawn() { // check if our current old entity is still valid: if (this.isActive()) return true; if (entity != null) { // clean up metadata before replacing the currently stored entity with a new one: this.removeShopkeeperMetadata(entity); } // prepare location: World world = Bukkit.getWorld(shopkeeper.getWorldName()); Location location = new Location(world, shopkeeper.getX() + 0.5D, shopkeeper.getY() + 0.5D, shopkeeper.getZ() + 0.5D); // find old shopkeeper entity, else spawn a new one: if (!this.searchOldEntity(location)) { // TODO check if the block is passable before spawning there? // try to bypass entity-spawn blocking plugins: EntityType entityType = this.getEntityType(); ShopkeepersPlugin.getInstance().forceCreatureSpawn(location, entityType); entity = (LivingEntity) world.spawnEntity(location, entityType); uuid = entity.getUniqueId().toString(); } if (this.isActive()) { // assign metadata for easy identification by other plugins: this.assignShopkeeperMetadata(entity); this.setName(shopkeeper.getName()); // configure some entity attributes: entity.eject(); // some entities might automatically mount on nearby entities (like baby zombies on chicken) entity.setRemoveWhenFarAway(false); entity.setCanPickupItems(false); // disable breeding: if (entity instanceof Ageable) { Ageable ageable = ((Ageable) entity); ageable.setBreed(false); ageable.setAgeLock(true); } // remove potion effects: for (PotionEffect potionEffect : entity.getActivePotionEffects()) { entity.removePotionEffect(potionEffect.getType()); } // overwrite AI: this.overwriteAI(); // apply sub type: this.applySubType(); // success: return true; } else { // failure: entity = null; return false; } }