Move fishing treasues to new file fishing_treasures.yml, replace Records rarity with Mythic, and allow for Enchanted_Book in the treasures list with new optional whitelist/blacklist parameters

read the changelog for information about this
This commit is contained in:
nossr50
2020-12-28 16:42:00 -08:00
parent 31134b38de
commit 652a9519c1
26 changed files with 1512 additions and 936 deletions

View File

@@ -1,14 +1,14 @@
package com.gmail.nossr50.config.treasure;
import com.gmail.nossr50.config.ConfigLoader;
import com.gmail.nossr50.datatypes.treasure.*;
import com.gmail.nossr50.util.EnchantmentUtils;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.util.text.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -22,18 +22,14 @@ import java.util.List;
public class TreasureConfig extends ConfigLoader {
public static final String FILENAME = "treasures.yml";
private static TreasureConfig instance;
public HashMap<String, List<ExcavationTreasure>> excavationMap = new HashMap<>();
public HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<>();
public HashMap<String, List<HylianTreasure>> hylianMap = new HashMap<>();
public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<>();
public HashMap<Rarity, List<EnchantmentTreasure>> fishingEnchantments = new HashMap<>();
private TreasureConfig() {
super("treasures.yml");
super(FILENAME);
loadKeys();
validate();
}
@@ -51,29 +47,18 @@ public class TreasureConfig extends ConfigLoader {
// Validate all the settings!
List<String> reason = new ArrayList<>();
for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) {
double totalEnchantDropRate = 0;
double totalItemDropRate = 0;
for (Rarity rarity : Rarity.values()) {
double enchantDropRate = config.getDouble("Enchantment_Drop_Rates." + tier + "." + rarity.toString());
double itemDropRate = config.getDouble("Item_Drop_Rates." + tier + "." + rarity.toString());
if ((enchantDropRate < 0.0 || enchantDropRate > 100.0) && rarity != Rarity.RECORD) {
reason.add("The enchant drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
}
if (itemDropRate < 0.0 || itemDropRate > 100.0) {
reason.add("The item drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
}
totalEnchantDropRate += enchantDropRate;
totalItemDropRate += itemDropRate;
}
if (totalEnchantDropRate < 0 || totalEnchantDropRate > 100.0) {
reason.add("The total enchant drop rate for " + tier + " should be between 0.0 and 100.0!");
}
if (totalItemDropRate < 0 || totalItemDropRate > 100.0) {
reason.add("The total item drop rate for " + tier + " should be between 0.0 and 100.0!");
}
@@ -92,7 +77,6 @@ public class TreasureConfig extends ConfigLoader {
loadTreasures("Fishing");
loadTreasures("Excavation");
loadTreasures("Hylian_Luck");
loadEnchantments();
for (EntityType entity : EntityType.values()) {
if (entity.isAlive()) {
@@ -102,8 +86,6 @@ public class TreasureConfig extends ConfigLoader {
}
private void loadTreasures(String type) {
boolean isFishing = type.equals("Fishing");
boolean isShake = type.contains("Shake");
boolean isExcavation = type.equals("Excavation");
boolean isHylian = type.equals("Hylian_Luck");
@@ -113,13 +95,6 @@ public class TreasureConfig extends ConfigLoader {
return;
}
// Initialize fishing HashMap
for (Rarity rarity : Rarity.values()) {
if (!fishingRewards.containsKey(rarity)) {
fishingRewards.put(rarity, (new ArrayList<>()));
}
}
for (String treasureName : treasureSection.getKeys(false)) {
// Validate all the things!
List<String> reason = new ArrayList<>();
@@ -131,16 +106,7 @@ public class TreasureConfig extends ConfigLoader {
* Material, Amount, and Data
*/
Material material;
if (materialName.contains("INVENTORY")) {
// Use magic material BEDROCK to know that we're grabbing something from the inventory and not a normal treasure
if (!shakeMap.containsKey(EntityType.PLAYER))
shakeMap.put(EntityType.PLAYER, new ArrayList<>());
shakeMap.get(EntityType.PLAYER).add(new ShakeTreasure(new ItemStack(Material.BEDROCK, 1, (byte) 0), 1, getInventoryStealDropChance(), getInventoryStealDropLevel()));
continue;
} else {
material = Material.matchMaterial(materialName);
}
material = Material.matchMaterial(materialName);
int amount = config.getInt(type + "." + treasureName + ".Amount");
short data = (treasureInfo.length == 2) ? Short.parseShort(treasureInfo[1]) : (short) config.getInt(type + "." + treasureName + ".Data");
@@ -177,19 +143,6 @@ public class TreasureConfig extends ConfigLoader {
reason.add(treasureName + " has an invalid Drop_Level: " + dropLevel);
}
/*
* Specific Types
*/
Rarity rarity = null;
if (isFishing) {
rarity = Rarity.getRarity(config.getString(type + "." + treasureName + ".Rarity"));
if (rarity == null) {
reason.add("Invalid Rarity for item: " + treasureName);
}
}
/*
* Itemstack
*/
@@ -198,7 +151,7 @@ public class TreasureConfig extends ConfigLoader {
if (materialName.contains("POTION")) {
Material mat = Material.matchMaterial(materialName);
if (mat == null) {
reason.add("Potion format for Treasures.yml has changed");
reason.add("Potion format for " + FILENAME + " has changed");
} else {
item = new ItemStack(mat, amount, data);
PotionMeta itemMeta = (PotionMeta) item.getItemMeta();
@@ -247,16 +200,7 @@ public class TreasureConfig extends ConfigLoader {
}
if (noErrorsInConfig(reason)) {
if (isFishing) {
fishingRewards.get(rarity).add(new FishingTreasure(item, xp));
} else if (isShake) {
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
EntityType entityType = EntityType.valueOf(type.substring(6));
if (!shakeMap.containsKey(entityType))
shakeMap.put(entityType, new ArrayList<>());
shakeMap.get(entityType).add(shakeTreasure);
} else if (isExcavation) {
if (isExcavation) {
ExcavationTreasure excavationTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
@@ -309,36 +253,6 @@ public class TreasureConfig extends ConfigLoader {
hylianMap.get(dropper).add(treasure);
}
private void loadEnchantments() {
for (Rarity rarity : Rarity.values()) {
if (rarity == Rarity.RECORD) {
continue;
}
if (!fishingEnchantments.containsKey(rarity)) {
fishingEnchantments.put(rarity, (new ArrayList<>()));
}
ConfigurationSection enchantmentSection = config.getConfigurationSection("Enchantments_Rarity." + rarity.toString());
if (enchantmentSection == null) {
return;
}
for (String enchantmentName : enchantmentSection.getKeys(false)) {
int level = config.getInt("Enchantments_Rarity." + rarity.toString() + "." + enchantmentName);
Enchantment enchantment = EnchantmentUtils.getByName(enchantmentName);
if (enchantment == null) {
plugin.getLogger().warning("Skipping invalid enchantment in treasures.yml: " + enchantmentName);
continue;
}
fishingEnchantments.get(rarity).add(new EnchantmentTreasure(enchantment, level));
}
}
}
public boolean getInventoryStealEnabled() {
return config.contains("Shake.PLAYER.INVENTORY");
}