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;
- ItemStack item = items.getItemByAlias(rootitem);
- item.setAmount(section.getInt(rootitem + ".count", 1));
- ItemMeta meta = item.getItemMeta();
- meta.setLore(section.getStringList(rootitem + ".lore"));
- if (section.isSet(rootitem + ".name"))
- meta.setDisplayName(section.getString(rootitem + ".name"));
- if (section.isSet(rootitem + ".ench")) {
- for (Entry ench : section.getConfigurationSection(rootitem + ".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.setDurability((short) section.getInt(rootitem + ".damage", 0));
- item.setItemMeta(meta);
- toReturn.add(item);
- }
- return (ItemStack[]) toReturn.toArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement