package com.yaohun.crazyprizepool.data; import com.yaohun.itemlibrary.api.ItemKuAPI; import me.Demon.DemonPlugin.DemonAPI; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; import java.util.Random; public class ContentData { private String poolKey; private Map stackMap = new HashMap<>(); private Map chanceMap = new HashMap<>(); public ContentData(String poolKey, ConfigurationSection section) { ConfigurationSection section1 = section.getConfigurationSection(poolKey); for (String contentKey : section1.getKeys(false)) { double chance = section1.getDouble(contentKey + ".chance"); if(chance >= 0.1) { chanceMap.put(contentKey, chance); int itemAmount = section1.getInt(contentKey + ".amount"); String itemKey = section1.getString(contentKey + ".item"); if (itemKey.contains("ItemKu#")) { String[] strings = itemKey.split("#"); String stackKey = strings[1]; ItemStack stack = ItemKuAPI.getItems(stackKey, itemAmount); stackMap.put(contentKey, stack); } else if (itemKey.contains("CSGO#")) { String[] strings = itemKey.split("#"); String stackKey = strings[1]; ItemStack stack = me.Demon.DemonCSGO.Api.CratesAPI.getCratesItemStack(stackKey, itemAmount); stackMap.put(contentKey, stack); } else { ItemStack stack = section1.getItemStack(contentKey + ".item"); stack.setAmount(itemAmount); stackMap.put(contentKey, stack); } } } } public ItemStack getCratesStack(String contentKey){ if(this.stackMap.get(contentKey) == null){ return null; } return this.stackMap.get(contentKey); } public String Start_CratesKey(){ Map chanceMap = new HashMap<>(); int a = 0; for (String contentKey : this.chanceMap.keySet()){ double chance = this.chanceMap.get(contentKey); chanceMap.put(contentKey,chance); a += chance; } String CratesKey = null; Random ran = new Random(); ran.setSeed(System.currentTimeMillis()+ DemonAPI.getRandomInt(80000,1000)); int b = ran.nextInt(a); for (String rewardKey : this.chanceMap.keySet()){ if(chanceMap.get(rewardKey) > b){ CratesKey = rewardKey; break; } b -= chanceMap.get(rewardKey); } return CratesKey; } }