Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. package com.redenoxus.nxtreasures.manager;
  2.  
  3. import com.redenoxus.nxtreasures.object.Treasures;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.Material;
  6. import org.bukkit.configuration.ConfigurationSection;
  7. import org.bukkit.configuration.file.FileConfiguration;
  8. import org.bukkit.inventory.ItemStack;
  9. import org.bukkit.inventory.meta.ItemMeta;
  10.  
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. import static com.redenoxus.nxtreasures.NxTreasures.*;
  15.  
  16. public class TreasuresManager {
  17.  
  18. private List<Treasures> treasures = new ArrayList<>();
  19.  
  20. public List<Treasures> getTreasures() {
  21. return treasures;
  22. }
  23.  
  24. public Treasures getTreasureByLevel(int level) {
  25. return treasures.stream().filter(l -> l.getLevel() == level).findFirst().orElse(null);
  26. }
  27.  
  28. public Treasures getTreasureByMcmmo(int mcmmo) {
  29. return treasures.stream().filter(l -> l.getMcmmo() == mcmmo).findFirst().orElse(null);
  30. }
  31.  
  32. public void loadTreasures() {
  33. FileConfiguration configuration = getInstance().getConfig();
  34. ConfigurationSection section = configuration.getConfigurationSection("config.treasures");
  35. int i = 0;
  36. if (section == null) return;
  37. for (String path : section.getKeys(false)) {
  38. String key = "config.treasures" + path + ".";
  39. int level = configuration.getInt(key + "level");
  40. int mcmmo = configuration.getInt(key + "mcmmo");
  41. double chance = configuration.getDouble(key + "chance");
  42. if (level == 0 || mcmmo == 0 || chance == 0D) continue;
  43. ConfigurationSection section2 = configuration.getConfigurationSection(key + "items");
  44. if (section2 == null) return;
  45. for (String path2 : section2.getKeys(false)) {
  46. String key2 = key + "items." + path2 + ".";
  47. String displayName = configuration.getString(key2 + "displayName");
  48. String material = configuration.getString(key2 + "material");
  49. int amount = configuration.getInt(key2 + "amount");
  50. List<String> lore = new ArrayList<>();
  51. for (String lines : configuration.getStringList(key2 + "lore")) {
  52. lore.add(lines.replace("&", "§"));
  53. }
  54. if (material == null || displayName == null) continue;
  55. String id;
  56. int data = 0;
  57. if (material.contains(":")) {
  58. id = material.split(":")[0];
  59. data = Integer.parseInt(material.split(":")[1]);
  60. } else {
  61. id = material;
  62. data = 0;
  63. }
  64. ItemStack itemStack = new ItemStack(Material.getMaterial(id), amount, (short) data);
  65. ItemMeta itemMeta = itemStack.getItemMeta();
  66. itemMeta.setDisplayName(displayName);
  67. itemMeta.setLore(lore);
  68. itemStack.setItemMeta(itemMeta);
  69. Treasures treasure = new Treasures(level, mcmmo, chance, itemStack);
  70. treasures.add(treasure);
  71. }
  72. i++;
  73. }
  74. Bukkit.getConsoleSender().sendMessage("§d[NxTreasures] §fForam carregados §a" + i + " §ftesouros.");
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement