View difference between Paste ID: W2b8tJYD and 62uEB69S
SHOW: | | - or go back to the newest paste.
1
package com.applecraftserver.aprx.minecave.zombiewaves;
2
3
import com.applecraftserver.aprx.minecave.zombiewaves.files.ItemAliases;
4
import java.util.ArrayList;
5
import java.util.List;
6
import java.util.Map.Entry;
7
import org.bukkit.Material;
8
import org.bukkit.configuration.ConfigurationSection;
9
import org.bukkit.enchantments.Enchantment;
10
import org.bukkit.inventory.ItemStack;
11
import org.bukkit.inventory.meta.ItemMeta;
12
13
/**
14
 *
15
 * @author aprx
16
 */
17
public class ItemParser {
18
	private static MCZombieWaves plugin;
19
	
20
	public ItemParser(MCZombieWaves pl) {
21
		plugin = pl;
22
	}
23
	
24
	public static ItemStack[] parse(ConfigurationSection section) {
25
		ItemAliases items = plugin.getItems();
26
		List<ItemStack> toReturn = new ArrayList();
27
		for (String rootitem : section.getKeys(false)) {
28
			if (rootitem.equalsIgnoreCase("air")) {
29
				toReturn.add(new ItemStack(Material.AIR));
30
				continue;
31
			}
32
			if (items.getItemByAlias(rootitem) == null)
33
				continue;
34
			ConfigurationSection itemSection = section.getConfigurationsection(rootitem);
35
			ItemStack item = items.getItemByAlias(rootitem);
36-
			item.setAmount(section.getInt(rootitem + ".count", 1));
36+
			item.setAmount(itemSection.getInt("count", 1));
37
			if (itemSection.isSet("damage")) {
38-
			meta.setLore(section.getStringList(rootitem + ".lore"));
38+
				item.setDurability((short) itemSection.getInt("damage", 0));
39-
			if (section.isSet(rootitem + ".name"))
39+
40-
				meta.setDisplayName(section.getString(rootitem + ".name"));
40+
			meta.setLore(itemSection.getStringList("lore"));
41-
			if (section.isSet(rootitem + ".ench")) {
41+
			if (itemSection.isSet("name"))
42-
				for (Entry ench : section.getConfigurationSection(rootitem + ".ench").getValues(false).entrySet()) {
42+
				meta.setDisplayName(itemSection.getString("name"));
43
			if (itemSection.isSet("ench")) {
44
				for (Entry ench : section.getConfigurationSection("ench").getValues(false).entrySet()) {
45
					if (Enchantment.getByName(ench.getKey().toString()) == null)
46
						continue;
47
					try {
48
						Integer.parseInt(ench.getValue().toString());
49
					} catch (Exception e) {
50
						continue;
51
					}
52
					item.addUnsafeEnchantment(Enchantment.getByName(ench.getKey().toString()), Integer.parseInt(ench.getValue().toString()));
53-
			item.setDurability((short) section.getInt(rootitem + ".damage", 0));
53+
54
			}
55
			item.setItemMeta(meta);
56
			toReturn.add(item);
57
		}
58
		
59
		
60
		return (ItemStack[]) toReturn.toArray();
61
	}
62
	
63
}