Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void parse(ConfigurationSection config) {
- for (String key : config.getKeys(false)) {
- ConfigurationSection section = config.getConfigurationSection(key);
- Map<ItemStack, Double> stacks = new HashMap<>();
- for (Map.Entry<String, Object> entr : section.getValues(false).entrySet()) {
- ConfigurationSection dir = section.getConfigurationSection(entr.getKey());
- double chance = dir.getDouble("chance", 0);
- String material = dir.getString("material", "stone").toUpperCase();
- int amount = dir.getInt("amount", 1);
- int damage = dir.getInt("damage", 0);
- Material mater;
- try {
- mater = Material.valueOf(material);
- } catch (IllegalArgumentException ex) {
- LobbyPvP.log.warning("Can't find material " + material);
- mater = Material.STONE;
- }
- ItemStack stack = new ItemStack(mater, amount, (short) damage);
- if (dir.isString("name")) {
- String stackName = dir.getString("name");
- stack = ItemUtil.setName(stack, stackName);
- }
- if (dir.isList("lore")) {
- List<String> stackLore = dir.getStringList("lore");
- stack = ItemUtil.setLore(stack, stackLore);
- }
- if (dir.isConfigurationSection("enchantments")) {
- Map<String, Object> enchant = dir.getConfigurationSection("enchantments").getValues(false);
- for (Map.Entry<String, Object> entry : enchant.entrySet()) {
- Enchantment ench = Enchantment.getByName(entry.getKey().toUpperCase());
- if (ench != null) {
- int enchLvl = (int) entry.getValue();
- stack.addUnsafeEnchantment(ench, enchLvl);
- }
- }
- }
- if (material.equals("ENCHANTED_BOOK") && dir.isConfigurationSection("bookEnchant")) {
- Map<String, Object> bookEnchant = dir.getConfigurationSection("bookEnchant").getValues(false);
- EnchantmentStorageMeta meta = (EnchantmentStorageMeta) stack.getItemMeta();
- for (Map.Entry<String, Object> entry : bookEnchant.entrySet()) {
- Enchantment ench = Enchantment.getByName(entry.getKey().toUpperCase());
- int enchLvl = (int) entry.getValue();
- meta.addStoredEnchant(ench, enchLvl, true);
- }
- stack.setItemMeta(meta);
- }
- if (((mater.toString().contains("POTION")) || mater.toString().contains("TIPPED")) && dir.isConfigurationSection("potion")) {
- ConfigurationSection potions = dir.getConfigurationSection("potion");
- PotionMeta meta = (PotionMeta) stack.getItemMeta();
- if (potions.getBoolean("many_effects", false)) {
- for (String pkey : potions.getKeys(false)) {
- ConfigurationSection p = potions.getConfigurationSection(pkey);
- PotionEffect effect = getEffectFromConfig(p);
- meta.addCustomEffect(effect, true);
- }
- } else {
- PotionEffect effect = getEffectFromConfig(potions);
- meta.addCustomEffect(effect, true);
- }
- List<Integer> bcolor = potions.getIntegerList("bottle_color");
- if (!bcolor.isEmpty()) {
- meta.setColor(readColor(bcolor));
- } else {
- meta.setColor(meta.getCustomEffects().get(0).getType().getColor());
- }
- stack.setItemMeta(meta);
- }
- stacks.put(stack, chance);
- }
- ItemSet.create(key, stacks);
- }
- }
- private static Color readColor(List<Integer> rgb) {
- Color color;
- if (rgb != null && rgb.size() == 3) {
- color = Color.fromRGB(rgb.get(0), rgb.get(1), rgb.get(2));
- } else {
- color = Color.WHITE;
- }
- return color;
- }
- private static PotionEffect getEffectFromConfig(ConfigurationSection section) {
- String eff = section.getString("effect", "SPEED");
- PotionEffectType effect;
- try {
- effect = PotionEffectType.getByName(eff.toUpperCase());
- } catch (IllegalArgumentException ex) {
- LobbyPvP.log.warning("Can't find potion " + eff);
- effect = PotionEffectType.SPEED;
- }
- int duration = section.getInt("duration", effect.isInstant() ? 1 : 20 * 30);
- int amplifier = section.getInt("amplifier", 1) - 1;
- boolean particles = section.getBoolean("particles", true);
- List<Integer> scolor = section.getIntegerList("color");
- if (scolor == null) {
- return new PotionEffect(effect, duration, amplifier, false, particles);
- } else {
- Color color = readColor(scolor);
- return new PotionEffect(effect, duration, amplifier, particles, particles, color);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement