Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.redenoxus.nxtreasures.manager;
- import com.redenoxus.nxtreasures.object.Treasures;
- import org.bukkit.Bukkit;
- import org.bukkit.Material;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import java.util.ArrayList;
- import java.util.List;
- import static com.redenoxus.nxtreasures.NxTreasures.*;
- public class TreasuresManager {
- private List<Treasures> treasures = new ArrayList<>();
- public List<Treasures> getTreasures() {
- return treasures;
- }
- public Treasures getTreasureByLevel(int level) {
- return treasures.stream().filter(l -> l.getLevel() == level).findFirst().orElse(null);
- }
- public Treasures getTreasureByMcmmo(int mcmmo) {
- return treasures.stream().filter(l -> l.getMcmmo() == mcmmo).findFirst().orElse(null);
- }
- public void loadTreasures() {
- FileConfiguration configuration = getInstance().getConfig();
- ConfigurationSection section = configuration.getConfigurationSection("config.treasures");
- int i = 0;
- if (section == null) return;
- for (String path : section.getKeys(false)) {
- String key = "config.treasures" + path + ".";
- int level = configuration.getInt(key + "level");
- int mcmmo = configuration.getInt(key + "mcmmo");
- double chance = configuration.getDouble(key + "chance");
- if (level == 0 || mcmmo == 0 || chance == 0D) continue;
- ConfigurationSection section2 = configuration.getConfigurationSection(key + "items");
- if (section2 == null) return;
- for (String path2 : section2.getKeys(false)) {
- String key2 = key + "items." + path2 + ".";
- String displayName = configuration.getString(key2 + "displayName");
- String material = configuration.getString(key2 + "material");
- int amount = configuration.getInt(key2 + "amount");
- List<String> lore = new ArrayList<>();
- for (String lines : configuration.getStringList(key2 + "lore")) {
- lore.add(lines.replace("&", "§"));
- }
- if (material == null || displayName == null) continue;
- String id;
- int data = 0;
- if (material.contains(":")) {
- id = material.split(":")[0];
- data = Integer.parseInt(material.split(":")[1]);
- } else {
- id = material;
- data = 0;
- }
- ItemStack itemStack = new ItemStack(Material.getMaterial(id), amount, (short) data);
- ItemMeta itemMeta = itemStack.getItemMeta();
- itemMeta.setDisplayName(displayName);
- itemMeta.setLore(lore);
- itemStack.setItemMeta(itemMeta);
- Treasures treasure = new Treasures(level, mcmmo, chance, itemStack);
- treasures.add(treasure);
- }
- i++;
- }
- Bukkit.getConsoleSender().sendMessage("§d[NxTreasures] §fForam carregados §a" + i + " §ftesouros.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement