123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- package com.gmail.nossr50.config.treasure;
- import java.util.ArrayList;
- import java.util.List;
- import org.bukkit.DyeColor;
- import org.bukkit.Material;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.entity.EntityType;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.material.Dye;
- 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;
- 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> shakeFromHorse = 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() {
- if (config.getConfigurationSection("Treasures") != null) {
- backup();
- return;
- }
- loadTreaures("Fishing");
- loadTreaures("Excavation");
- loadTreaures("Hylian_Luck");
- for (EntityType entity : EntityType.values()) {
- if (entity.isAlive()) {
- loadTreaures("Shake." + entity.toString());
- }
- }
- }
- private void loadTreaures(String type) {
- boolean isFishing = type.equals("Fishing");
- boolean isShake = type.contains("Shake");
- boolean isExcavation = type.equals("Excavation");
- boolean isHylian = type.equals("Hylian_Luck");
- ConfigurationSection treasureSection = config.getConfigurationSection(type);
- if (treasureSection == null) {
- return;
- }
- for (String treasureName : treasureSection.getKeys(false)) {
- // Validate all the things!
- List<String> reason = new ArrayList<String>();
- /*
- * Material, Amount, and Data
- */
- Material material;
- if (treasureName.contains("POTION")) {
- material = Material.POTION;
- }
- else if (treasureName.contains("INK_SACK")) {
- material = Material.INK_SACK;
- }
- else {
- material = Material.matchMaterial(treasureName);
- }
- int amount = config.getInt(type + "." + treasureName + ".Amount");
- int data = config.getInt(type + "." + treasureName + ".Data");
- if (material == null) {
- reason.add("Invalid material: " + treasureName);
- }
- if (amount <= 0) {
- reason.add("Amount of " + treasureName + " must be greater than 0! " + amount);
- }
- if (material != null && material.isBlock() && (data > 127 || data < -128)) {
- reason.add("Data of " + treasureName + " is invalid! " + data);
- }
- /*
- * XP, Drop Chance, and Drop Level
- */
- int xp = config.getInt(type + "." + treasureName + ".XP");
- double dropChance = config.getDouble(type + "." + treasureName + ".Drop_Chance");
- int dropLevel = config.getInt(type + "." + treasureName + ".Drop_Level");
- if (xp < 0) {
- reason.add(treasureName + " has an invalid XP value: " + xp);
- }
- if (dropChance < 0.0D) {
- reason.add(treasureName + " has an invalid Drop_Chance: " + dropChance);
- }
- if (dropLevel < 0) {
- reason.add(treasureName + " has an invalid Drop_Level: " + dropLevel);
- }
- /*
- * Specific Types
- */
- int maxLevel = 0;
- if (isFishing) {
- maxLevel = config.getInt(type + "." + treasureName + ".Max_Level");
- if (maxLevel < -1) {
- reason.add(treasureName + " has an invalid Max_Level: " + maxLevel);
- }
- if (maxLevel != -1 && maxLevel < dropLevel) {
- reason.add(treasureName + " Max_Level must be -1 or greater than Drop_Level!");
- }
- }
- /*
- * Itemstack
- */
- ItemStack item = null;
- if (treasureName.contains("POTION")) {
- String potionType = treasureName.substring(7);
- try {
- item = new Potion(PotionType.valueOf(potionType.toUpperCase().trim())).toItemStack(amount);
- }
- catch (IllegalArgumentException ex) {
- reason.add("Invalid Potion_Type: " + potionType);
- }
- }
- else if (treasureName.contains("INK_SACK")) {
- String color = treasureName.substring(9);
- try {
- Dye dye = new Dye();
- dye.setColor(DyeColor.valueOf(color.toUpperCase().trim()));
- item = dye.toItemStack(amount);
- }
- catch (IllegalArgumentException ex) {
- reason.add("Invalid Dye_Color: " + color);
- }
- }
- else if (material != null) {
- item = new ItemStack(material, amount, (short) data);
- if (config.contains(type + "." + treasureName + ".Custom_Name")) {
- ItemMeta itemMeta = item.getItemMeta();
- itemMeta.setDisplayName(config.getString(type + "." + treasureName + "Custom_Name"));
- item.setItemMeta(itemMeta);
- }
- if (config.contains(type + "." + treasureName + ".Lore")) {
- ItemMeta itemMeta = item.getItemMeta();
- itemMeta.setLore(config.getStringList(type + "." + treasureName + "Custom_Name"));
- item.setItemMeta(itemMeta);
- }
- }
- if (noErrorsInConfig(reason)) {
- if (isFishing) {
- fishingRewards.add(new FishingTreasure(item, xp, dropChance, dropLevel, maxLevel));
- }
- else if (isShake) {
- ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
- if (type.equals("Shake.BLAZE")) {
- shakeFromBlaze.add(shakeTreasure);
- }
- else if (type.equals("Shake.CAVE_SPIDER")) {
- shakeFromCaveSpider.add(shakeTreasure);
- }
- else if (type.equals("Shake.CHICKEN")) {
- shakeFromChicken.add(shakeTreasure);
- }
- else if (type.equals("Shake.COW")) {
- shakeFromCow.add(shakeTreasure);
- }
- else if (type.equals("Shake.CREEPER")) {
- shakeFromCreeper.add(shakeTreasure);
- }
- else if (type.equals("Shake.ENDERMAN")) {
- shakeFromEnderman.add(shakeTreasure);
- }
- else if (type.equals("Shake.GHAST")) {
- shakeFromGhast.add(shakeTreasure);
- }
- else if (type.equals("Shake.HORSE")) {
- shakeFromHorse.add(shakeTreasure);
- }
- else if (type.equals("Shake.IRON_GOLEM")) {
- shakeFromIronGolem.add(shakeTreasure);
- }
- else if (type.equals("Shake.MAGMA_CUBE")) {
- shakeFromMagmaCube.add(shakeTreasure);
- }
- else if (type.equals("Shake.MUSHROOM_COW")) {
- shakeFromMushroomCow.add(shakeTreasure);
- }
- else if (type.equals("Shake.PIG")) {
- shakeFromPig.add(shakeTreasure);
- }
- else if (type.equals("Shake.PIG_ZOMBIE")) {
- shakeFromPigZombie.add(shakeTreasure);
- }
- else if (type.equals("Shake.SHEEP")) {
- shakeFromSheep.add(shakeTreasure);
- }
- else if (type.equals("Shake.SKELETON")) {
- shakeFromSkeleton.add(shakeTreasure);
- }
- else if (type.equals("Shake.SLIME")) {
- shakeFromSlime.add(shakeTreasure);
- }
- else if (type.equals("Shake.SPIDER")) {
- shakeFromSpider.add(shakeTreasure);
- }
- else if (type.equals("Shake.SNOWMAN")) {
- shakeFromSnowman.add(shakeTreasure);
- }
- else if (type.equals("Shake.SQUID")) {
- shakeFromSquid.add(shakeTreasure);
- }
- else if (type.equals("Shake.WITCH")) {
- shakeFromWitch.add(shakeTreasure);
- }
- else if (type.equals("Shake.ZOMBIE")) {
- shakeFromZombie.add(shakeTreasure);
- }
- }
- else if (isExcavation) {
- ExcavationTreasure excavationTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
- List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
- if (dropList.contains("Dirt")) {
- excavationFromDirt.add(excavationTreasure);
- }
- if (dropList.contains("Grass")) {
- excavationFromGrass.add(excavationTreasure);
- }
- if (dropList.contains("Sand")) {
- excavationFromSand.add(excavationTreasure);
- }
- if (dropList.contains("Gravel")) {
- excavationFromGravel.add(excavationTreasure);
- }
- if (dropList.contains("Clay")) {
- excavationFromClay.add(excavationTreasure);
- }
- if (dropList.contains("Mycelium")) {
- excavationFromMycel.add(excavationTreasure);
- }
- if (dropList.contains("Soul_Sand")) {
- excavationFromSoulSand.add(excavationTreasure);
- }
- if (dropList.contains("Snow")) {
- excavationFromSnow.add(excavationTreasure);
- }
- }
- else if (isHylian) {
- HylianTreasure hylianTreasure = new HylianTreasure(item, xp, dropChance, dropLevel);
- List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
- if (dropList.contains("Bushes")) {
- hylianFromBushes.add(hylianTreasure);
- }
- if (dropList.contains("Flowers")) {
- hylianFromFlowers.add(hylianTreasure);
- }
- if (dropList.contains("Pots")) {
- hylianFromPots.add(hylianTreasure);
- }
- }
- }
- }
- }
- }
|