Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Merchant getSection(String sectionName, String merchantName/*, GameTeam team*/) {
- FileConfiguration shop = files.getShopInfo();
- ConfigurationSection value = shop.getConfigurationSection(sectionName);
- List<MerchantRecipe> recipes = new ArrayList();
- bcast("Value3:");
- for (String strng : value.getKeys(false)) {
- bcast("Value2:");
- ConfigurationSection section = value.getConfigurationSection(strng);
- ConfigurationSection primary = section.getConfigurationSection("primary");
- ConfigurationSection result = section.getConfigurationSection("result");
- Boolean resultTeam = false;
- int resultDamage = 0;
- String primaryMaterial = primary.getString("material");
- bcast("Value1:" + primaryMaterial);
- int primaryAmount = primary.getInt("amount");
- int primaryDamage = primary.getInt("damage");
- ItemStack primaryStack = new ItemStack(Material.valueOf(primaryMaterial), primaryAmount, (short) primaryDamage);
- ItemStack optionalStack = null;
- if (section.isConfigurationSection("option")) {
- ConfigurationSection optional = section.getConfigurationSection("optional");
- String optionalMaterial = optional.getString("material");
- int optionalAmount = optional.getInt("amount");
- int optionalDamage = optional.getInt("damage");
- optionalStack = new ItemStack(Material.valueOf(optionalMaterial), optionalAmount, (short) optionalDamage);
- }
- String resultMaterial = result.getString("material");
- bcast("Value2:" + resultMaterial);
- int resultAmount = result.getInt("amount");
- if (result.isBoolean("team")) {
- resultTeam = result.getBoolean("team");
- resultDamage = 5;//getDamageByColor(team.getColor());
- }
- if (!resultTeam) {
- resultDamage = result.getInt("damage");
- }
- ItemStack resultStack = new ItemStack(Material.valueOf(resultMaterial), resultAmount, (short) resultDamage);
- if (result.isString("name")) {
- String resultName = result.getString("name");
- resultStack = item.setName(resultStack, resultName);
- }
- if (result.isList("lore")) {
- List<String> resultLore = result.getStringList("lore");
- resultStack = item.setLore(resultStack, resultLore);
- }
- if (result.isList("enchantments")) {
- List<String> resultEnch = result.getStringList("enchantments");
- for (String enchant : resultEnch) {
- resultStack.addEnchantment(Enchantment.getByName(enchant), 1);
- }
- }
- if (resultMaterial.equals("ENCHANTED_BOOK")) {
- Map<String, Object> bookEnchant = result.getConfigurationSection("bookEnchant").getValues(false);
- EnchantmentStorageMeta meta = (EnchantmentStorageMeta) resultStack.getItemMeta();
- for (Map.Entry<String, Object> entry : bookEnchant.entrySet()) {
- Enchantment ench = Enchantment.getByName(entry.getKey());
- int enchLvl = (int) entry.getValue();
- meta.addStoredEnchant(ench, enchLvl, true);
- }
- resultStack.setItemMeta(meta);
- }
- MerchantRecipe recipe = new MerchantRecipe(resultStack, 999);
- recipe.addIngredient(primaryStack);
- if (optionalStack != null) {
- recipe.addIngredient(optionalStack);
- }
- recipes.add(recipe);
- }
- Merchant m = Bukkit.createMerchant(merchantName);
- m.setRecipes(recipes);
- return m;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement