| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- package com.gmail.nossr50.config.treasure;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Map.Entry;
- import org.bukkit.Material;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.entity.EntityType;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.material.MaterialData;
- import org.bukkit.potion.Potion;
- import org.bukkit.potion.PotionType;
- import com.gmail.nossr50.config.ConfigLoader;
- import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
- import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
- import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
- import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
- import com.gmail.nossr50.datatypes.treasure.Treasure;
- public class TreasureConfig extends ConfigLoader {
- private static TreasureConfig instance;
- public List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>();
- public List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
- public List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>();
- public List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>();
- public List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>();
- public List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>();
- public List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>();
- public List<ExcavationTreasure> excavationFromSnow = new ArrayList<ExcavationTreasure>();
- public List<HylianTreasure> hylianFromBushes = new ArrayList<HylianTreasure>();
- public List<HylianTreasure> hylianFromFlowers = new ArrayList<HylianTreasure>();
- public List<HylianTreasure> hylianFromPots = new ArrayList<HylianTreasure>();
- public List<ShakeTreasure> shakeFromBlaze = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromCaveSpider = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromSpider = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromChicken = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromCow = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromCreeper = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromEnderman = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromGhast = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromIronGolem = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromMagmaCube = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromMushroomCow = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromPig = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromPigZombie = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromSheep = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromSkeleton = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromSlime = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromSnowman = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromSquid = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromWitch = new ArrayList<ShakeTreasure>();
- public List<ShakeTreasure> shakeFromZombie = new ArrayList<ShakeTreasure>();
- public List<FishingTreasure> fishingRewards = new ArrayList<FishingTreasure>();
- private TreasureConfig() {
- super("treasures.yml");
- loadKeys();
- }
- public static TreasureConfig getInstance() {
- if (instance == null) {
- instance = new TreasureConfig();
- }
- return instance;
- }
- @Override
- protected void loadKeys() {
- Map<String, Treasure> treasures = new HashMap<String, Treasure>();
- ConfigurationSection treasureSection = config.getConfigurationSection("Treasures");
- if (treasureSection == null) {
- return;
- }
- for (String treasureName : treasureSection.getKeys(false)) {
- // Validate all the things!
- List<String> reason = new ArrayList<String>();
- /*
- * ID, Amount, and Data
- */
- if (!config.contains("Treasures." + treasureName + ".ID")) {
- reason.add("Missing ID");
- }
- if (!config.contains("Treasures." + treasureName + ".Amount")) {
- reason.add("Missing Amount");
- }
- if (!config.contains("Treasures." + treasureName + ".Data")) {
- reason.add("Missing Data");
- }
- int id = config.getInt("Treasures." + treasureName + ".ID");
- int amount = config.getInt("Treasures." + treasureName + ".Amount");
- int data = config.getInt("Treasures." + treasureName + ".Data");
- if (Material.getMaterial(id) == null) {
- reason.add("Invalid id: " + id);
- }
- if (amount < 1) {
- reason.add("Invalid amount: " + amount);
- }
- if (id < 256 && (data > 127 || data < -128)) {
- reason.add("Invalid data: " + data);
- }
- /*
- * XP, Drop Chance, and Drop Level
- */
- if (!config.contains("Treasures." + treasureName + ".XP")) {
- reason.add("Missing XP");
- }
- if (!config.contains("Treasures." + treasureName + ".Drop_Chance")) {
- reason.add("Missing Drop_Chance");
- }
- if (!config.contains("Treasures." + treasureName + ".Drop_Level")) {
- reason.add("Missing Drop_Level");
- }
- int xp = config.getInt("Treasures." + treasureName + ".XP");
- Double dropChance = config.getDouble("Treasures." + treasureName + ".Drop_Chance");
- int dropLevel = config.getInt("Treasures." + treasureName + ".Drop_Level");
- if (xp < 0) {
- reason.add("Invalid xp: " + xp);
- }
- if (dropChance < 0) {
- reason.add("Invalid Drop_Chance: " + dropChance);
- }
- if (dropLevel < 0) {
- reason.add("Invalid Drop_Level: " + dropLevel);
- }
- /*
- * Potions
- */
- ItemStack item = null;
- if (config.contains("Treasures." + treasureName + ".Potion_Type")) {
- String potionType = config.getString("Treasures." + treasureName + ".Potion_Type");
- try {
- item = new Potion(PotionType.valueOf(potionType.toUpperCase())).toItemStack(amount);
- }
- catch (IllegalArgumentException ex) {
- reason.add("Invalid Potion_Type: " + potionType);
- }
- }
- else {
- item = (new MaterialData(id, (byte) data)).toItemStack(amount);
- }
- /*
- * Drops From & Max Level
- */
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
- if (config.getConfigurationSection("Treasures." + treasureName + ".Drops_From").getKeys(false).size() != 1) {
- reason.add("This can only be a fishing drop.");
- }
- if (!config.contains("Treasures." + treasureName + ".Max_Level")) {
- reason.add("Missing Max_Level");
- }
- int maxLevel = config.getInt("Treasures." + treasureName + ".Max_Level");
- if (noErrorsInConfig(reason)) {
- FishingTreasure fTreasure = new FishingTreasure(item, xp, dropChance, dropLevel, maxLevel);
- treasures.put(treasureName, fTreasure);
- }
- }
- else if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Shake", false)) {
- if (config.getConfigurationSection("Treasures." + treasureName + ".Drops_From").getKeys(false).size() != 1) {
- reason.add("This can only be a shake drop.");
- }
- if (!config.contains("Treasures." + treasureName + ".Mob")) {
- reason.add("Missing Mob");
- }
- String mobType = config.getString("Treasures." + treasureName + ".Mob");
- EntityType mob = null;
- try {
- mob = EntityType.valueOf(mobType.toUpperCase().trim());
- }
- catch (IllegalArgumentException ex){
- reason.add("Invalid Mob: " + mobType);
- }
- if (noErrorsInConfig(reason)) {
- ShakeTreasure sTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel, mob);
- treasures.put(treasureName, sTreasure);
- }
- }
- else {
- ExcavationTreasure eTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
- HylianTreasure hTreasure = new HylianTreasure(item, xp, dropChance, dropLevel);
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Dirt", false)) {
- eTreasure.setDropsFromDirt();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Grass", false)) {
- eTreasure.setDropsFromGrass();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Sand", false)) {
- eTreasure.setDropsFromSand();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Gravel", false)) {
- eTreasure.setDropsFromGravel();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Clay", false)) {
- eTreasure.setDropsFromClay();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Mycelium", false)) {
- eTreasure.setDropsFromMycel();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Soul_Sand", false)) {
- eTreasure.setDropsFromSoulSand();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Snow", false)) {
- eTreasure.setDropsFromSnow();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Bushes", false)) {
- hTreasure.setDropsFromBushes();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Flowers", false)) {
- hTreasure.setDropsFromFlowers();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Pots", false)) {
- hTreasure.setDropsFromPots();
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
- reason.add("This cannot also be a fishing drop.");
- }
- if (config.getBoolean("Treasures." + treasureName + ".Drops_From.Shake", false)) {
- reason.add("This cannot also be a shake drop.");
- }
- if (noErrorsInConfig(reason) && hTreasure.getDropsFrom() == (byte) 0x0) {
- treasures.put(treasureName, eTreasure);
- }
- else if (noErrorsInConfig(reason) && eTreasure.getDropsFrom() == (byte) 0x0) {
- treasures.put(treasureName, hTreasure);
- }
- }
- }
- List<String> excavationTreasures = config.getStringList("Excavation.Treasure");
- List<String> fishingTreasures = config.getStringList("Fishing.Treasure");
- List<String> hylianTreasures = config.getStringList("Hylian_Luck.Treasure");
- List<String> shakeTreasures = config.getStringList("Shake.Treasure");
- for (Entry<String, Treasure> nextEntry : treasures.entrySet()) {
- String treasureKey = nextEntry.getKey();
- Treasure treasure = nextEntry.getValue();
- if (treasure instanceof FishingTreasure) {
- if (fishingTreasures == null || !fishingTreasures.contains(treasureKey)) {
- continue;
- }
- fishingRewards.add((FishingTreasure) treasure);
- }
- else if (treasure instanceof ShakeTreasure) {
- if (shakeTreasures == null || !shakeTreasures.contains(treasureKey)) {
- continue;
- }
- ShakeTreasure e = (ShakeTreasure) treasure;
- switch (e.getMob()) {
- case BLAZE:
- shakeFromBlaze.add(e);
- break;
- case CAVE_SPIDER:
- shakeFromCaveSpider.add(e);
- break;
- case CHICKEN:
- shakeFromChicken.add(e);
- break;
- case COW:
- shakeFromCow.add(e);
- break;
- case CREEPER:
- shakeFromCreeper.add(e);
- break;
- case ENDERMAN:
- shakeFromEnderman.add(e);
- break;
- case GHAST:
- shakeFromGhast.add(e);
- break;
- case IRON_GOLEM:
- shakeFromIronGolem.add(e);
- break;
- case MAGMA_CUBE:
- shakeFromMagmaCube.add(e);
- break;
- case MUSHROOM_COW:
- shakeFromMushroomCow.add(e);
- break;
- case PIG:
- shakeFromPig.add(e);
- break;
- case PIG_ZOMBIE:
- shakeFromPigZombie.add(e);
- break;
- case SHEEP:
- shakeFromSheep.add(e);
- break;
- case SKELETON:
- shakeFromSkeleton.add(e);
- break;
- case SLIME:
- shakeFromSlime.add(e);
- break;
- case SPIDER:
- shakeFromSpider.add(e);
- break;
- case SNOWMAN:
- shakeFromSnowman.add(e);
- break;
- case SQUID:
- shakeFromSquid.add(e);
- break;
- case WITCH:
- shakeFromWitch.add(e);
- break;
- case ZOMBIE:
- shakeFromZombie.add(e);
- break;
- default:
- break;
- }
- }
- else if (treasure instanceof HylianTreasure) {
- if (hylianTreasures == null || !hylianTreasures.contains(treasureKey)) {
- continue;
- }
- HylianTreasure hTreasure = (HylianTreasure) treasure;
- if (hTreasure.getDropsFromBushes()) {
- hylianFromBushes.add(hTreasure);
- }
- if (hTreasure.getDropsFromFlowers()) {
- hylianFromFlowers.add(hTreasure);
- }
- if (hTreasure.getDropsFromPots()) {
- hylianFromPots.add(hTreasure);
- }
- }
- else if (treasure instanceof ExcavationTreasure) {
- if (excavationTreasures == null || !excavationTreasures.contains(treasureKey)) {
- continue;
- }
- ExcavationTreasure eTreasure = (ExcavationTreasure) treasure;
- if (eTreasure.getDropsFromDirt()) {
- excavationFromDirt.add(eTreasure);
- }
- if (eTreasure.getDropsFromGrass()) {
- excavationFromGrass.add(eTreasure);
- }
- if (eTreasure.getDropsFromSand()) {
- excavationFromSand.add(eTreasure);
- }
- if (eTreasure.getDropsFromGravel()) {
- excavationFromGravel.add(eTreasure);
- }
- if (eTreasure.getDropsFromClay()) {
- excavationFromClay.add(eTreasure);
- }
- if (eTreasure.getDropsFromMycel()) {
- excavationFromMycel.add(eTreasure);
- }
- if (eTreasure.getDropsFromSoulSand()) {
- excavationFromSoulSand.add(eTreasure);
- }
- if (eTreasure.getDropsFromSnow()) {
- excavationFromSnow.add(eTreasure);
- }
- }
- }
- }
- }
|