Advertisement
Cool_boy21

Untitled

May 13th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.87 KB | None | 0 0
  1. public Merchant getSection(String sectionName, String merchantName/*, GameTeam team*/) {
  2.         FileConfiguration shop = files.getShopInfo();
  3.         ConfigurationSection value = shop.getConfigurationSection(sectionName);
  4.         List<MerchantRecipe> recipes = new ArrayList();
  5.         bcast("Value3:");
  6.         for (String strng : value.getKeys(false)) {
  7.             bcast("Value2:");
  8.             ConfigurationSection section = value.getConfigurationSection(strng);
  9.             ConfigurationSection primary = section.getConfigurationSection("primary");
  10.             ConfigurationSection result = section.getConfigurationSection("result");
  11.  
  12.             Boolean resultTeam = false;
  13.             int resultDamage = 0;
  14.  
  15.             String primaryMaterial = primary.getString("material");
  16.             bcast("Value1:" + primaryMaterial);
  17.             int primaryAmount = primary.getInt("amount");
  18.             int primaryDamage = primary.getInt("damage");
  19.             ItemStack primaryStack = new ItemStack(Material.valueOf(primaryMaterial), primaryAmount, (short) primaryDamage);
  20.  
  21.             ItemStack optionalStack = null;
  22.             if (section.isConfigurationSection("option")) {
  23.                 ConfigurationSection optional = section.getConfigurationSection("optional");
  24.                 String optionalMaterial = optional.getString("material");
  25.                 int optionalAmount = optional.getInt("amount");
  26.                 int optionalDamage = optional.getInt("damage");
  27.                 optionalStack = new ItemStack(Material.valueOf(optionalMaterial), optionalAmount, (short) optionalDamage);
  28.             }
  29.  
  30.             String resultMaterial = result.getString("material");
  31.             bcast("Value2:" + resultMaterial);
  32.             int resultAmount = result.getInt("amount");
  33.             if (result.isBoolean("team")) {
  34.                 resultTeam = result.getBoolean("team");
  35.                 resultDamage = 5;//getDamageByColor(team.getColor());
  36.             }
  37.             if (!resultTeam) {
  38.                 resultDamage = result.getInt("damage");
  39.             }
  40.             ItemStack resultStack = new ItemStack(Material.valueOf(resultMaterial), resultAmount, (short) resultDamage);
  41.             if (result.isString("name")) {
  42.                 String resultName = result.getString("name");
  43.                 resultStack = item.setName(resultStack, resultName);
  44.             }
  45.             if (result.isList("lore")) {
  46.                 List<String> resultLore = result.getStringList("lore");
  47.                 resultStack = item.setLore(resultStack, resultLore);
  48.             }
  49.  
  50.             if (result.isList("enchantments")) {
  51.                 List<String> resultEnch = result.getStringList("enchantments");
  52.                 for (String enchant : resultEnch) {
  53.                     resultStack.addEnchantment(Enchantment.getByName(enchant), 1);
  54.                 }
  55.             }
  56.             if (resultMaterial.equals("ENCHANTED_BOOK")) {
  57.                 Map<String, Object> bookEnchant = result.getConfigurationSection("bookEnchant").getValues(false);
  58.                 EnchantmentStorageMeta meta = (EnchantmentStorageMeta) resultStack.getItemMeta();
  59.                 for (Map.Entry<String, Object> entry : bookEnchant.entrySet()) {
  60.                     Enchantment ench = Enchantment.getByName(entry.getKey());
  61.                     int enchLvl = (int) entry.getValue();
  62.                     meta.addStoredEnchant(ench, enchLvl, true);
  63.                 }
  64.                 resultStack.setItemMeta(meta);
  65.             }
  66.             MerchantRecipe recipe = new MerchantRecipe(resultStack, 999);
  67.             recipe.addIngredient(primaryStack);
  68.             if (optionalStack != null) {
  69.                 recipe.addIngredient(optionalStack);
  70.             }
  71.             recipes.add(recipe);
  72.         }
  73.         Merchant m = Bukkit.createMerchant(merchantName);
  74.         m.setRecipes(recipes);
  75.         return m;
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement