Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.applecraftserver.aprx.minecave.zombiewaves;
- import com.applecraftserver.aprx.minecave.zombiewaves.files.ItemAliases;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map.Entry;
- import org.bukkit.Material;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- /**
- *
- * @author aprx
- */
- public class ItemParser {
- private static MCZombieWaves plugin;
- public ItemParser(MCZombieWaves pl) {
- plugin = pl;
- }
- public static ItemStack[] parse(ConfigurationSection section) {
- ItemAliases items = plugin.getItems();
- List<ItemStack> toReturn = new ArrayList();
- for (String rootitem : section.getKeys(false)) {
- if (rootitem.equalsIgnoreCase("air")) {
- toReturn.add(new ItemStack(Material.AIR));
- continue;
- }
- if (items.getItemByAlias(rootitem) == null)
- continue;
- ConfigurationSection itemSection = section.getConfigurationsection(rootitem);
- ItemStack item = items.getItemByAlias(rootitem);
- item.setAmount(itemSection.getInt("count", 1));
- if (itemSection.isSet("damage")) {
- item.setDurability((short) itemSection.getInt("damage", 0));
- ItemMeta meta = item.getItemMeta();
- meta.setLore(itemSection.getStringList("lore"));
- if (itemSection.isSet("name"))
- meta.setDisplayName(itemSection.getString("name"));
- if (itemSection.isSet("ench")) {
- for (Entry ench : section.getConfigurationSection("ench").getValues(false).entrySet()) {
- if (Enchantment.getByName(ench.getKey().toString()) == null)
- continue;
- try {
- Integer.parseInt(ench.getValue().toString());
- } catch (Exception e) {
- continue;
- }
- item.addUnsafeEnchantment(Enchantment.getByName(ench.getKey().toString()), Integer.parseInt(ench.getValue().toString()));
- }
- }
- item.setItemMeta(meta);
- toReturn.add(item);
- }
- return (ItemStack[]) toReturn.toArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement