mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-05 22:15:27 +02:00
formatting applied to most of the source code to tidy things up, and misc refactors
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.gmail.nossr50.config.treasure;
|
||||
|
||||
import static com.gmail.nossr50.util.text.ConfigStringUtils.getMaterialConfigString;
|
||||
|
||||
import com.gmail.nossr50.config.BukkitConfig;
|
||||
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
||||
@@ -7,6 +9,10 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.LogUtils;
|
||||
import com.gmail.nossr50.util.PotionUtil;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
@@ -16,13 +22,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gmail.nossr50.util.text.ConfigStringUtils.getMaterialConfigString;
|
||||
|
||||
public class TreasureConfig extends BukkitConfig {
|
||||
|
||||
public static final String FILENAME = "treasures.yml";
|
||||
@@ -95,7 +94,9 @@ public class TreasureConfig extends BukkitConfig {
|
||||
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");
|
||||
short data = (treasureInfo.length == 2) ? Short.parseShort(treasureInfo[1])
|
||||
: (short) config.getInt(
|
||||
type + "." + treasureName + ".Data");
|
||||
|
||||
if (material == null) {
|
||||
reason.add("Invalid material: " + materialName);
|
||||
@@ -120,31 +121,42 @@ public class TreasureConfig extends BukkitConfig {
|
||||
//Check for legacy drop level values and convert
|
||||
if (getWrongKeyValue(type, treasureName, DropLevelKeyConversionType.LEGACY) != -1) {
|
||||
//Legacy Drop level, needs to be converted
|
||||
shouldWeUpdateFile = processAutomaticKeyConversion(type, shouldWeUpdateFile, treasureName, DropLevelKeyConversionType.LEGACY);
|
||||
shouldWeUpdateFile = processAutomaticKeyConversion(
|
||||
type, shouldWeUpdateFile, treasureName,
|
||||
DropLevelKeyConversionType.LEGACY);
|
||||
}
|
||||
|
||||
//Check for a bad key that was accidentally shipped out to some users
|
||||
if (getWrongKeyValue(type, treasureName, DropLevelKeyConversionType.WRONG_KEY_STANDARD) != -1) {
|
||||
if (getWrongKeyValue(type, treasureName, DropLevelKeyConversionType.WRONG_KEY_STANDARD)
|
||||
!= -1) {
|
||||
//Partially converted to the new system, I had a dyslexic moment so some configs have this
|
||||
shouldWeUpdateFile = processAutomaticKeyConversion(type, shouldWeUpdateFile, treasureName, DropLevelKeyConversionType.WRONG_KEY_STANDARD);
|
||||
shouldWeUpdateFile = processAutomaticKeyConversion(
|
||||
type, shouldWeUpdateFile, treasureName,
|
||||
DropLevelKeyConversionType.WRONG_KEY_STANDARD);
|
||||
}
|
||||
|
||||
//Check for a bad key that was accidentally shipped out to some users
|
||||
if (getWrongKeyValue(type, treasureName, DropLevelKeyConversionType.WRONG_KEY_RETRO) != -1) {
|
||||
if (getWrongKeyValue(type, treasureName, DropLevelKeyConversionType.WRONG_KEY_RETRO)
|
||||
!= -1) {
|
||||
//Partially converted to the new system, I had a dyslexic moment so some configs have this
|
||||
shouldWeUpdateFile = processAutomaticKeyConversion(type, shouldWeUpdateFile, treasureName, DropLevelKeyConversionType.WRONG_KEY_RETRO);
|
||||
shouldWeUpdateFile = processAutomaticKeyConversion(
|
||||
type, shouldWeUpdateFile, treasureName,
|
||||
DropLevelKeyConversionType.WRONG_KEY_RETRO);
|
||||
}
|
||||
|
||||
int dropLevel = -1;
|
||||
|
||||
if (mcMMO.isRetroModeEnabled()) {
|
||||
dropLevel = config.getInt(type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE, -1);
|
||||
dropLevel = config.getInt(type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE,
|
||||
-1);
|
||||
} else {
|
||||
dropLevel = config.getInt(type + "." + treasureName + LEVEL_REQUIREMENT_STANDARD_MODE, -1);
|
||||
dropLevel = config.getInt(
|
||||
type + "." + treasureName + LEVEL_REQUIREMENT_STANDARD_MODE, -1);
|
||||
}
|
||||
|
||||
if (dropLevel == -1) {
|
||||
mcMMO.p.getLogger().severe("Could not find a Level_Requirement entry for treasure " + treasureName);
|
||||
mcMMO.p.getLogger().severe("Could not find a Level_Requirement entry for treasure "
|
||||
+ treasureName);
|
||||
mcMMO.p.getLogger().severe("Skipping treasure");
|
||||
continue;
|
||||
}
|
||||
@@ -171,19 +183,27 @@ public class TreasureConfig extends BukkitConfig {
|
||||
item = new ItemStack(mat, amount, data);
|
||||
PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
|
||||
if (potionMeta == null) {
|
||||
mcMMO.p.getLogger().severe("Item meta when adding potion to treasure was null, contact the mcMMO devs!");
|
||||
reason.add("Item meta when adding potion to treasure was null, contact the mcMMO devs!");
|
||||
mcMMO.p.getLogger().severe(
|
||||
"Item meta when adding potion to treasure was null, contact the mcMMO devs!");
|
||||
reason.add(
|
||||
"Item meta when adding potion to treasure was null, contact the mcMMO devs!");
|
||||
continue;
|
||||
}
|
||||
|
||||
String potionTypeStr;
|
||||
potionTypeStr = config.getString(type + "." + treasureName + ".PotionData.PotionType", "WATER");
|
||||
boolean extended = config.getBoolean(type + "." + treasureName + ".PotionData.Extended", false);
|
||||
boolean upgraded = config.getBoolean(type + "." + treasureName + ".PotionData.Upgraded", false);
|
||||
PotionType potionType = PotionUtil.matchPotionType(potionTypeStr, extended, upgraded);
|
||||
potionTypeStr = config.getString(
|
||||
type + "." + treasureName + ".PotionData.PotionType", "WATER");
|
||||
boolean extended = config.getBoolean(
|
||||
type + "." + treasureName + ".PotionData.Extended", false);
|
||||
boolean upgraded = config.getBoolean(
|
||||
type + "." + treasureName + ".PotionData.Upgraded", false);
|
||||
PotionType potionType = PotionUtil.matchPotionType(potionTypeStr, extended,
|
||||
upgraded);
|
||||
|
||||
if (potionType == null) {
|
||||
reason.add("Could not derive potion type from: " + potionTypeStr +", " + extended + ", " + upgraded);
|
||||
reason.add(
|
||||
"Could not derive potion type from: " + potionTypeStr + ", "
|
||||
+ extended + ", " + upgraded);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -192,7 +212,9 @@ public class TreasureConfig extends BukkitConfig {
|
||||
PotionUtil.setBasePotionType(potionMeta, potionType, extended, upgraded);
|
||||
|
||||
if (config.contains(type + "." + treasureName + ".Custom_Name")) {
|
||||
potionMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getString(type + "." + treasureName + ".Custom_Name")));
|
||||
potionMeta.setDisplayName(ChatColor.translateAlternateColorCodes(
|
||||
'&',
|
||||
config.getString(type + "." + treasureName + ".Custom_Name")));
|
||||
}
|
||||
|
||||
if (config.contains(type + "." + treasureName + ".Lore")) {
|
||||
@@ -209,7 +231,9 @@ public class TreasureConfig extends BukkitConfig {
|
||||
|
||||
if (config.contains(type + "." + treasureName + ".Custom_Name")) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', config.getString(type + "." + treasureName + ".Custom_Name")));
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes(
|
||||
'&',
|
||||
config.getString(type + "." + treasureName + ".Custom_Name")));
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
@@ -226,43 +250,62 @@ public class TreasureConfig extends BukkitConfig {
|
||||
|
||||
if (noErrorsInConfig(reason)) {
|
||||
if (isExcavation) {
|
||||
ExcavationTreasure excavationTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
|
||||
List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
|
||||
ExcavationTreasure excavationTreasure = new ExcavationTreasure(item, xp,
|
||||
dropChance, dropLevel);
|
||||
List<String> dropList = config.getStringList(
|
||||
type + "." + treasureName + ".Drops_From");
|
||||
|
||||
for (String blockType : dropList) {
|
||||
if (!excavationMap.containsKey(blockType))
|
||||
if (!excavationMap.containsKey(blockType)) {
|
||||
excavationMap.put(blockType, new ArrayList<>());
|
||||
}
|
||||
excavationMap.get(blockType).add(excavationTreasure);
|
||||
}
|
||||
} else if (isHylian) {
|
||||
HylianTreasure hylianTreasure = new HylianTreasure(item, xp, dropChance, dropLevel);
|
||||
List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
|
||||
HylianTreasure hylianTreasure = new HylianTreasure(item, xp, dropChance,
|
||||
dropLevel);
|
||||
List<String> dropList = config.getStringList(
|
||||
type + "." + treasureName + ".Drops_From");
|
||||
|
||||
for (String dropper : dropList) {
|
||||
if (dropper.equals("Bushes")) {
|
||||
AddHylianTreasure(getMaterialConfigString(Material.FERN), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(BlockUtils.getShortGrass()), hylianTreasure);
|
||||
for (Material species : Tag.SAPLINGS.getValues())
|
||||
AddHylianTreasure(getMaterialConfigString(Material.FERN),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(BlockUtils.getShortGrass()),
|
||||
hylianTreasure);
|
||||
for (Material species : Tag.SAPLINGS.getValues()) {
|
||||
AddHylianTreasure(getMaterialConfigString(species), hylianTreasure);
|
||||
}
|
||||
|
||||
AddHylianTreasure(getMaterialConfigString(Material.DEAD_BUSH), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.DEAD_BUSH),
|
||||
hylianTreasure);
|
||||
continue;
|
||||
}
|
||||
if (dropper.equals("Flowers")) {
|
||||
AddHylianTreasure(getMaterialConfigString(Material.POPPY), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.DANDELION), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.BLUE_ORCHID), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.ALLIUM), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.AZURE_BLUET), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.ORANGE_TULIP), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.PINK_TULIP), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.RED_TULIP), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.WHITE_TULIP), hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.POPPY),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.DANDELION),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.BLUE_ORCHID),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.ALLIUM),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.AZURE_BLUET),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.ORANGE_TULIP),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.PINK_TULIP),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.RED_TULIP),
|
||||
hylianTreasure);
|
||||
AddHylianTreasure(getMaterialConfigString(Material.WHITE_TULIP),
|
||||
hylianTreasure);
|
||||
continue;
|
||||
}
|
||||
if (dropper.equals("Pots")) {
|
||||
for (Material species : Tag.FLOWER_POTS.getValues())
|
||||
for (Material species : Tag.FLOWER_POTS.getValues()) {
|
||||
AddHylianTreasure(getMaterialConfigString(species), hylianTreasure);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
AddHylianTreasure(dropper, hylianTreasure);
|
||||
@@ -281,36 +324,61 @@ public class TreasureConfig extends BukkitConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean processAutomaticKeyConversion(String type, boolean shouldWeUpdateTheFile, String treasureName, DropLevelKeyConversionType conversionType) {
|
||||
private boolean processAutomaticKeyConversion(String type, boolean shouldWeUpdateTheFile,
|
||||
String treasureName,
|
||||
DropLevelKeyConversionType conversionType) {
|
||||
switch (conversionType) {
|
||||
case LEGACY:
|
||||
int legacyDropLevel = getWrongKeyValue(type, treasureName, conversionType); //Legacy only had one value, Retro Mode didn't have a setting
|
||||
int legacyDropLevel = getWrongKeyValue(
|
||||
type, treasureName,
|
||||
conversionType); //Legacy only had one value, Retro Mode didn't have a setting
|
||||
//Config needs to be updated to be more specific
|
||||
LogUtils.debug(mcMMO.p.getLogger(), "(" + treasureName + ") [Fixing bad address: Legacy] Converting Drop_Level to Level_Requirement in treasures.yml for treasure to match new expected format");
|
||||
config.set(type + "." + treasureName + LEGACY_DROP_LEVEL, null); //Remove legacy entry
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE, legacyDropLevel * 10); //Multiply by 10 for Retro
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_STANDARD_MODE, legacyDropLevel);
|
||||
LogUtils.debug(
|
||||
mcMMO.p.getLogger(),
|
||||
"(" + treasureName
|
||||
+ ") [Fixing bad address: Legacy] Converting Drop_Level to Level_Requirement in treasures.yml for treasure to match new expected format");
|
||||
config.set(type + "." + treasureName + LEGACY_DROP_LEVEL,
|
||||
null); //Remove legacy entry
|
||||
config.set(
|
||||
type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE,
|
||||
legacyDropLevel * 10); //Multiply by 10 for Retro
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_STANDARD_MODE,
|
||||
legacyDropLevel);
|
||||
shouldWeUpdateTheFile = true;
|
||||
break;
|
||||
case WRONG_KEY_STANDARD:
|
||||
LogUtils.debug(mcMMO.p.getLogger(), "(" + treasureName + ") [Fixing bad address: STANDARD] Converting Drop_Level to Level_Requirement in treasures.yml for treasure to match new expected format");
|
||||
LogUtils.debug(
|
||||
mcMMO.p.getLogger(),
|
||||
"(" + treasureName
|
||||
+ ") [Fixing bad address: STANDARD] Converting Drop_Level to Level_Requirement in treasures.yml for treasure to match new expected format");
|
||||
int wrongKeyValueStandard = getWrongKeyValue(type, treasureName, conversionType);
|
||||
config.set(type + "." + treasureName + WRONG_KEY_ROOT, null); //We also kill the Retro key here as we have enough information for setting in values if needed
|
||||
config.set(
|
||||
type + "." + treasureName + WRONG_KEY_ROOT,
|
||||
null); //We also kill the Retro key here as we have enough information for setting in values if needed
|
||||
|
||||
if (wrongKeyValueStandard != -1) {
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_STANDARD_MODE, wrongKeyValueStandard);
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE, wrongKeyValueStandard * 10); //Multiply by 10 for Retro
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_STANDARD_MODE,
|
||||
wrongKeyValueStandard);
|
||||
config.set(
|
||||
type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE,
|
||||
wrongKeyValueStandard * 10); //Multiply by 10 for Retro
|
||||
}
|
||||
|
||||
shouldWeUpdateTheFile = true;
|
||||
break;
|
||||
case WRONG_KEY_RETRO:
|
||||
LogUtils.debug(mcMMO.p.getLogger(), "(" + treasureName + ") [Fixing bad address: RETRO] Converting Drop_Level to Level_Requirement in treasures.yml for treasure to match new expected format");
|
||||
LogUtils.debug(
|
||||
mcMMO.p.getLogger(),
|
||||
"(" + treasureName
|
||||
+ ") [Fixing bad address: RETRO] Converting Drop_Level to Level_Requirement in treasures.yml for treasure to match new expected format");
|
||||
int wrongKeyValueRetro = getWrongKeyValue(type, treasureName, conversionType);
|
||||
config.set(type + "." + treasureName + WRONG_KEY_ROOT, null); //We also kill the Retro key here as we have enough information for setting in values if needed
|
||||
config.set(
|
||||
type + "." + treasureName + WRONG_KEY_ROOT,
|
||||
null); //We also kill the Retro key here as we have enough information for setting in values if needed
|
||||
|
||||
if (wrongKeyValueRetro != -1) {
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE, wrongKeyValueRetro);
|
||||
config.set(type + "." + treasureName + LEVEL_REQUIREMENT_RETRO_MODE,
|
||||
wrongKeyValueRetro);
|
||||
}
|
||||
|
||||
shouldWeUpdateTheFile = true;
|
||||
@@ -319,24 +387,26 @@ public class TreasureConfig extends BukkitConfig {
|
||||
return shouldWeUpdateTheFile;
|
||||
}
|
||||
|
||||
private int getWrongKeyValue(String type, String treasureName, DropLevelKeyConversionType dropLevelKeyConversionType) {
|
||||
private int getWrongKeyValue(String type, String treasureName,
|
||||
DropLevelKeyConversionType dropLevelKeyConversionType) {
|
||||
return switch (dropLevelKeyConversionType) {
|
||||
case LEGACY -> config.getInt(type + "." + treasureName + LEGACY_DROP_LEVEL, -1);
|
||||
case WRONG_KEY_STANDARD -> config.getInt(type + "." + treasureName + WRONG_KEY_VALUE_STANDARD, -1);
|
||||
case WRONG_KEY_RETRO -> config.getInt(type + "." + treasureName + WRONG_KEY_VALUE_RETRO, -1);
|
||||
case WRONG_KEY_STANDARD ->
|
||||
config.getInt(type + "." + treasureName + WRONG_KEY_VALUE_STANDARD, -1);
|
||||
case WRONG_KEY_RETRO ->
|
||||
config.getInt(type + "." + treasureName + WRONG_KEY_VALUE_RETRO, -1);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private void AddHylianTreasure(String dropper, HylianTreasure treasure) {
|
||||
if (!hylianMap.containsKey(dropper))
|
||||
if (!hylianMap.containsKey(dropper)) {
|
||||
hylianMap.put(dropper, new ArrayList<>());
|
||||
}
|
||||
hylianMap.get(dropper).add(treasure);
|
||||
}
|
||||
|
||||
private enum DropLevelKeyConversionType {
|
||||
LEGACY,
|
||||
WRONG_KEY_STANDARD,
|
||||
WRONG_KEY_RETRO
|
||||
LEGACY, WRONG_KEY_STANDARD, WRONG_KEY_RETRO
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user