public static ItemMeta parse(Element xml, ItemMeta source) { if (source instanceof BannerMeta) { return parseBanner(xml, (BannerMeta) source); } else if (source instanceof BookMeta) { return parseBook(xml, (BookMeta) source); } else if (source instanceof EnchantmentStorageMeta) { return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source); } else if (source instanceof FireworkMeta) { return parseFirework(xml, (FireworkMeta) source); } else if (source instanceof FireworkEffectMeta) { return parseFireworkEffect(xml, (FireworkEffectMeta) source); } else if (source instanceof LeatherArmorMeta) { return parseLeatherArmor(xml, (LeatherArmorMeta) source); } else if (source instanceof MapMeta) { return parseMap(xml, (MapMeta) source); } else if (source instanceof PotionMeta) { return parsePotion(xml, (PotionMeta) source); } else if (source instanceof SkullMeta) { return parseSkull(xml, (SkullMeta) source); } else if (source instanceof SpawnEggMeta) { return parseSpawnEgg(xml, (SpawnEggMeta) source); } return source; }
/** * Makes a call to the ExpenseHandler, generates a SpawnEgg, assigns data to * it and drops it where the mob used to be. * @param entry - The EggTrackerEntry we are dealing with for this SpawnEgg. */ public void makeSpawnEgg(EggTrackerEntry entry) { Player player = entry.getPlayer(); LivingEntity livingEntity = entry.getEntity(); expenseHandler.execute(player); ItemStack stack = new ItemStack(Material.MONSTER_EGG); SpawnEggMeta meta = (SpawnEggMeta) stack.getItemMeta(); meta.setSpawnedType(livingEntity.getType()); String name = Text.a + livingEntity.getType().getEntityClass().getSimpleName(); if (livingEntity.getCustomName() != null) { name += ": " + livingEntity.getCustomName(); } meta.setDisplayName(name); meta.setLore(new LorePacker(livingEntity).getLore()); stack.setItemMeta(meta); livingEntity.getWorld().dropItem(livingEntity.getLocation(), stack); livingEntity.remove(); player.sendMessage(String.format("%s%s%s%s captured successfully!", Text.tag, Text.a, livingEntity.getType().getEntityClass().getSimpleName(), Text.b)); }
@Override public ItemStack getSpawnEgg(EntityType type, int amount) { ItemStack egg = new ItemStack(Material.MONSTER_EGG, amount); SpawnEggMeta spm = (SpawnEggMeta)egg.getItemMeta(); spm.setSpawnedType(type); egg.setItemMeta(spm); return egg; }
private ItemStack getHorseItem() { ItemStack item = new ItemStack(Material.MONSTER_EGG); SpawnEggMeta meta = (SpawnEggMeta) item.getItemMeta(); meta.setSpawnedType(EntityType.HORSE); item.setItemMeta(meta); return item; }
public static SpawnEggMeta parseSpawnEgg(Element xml, SpawnEggMeta source) { Element spawnerEgg = xml.getChild("spawner-egg"); if (spawnerEgg != null) { EntityType entity = XMLEntity.parse(spawnerEgg.getTextNormalize()); if (entity != null) { source.setSpawnedType(entity); } } return source; }
@EventHandler public void eggUseOnEntity(PlayerInteractEntityEvent event) { ItemStack stack = event.getPlayer().getInventory().getItemInMainHand(); ItemMeta meta = stack.getItemMeta(); if (meta instanceof SpawnEggMeta) { SpawnEggMeta spawnEggMeta = (SpawnEggMeta) meta; if (isSimpleEgg(spawnEggMeta)) { event.getPlayer().sendMessage(Text.tag + "You cannot use a SimpleEgg to make babies out of other adult mobs."); event.setCancelled(true); } } }
/** * Check if an egg's identifier line exists and the version on it matches * the current plugin version. * @return True if the egg is current, false otherwise. */ private boolean isVersionCurrent(SpawnEggMeta meta) { if (isSimpleEgg(meta)) { if (ChatColor.stripColor(meta.getLore().get(0)).endsWith(Main.getSelf().getDescription().getVersion())) { return true; } } return false; }
public static String getEgg(ItemStack itemStack) { if (itemStack != null) { if (itemStack.getType() == Material.MONSTER_EGG) { ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta instanceof SpawnEggMeta) { SpawnEggMeta spawnEggMeta = (SpawnEggMeta) itemMeta; return spawnEggMeta.getSpawnedType() != null ? StringUtilities.capitalizeFully(spawnEggMeta.getSpawnedType().name()) : null; } } } return null; }
@Override public SerialItemData initialize(ItemStack stack) { ItemMeta meta = stack.getItemMeta(); if(meta instanceof SpawnEggMeta) { valid = true; entity = ((SpawnEggMeta)meta).getSpawnedType().name(); } return this; }
@Override public ItemStack build(ItemStack stack) { if(valid) { SpawnEggMeta meta = (SpawnEggMeta)stack.getItemMeta(); meta.setSpawnedType(EntityType.valueOf(entity)); stack.setItemMeta(meta); } return stack; }
@Override public void processMeta(Player player, ItemMeta m) {//Add support for older versions super.processMeta(player, m); SpawnEggMeta meta = (SpawnEggMeta) m; meta.setSpawnedType(type); }
public SpawnEggMetaStorage(SpawnEggMeta meta) { super(meta); }
/** * Check if an egg's identifier line exists, regardless of version. * @return True if it has an identifier of any version, false otherwise. */ private boolean isSimpleEgg(SpawnEggMeta meta) { return meta.hasLore() && ChatColor.stripColor(meta.getLore().get(0)).startsWith("Identifier: SimpleEgg." + meta.getSpawnedType().getEntityClass().getSimpleName()); }