Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1. public static void loadConfig() {
  2. shopNames = new ArrayList<>();
  3. buyItems = new ArrayList<>();
  4. sellItems = new ArrayList<>();
  5. infoItem = new ArrayList<>();
  6. currency = new HashMap<>();
  7. itemInfo = new HashMap<>();
  8. buyactualItems = new HashMap<>();
  9. sellactualItems = new HashMap<>();
  10. config = getPlugin(ShopMain.class).getConfig();
  11. ConfigurationSection configSection = config.getConfigurationSection("Shops");
  12. if (configSection != null){
  13. for (String path: configSection.getKeys(false)){
  14. String shop = configSection.getString(path + ".Name");
  15. String currency = configSection.getString(path + ".Currency");
  16. boolean fluctuation = configSection.getBoolean(path + ".Fluctuation");
  17. shopNames.add(shop);
  18. ShopMain.currency.put(shop, currency);
  19. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Shop:" + shop);
  20. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Currency:" + currency);
  21. fluctuationEnabled.put(shop, fluctuation);
  22. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] S/D:" + fluctuation);
  23. ConfigurationSection configurationSection = config.getConfigurationSection("Shops." + path);
  24. if (configurationSection != null){
  25. buyItems = new ArrayList<>();
  26. sellItems = new ArrayList<>();
  27. for (String tehPath: configurationSection.getKeys(false)){
  28. infoItem = new ArrayList<>();
  29. if (!(tehPath.equals("Name") || tehPath.equals("Currency") || tehPath.equals("Fluctuation"))){
  30. String material = configurationSection.getString(tehPath + ".Material");
  31. int damageValue = configurationSection.getInt(tehPath + ".DamageValue");
  32. String name = configurationSection.getString(tehPath + ".ItemName").substring(1);
  33. String lore = configurationSection.getString(tehPath + ".ItemLore").substring(1);
  34. int sellPrice = configurationSection.getInt(tehPath + ".SellPrice");
  35. int sellNumba = configurationSection.getInt(tehPath + ".SellNumba");
  36. int buyPrice = configurationSection.getInt(tehPath + ".BuyPrice");
  37. int buyNumba = configurationSection.getInt(tehPath + ".BuyNumba");
  38. int amount = configurationSection.getInt(tehPath + ".Amount");
  39. if (amount < 100){
  40. amount+=5;
  41. }
  42. if (amount > 100){
  43. amount-=5;
  44. }
  45. ArrayList<String> itemLore = new ArrayList<>();
  46. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Item: " + tehPath);
  47. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Material: " + material);
  48. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Variant: " + damageValue);
  49. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Name: " + name);
  50. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Lore: " + lore);
  51. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Sell Price: " + sellPrice);
  52. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Number to Sell: " + sellNumba);
  53. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Buy Price: " + buyPrice);
  54. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Number to Buy: " + buyNumba);
  55. console.sendMessage(ChatColor.GREEN + "[AtlasSimpleShops] Amount: " + amount);
  56. if (!lore.equals("--")){
  57. if (lore.substring(0,1).equals("&")){
  58. String temp = lore.substring(0,2);
  59. lore = lore.substring(2);
  60. while (lore.indexOf("/") != -1){
  61. itemLore.add(ChatColor.translateAlternateColorCodes('&', temp + lore.substring(0, lore.indexOf("/"))));
  62. lore = lore.substring(lore.indexOf("/") + 1);
  63. }
  64. itemLore.add(ChatColor.translateAlternateColorCodes('&', temp + lore));
  65. }
  66. else {
  67. while (lore.indexOf("/") != -1){
  68. itemLore.add(ChatColor.translateAlternateColorCodes('&', lore.substring(0, lore.indexOf("/"))));
  69. lore = lore.substring(lore.indexOf("/") + 1);
  70. }
  71. itemLore.add(ChatColor.translateAlternateColorCodes('&', lore));
  72. }
  73. }
  74. ItemStack actualItem = new ItemStack(Material.getMaterial(material));
  75. ItemMeta actualItemMeta = actualItem.getItemMeta();
  76. if (!name.equals("--")){
  77. actualItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
  78. }
  79. actualItemMeta.setLore(itemLore);
  80. actualItem.setItemMeta(actualItemMeta);
  81. itemLore.add(ChatColor.translateAlternateColorCodes('&', "&4In Stock:&f " + amount));
  82. itemLore.add(ChatColor.translateAlternateColorCodes('&', "&f>>&eBuy Price:&f " + buyPrice));
  83. ItemStack buyItem = new ItemStack(Material.getMaterial(material), buyNumba, (byte) damageValue);
  84. ItemMeta buyItemMeta = buyItem.getItemMeta();
  85. if (!name.equals("--")){
  86. buyItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
  87. }
  88. buyItemMeta.setLore(itemLore);
  89. buyItem.setItemMeta(buyItemMeta);
  90. buyItems.add(buyItem);
  91. itemLore.remove(itemLore.size() - 1);
  92. itemLore.add(ChatColor.translateAlternateColorCodes('&',"&f>>&aSell Price:&f " + sellPrice));
  93. ItemStack sellItem = new ItemStack(Material.getMaterial(material), sellNumba, (byte) damageValue);
  94. ItemMeta sellItemMeta = sellItem.getItemMeta();
  95. if (!name.equals("--")){
  96. sellItemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
  97. }
  98. sellItemMeta.setLore(itemLore);
  99. sellItem.setItemMeta(sellItemMeta);
  100. sellItems.add(sellItem);
  101. //
  102. infoItem.add(sellPrice);
  103. infoItem.add(sellNumba);
  104. infoItem.add(buyPrice);
  105. infoItem.add(buyNumba);
  106. infoItem.add(damageValue);
  107. infoItem.add(amount);
  108. //
  109. itemInfo.put(actualItem, infoItem);
  110. buyactualItems.put(buyItem, actualItem);
  111. sellactualItems.put(sellItem, actualItem);
  112. }
  113. }
  114. }
  115. buyshops.put(shop, buyItems);
  116. sellshops.put(shop,sellItems);
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement