Treasure Config Split pt 2, Configs now register to be backed up with the config manager

This commit is contained in:
nossr50 2019-02-21 19:06:59 -08:00
parent 41bfba0c68
commit 349a714134
9 changed files with 318 additions and 99 deletions

View File

@ -20,6 +20,7 @@ import java.util.List;
public abstract class Config implements VersionedConfig, Unload {
/* SETTINGS */
//private static final String FILE_EXTENSION = ".conf"; //HOCON
private boolean mergeNewKeys; //Whether or not to merge keys found in the default config
private boolean removeOldKeys; //Whether or not to remove unused keys form the config
private boolean copyDefaults; //Whether or not to copy the default config when first creating the file
@ -65,8 +66,6 @@ public abstract class Config implements VersionedConfig, Unload {
DIRECTORY_DATA_FOLDER = pathToParentFolder; //Data Folder for our plugin
FILE_RELATIVE_PATH = relativePath; //Relative path to config from a parent folder
registerUnload();
//Attempt IO Operations
try {
//Makes sure we have valid Files corresponding to this config
@ -83,6 +82,10 @@ public abstract class Config implements VersionedConfig, Unload {
} catch (IOException e) {
e.printStackTrace();
}
//Cleanup and backup registers
registerUnload();
registerFileBackup();
}
/**
@ -94,6 +97,15 @@ public abstract class Config implements VersionedConfig, Unload {
mcMMO.getConfigManager().registerUnloadable(this);
}
/**
* Registers with the config managers file list
* Used for backing up configs with our zip library
*/
private void registerFileBackup()
{
mcMMO.getConfigManager().registerUserFile(getUserConfigFile());
}
/**
* Initializes the default copy File and the user config File
* @throws IOException
@ -170,6 +182,14 @@ public abstract class Config implements VersionedConfig, Unload {
}
}
/**
* Gets the File representation of the this users config
* @return the users config File
*/
public File getUserConfigFile() {
return new File(DIRECTORY_DATA_FOLDER, FILE_RELATIVE_PATH);
}
/**
* Used to make a new config file at a specified relative output path inside the data directory by copying the matching file found in that same relative path within the JAR
* @param relativeOutputPath the path to the output file

View File

@ -5,12 +5,16 @@ import com.gmail.nossr50.config.collectionconfigs.MultiConfigContainer;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
import com.gmail.nossr50.config.treasure.ExcavationTreasureConfig;
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
import com.gmail.nossr50.config.treasure.HerbalismTreasureConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairableManager;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
import com.gmail.nossr50.skills.salvage.salvageables.SimpleSalvageableManager;
import java.io.File;
import java.util.ArrayList;
/**
@ -31,6 +35,7 @@ public final class ConfigManager {
/* UNLOAD REGISTER */
private ArrayList<Unload> unloadables;
private ArrayList<File> userFiles;
/* MULTI CONFIG INSTANCES */
@ -56,7 +61,9 @@ public final class ConfigManager {
/* CONFIG INSTANCES */
private MainConfig mainConfig;
private TreasureConfig treasureConfig;
private FishingTreasureConfig fishingTreasureConfig;
private ExcavationTreasureConfig excavationTreasureConfig;
private HerbalismTreasureConfig herbalismTreasureConfig;
private ExperienceConfig experienceConfig;
private AdvancedConfig advancedConfig;
private PotionConfig potionConfig;
@ -74,6 +81,7 @@ public final class ConfigManager {
public ConfigManager()
{
unloadables = new ArrayList<>();
userFiles = new ArrayList<>();
// Load Config Files
// I'm pretty these are supposed to be done in a specific order, so don't rearrange them willy nilly
@ -81,7 +89,9 @@ public final class ConfigManager {
//TODO: Not sure about the order of MainConfig
mainConfig = new MainConfig();
treasureConfig = new TreasureConfig();
fishingTreasureConfig = new FishingTreasureConfig();
excavationTreasureConfig = new ExcavationTreasureConfig();
herbalismTreasureConfig = new HerbalismTreasureConfig();
advancedConfig = new AdvancedConfig();
@ -180,6 +190,7 @@ public final class ConfigManager {
//Clear
unloadables.clear();
userFiles.clear();
}
/**
@ -192,10 +203,29 @@ public final class ConfigManager {
unloadables.add(unload);
}
/**
* Registers an unloadable
* Unloadables call unload() on plugin disable to cleanup registries
*/
public void registerUserFile(File userFile)
{
if(!userFiles.contains(userFile))
userFiles.add(userFile);
}
/*
* GETTER BOILER PLATE
*/
/**
* Used to back up our zip files real easily
* @return
*/
public ArrayList<File> getConfigFiles()
{
return userFiles;
}
public SimpleRepairableManager getSimpleRepairableManager() {
return simpleRepairableManager;
}
@ -208,8 +238,16 @@ public final class ConfigManager {
return mainConfig;
}
public TreasureConfig getTreasureConfig() {
return treasureConfig;
public FishingTreasureConfig getFishingTreasureConfig() {
return fishingTreasureConfig;
}
public ExcavationTreasureConfig getExcavationTreasureConfig() {
return excavationTreasureConfig;
}
public HerbalismTreasureConfig getHerbalismTreasureConfig() {
return herbalismTreasureConfig;
}
public AdvancedConfig getAdvancedConfig() {

View File

@ -1,4 +1,66 @@
package com.gmail.nossr50.config.treasure;
public class ExcavationTreasureConfig {
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.Registers;
import com.gmail.nossr50.config.UnsafeValueValidation;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.mcMMO;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import java.io.File;
import java.util.HashMap;
import java.util.List;
public class ExcavationTreasureConfig extends Config implements UnsafeValueValidation, Registers {
public static final String EXCAVATION = "Archaeology";
public HashMap<String, List<ExcavationTreasure>> excavationMap = new HashMap<String, List<ExcavationTreasure>>();
public ExcavationTreasureConfig() {
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "excavation_treasures.yml", false, true, false);
register();
}
/**
* Register stuff
*/
@Override
public void register() {
ConfigurationNode excavationTreasureNode = getUserRootNode().getNode(EXCAVATION);
if(excavationTreasureNode == null)
{
mcMMO.p.getLogger().info("Excavation treasures in treasures config not defined");
return;
}
try {
for (String treasureName : excavationTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
@Override
public void unload() {
}
@Override
public List<String> validateKeys() {
return null;
}
/**
* The version of this config
*
* @return
*/
@Override
public double getConfigVersion() {
return 1;
}
}

View File

@ -1,4 +1,115 @@
package com.gmail.nossr50.config.treasure;
public class FishingTreasureConfig {
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.Registers;
import com.gmail.nossr50.config.UnsafeValueValidation;
import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Rarity;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.mcMMO;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import org.bukkit.entity.EntityType;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class FishingTreasureConfig extends Config implements UnsafeValueValidation, Registers {
public HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<EntityType, List<ShakeTreasure>>();
public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<Rarity, List<FishingTreasure>>();
public HashMap<Rarity, List<EnchantmentTreasure>> fishingEnchantments = new HashMap<Rarity, List<EnchantmentTreasure>>();
public static final String ITEM_DROP_RATES = "Item_Drop_Rates";
public static final String FISHING = "Fishing";
public static final String ENCHANTMENT_DROP_RATES = "Enchantment_Drop_Rates";
public static final String SHAKE = "Shake";
public FishingTreasureConfig() {
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "fishing_treasures.yml", false, true, false);
register();
}
/**
* Register stuff
*/
@Override
public void register() {
/* FISHING TREASURES */
ConfigurationNode fishingTreasureNode = getUserRootNode().getNode(FISHING);
if(fishingTreasureNode == null)
{
mcMMO.p.getLogger().info("Fishing treasures in treasures config not defined");
return;
}
// Initialize fishing HashMap
for (Rarity rarity : Rarity.values()) {
if (!fishingRewards.containsKey(rarity)) {
fishingRewards.put(rarity, (new ArrayList<FishingTreasure>()));
}
}
try {
for (String treasureName : fishingTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
//Shake
for (EntityType entity : EntityType.values()) {
if (entity.isAlive()) {
loadShake(entity);
}
}
}
private void loadShake(EntityType entityType)
{
ConfigurationNode shakeTreasureNode = getUserRootNode().getNode(SHAKE, entityType.toString());
if(shakeTreasureNode != null)
return;
try {
for (String treasureName : shakeTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
@Override
public void unload() {
shakeMap.clear();
fishingRewards.clear();
fishingEnchantments.clear();
}
@Override
public List<String> validateKeys() {
return null;
}
/**
* The version of this config
*
* @return
*/
@Override
public double getConfigVersion() {
return 1;
}
}

View File

@ -1,4 +1,66 @@
package com.gmail.nossr50.config.treasure;
public class HerbalismTreasureConfig {
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.Registers;
import com.gmail.nossr50.config.UnsafeValueValidation;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.mcMMO;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
import java.io.File;
import java.util.HashMap;
import java.util.List;
public class HerbalismTreasureConfig extends Config implements UnsafeValueValidation, Registers {
public static final String HYLIAN_LUCK = "Hylian_Luck";
public HashMap<String, List<HylianTreasure>> hylianMap = new HashMap<String, List<HylianTreasure>>();
public HerbalismTreasureConfig() {
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "herbalism_treasures.yml", false, true, false);
register();
}
/**
* Register stuff
*/
@Override
public void register() {
ConfigurationNode herbalismTreasureNode = getUserRootNode().getNode(HYLIAN_LUCK);
if(herbalismTreasureNode == null)
{
mcMMO.p.getLogger().info("Hylian_Luck in treasures config not defined");
return;
}
try {
for (String treasureName : herbalismTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
@Override
public void unload() {
hylianMap.clear();
}
@Override
public List<String> validateKeys() {
return null;
}
/**
* The version of this config
*
* @return
*/
@Override
public double getConfigVersion() {
return 1;
}
}

View File

@ -29,20 +29,15 @@ import java.util.List;
//TODO: Need to rewrite this too
public class TreasureConfig extends Config implements UnsafeValueValidation, Registers {
public static final String ENCHANTMENT_DROP_RATES = "Enchantment_Drop_Rates";
public static final String ITEM_DROP_RATES = "Item_Drop_Rates";
public static final String FISHING = "Fishing";
public static final String EXCAVATION = "Excavation";
public static final String SHAKE = "Shake";
public static final String HYLIAN_LUCK = "Hylian_Luck";
public HashMap<String, List<ExcavationTreasure>> excavationMap = new HashMap<String, List<ExcavationTreasure>>();
public HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<EntityType, List<ShakeTreasure>>();
public HashMap<String, List<HylianTreasure>> hylianMap = new HashMap<String, List<HylianTreasure>>();
public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<Rarity, List<FishingTreasure>>();
public HashMap<Rarity, List<EnchantmentTreasure>> fishingEnchantments = new HashMap<Rarity, List<EnchantmentTreasure>>();
public TreasureConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"treasures.yml");
@ -158,11 +153,7 @@ public class TreasureConfig extends Config implements UnsafeValueValidation, Reg
loadEnchantments();
for (EntityType entity : EntityType.values()) {
if (entity.isAlive()) {
loadShake(entity);
}
}
}
private void initRegisters()
@ -185,84 +176,23 @@ public class TreasureConfig extends Config implements UnsafeValueValidation, Reg
private void loadFishing()
{
ConfigurationNode fishingTreasureNode = getUserRootNode().getNode(FISHING);
if(fishingTreasureNode == null)
{
mcMMO.p.getLogger().info("Fishing treasures in treasures config not defined");
return;
}
// Initialize fishing HashMap
for (Rarity rarity : Rarity.values()) {
if (!fishingRewards.containsKey(rarity)) {
fishingRewards.put(rarity, (new ArrayList<FishingTreasure>()));
}
}
try {
for (String treasureName : fishingTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
private void loadExcavation()
{
ConfigurationNode excavationTreasureNode = getUserRootNode().getNode(EXCAVATION);
if(excavationTreasureNode == null)
{
mcMMO.p.getLogger().info("Excavation treasures in treasures config not defined");
return;
}
try {
for (String treasureName : excavationTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
private void loadHerbalism()
{
ConfigurationNode herbalismTreasureNode = getUserRootNode().getNode(HYLIAN_LUCK);
if(herbalismTreasureNode == null)
{
mcMMO.p.getLogger().info("Hylian_Luck in treasures config not defined");
return;
}
try {
for (String treasureName : herbalismTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
private void loadShake(EntityType entityType)
{
ConfigurationNode shakeTreasureNode = getUserRootNode().getNode(SHAKE, entityType.toString());
if(shakeTreasureNode != null)
return;
try {
for (String treasureName : shakeTreasureNode.getList(TypeToken.of(String.class))) {
}
} catch (ObjectMappingException e) {
e.printStackTrace();
}
}
private void loadTreasures(ConfigurationNode treasureChildNode) {
if (treasureChildNode == null) {

View File

@ -31,7 +31,6 @@ import com.gmail.nossr50.util.experience.FormulaManager;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.upgrade.UpgradeManager;
import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.google.common.base.Charsets;
import net.shatteredlands.shatt.backup.ZipLibrary;
@ -55,7 +54,7 @@ public class mcMMO extends JavaPlugin {
private static DatabaseManager databaseManager;
private static FormulaManager formulaManager;
private static HolidayManager holidayManager;
private static UpgradeManager upgradeManager;
//private static UpgradeManager upgradeManager;
/* Blacklist */
private static WorldBlacklist worldBlacklist;
@ -331,9 +330,9 @@ public class mcMMO extends JavaPlugin {
return modManager;
}*/
public static UpgradeManager getUpgradeManager() {
/*public static UpgradeManager getUpgradeManager() {
return upgradeManager;
}
}*/
@Deprecated
public static void setDatabaseManager(DatabaseManager databaseManager) {

View File

@ -1,6 +1,7 @@
package net.shatteredlands.shatt.backup;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.mcMMO;
import java.io.File;
@ -20,14 +21,14 @@ public class ZipLibrary {
private static File BACKUP_DIR = new File(BACKUP_DIRECTORY);
private static File FLAT_FILE_DIRECTORY = new File(mcMMO.getFlatFileDirectory());
private static File MOD_FILE_DIRECTORY = new File(mcMMO.getModDirectory());
private static File CONFIG_FILE = new File(mcMMO.getMainDirectory() + "config.yml");
/* private static File CONFIG_FILE = new File(mcMMO.getMainDirectory() + "config.yml");
private static File EXPERIENCE_FILE = new File(mcMMO.getMainDirectory() + "experience.yml");
//private static File TREASURE_FILE = new File(mcMMO.getMainDirectory() + "treasures.yml");
private static File ADVANCED_FILE = new File(mcMMO.getMainDirectory() + "advanced.yml");
private static File REPAIR_FILE = new File(mcMMO.getMainDirectory() + "repair.vanilla.yml");
private static File REPAIR_FILE = new File(mcMMO.getMainDirectory() + "repair.vanilla.yml");*/
public static void mcMMOBackup() throws IOException {
if (Config.getInstance().getUseMySQL()) {
if (MainConfig.getInstance().getUseMySQL()) {
mcMMO.p.debug("This server is running in SQL Mode.");
mcMMO.p.debug("Only config files will be backed up.");
}
@ -50,11 +51,7 @@ public class ZipLibrary {
List<File> sources = new ArrayList<File>();
sources.add(FLAT_FILE_DIRECTORY);
sources.add(CONFIG_FILE);
sources.add(EXPERIENCE_FILE);
sources.add(TREASURE_FILE);
sources.add(ADVANCED_FILE);
sources.add(REPAIR_FILE);
sources.addAll(mcMMO.getConfigManager().getConfigFiles()); //Config File Backups
if (MOD_FILE_DIRECTORY.exists()) {
sources.add(MOD_FILE_DIRECTORY);

View File

@ -1,7 +1,7 @@
#
# Settings for Excavation's Archaeology
###
Excavation:
Archaeology:
CAKE:
Amount: 1
XP: 3000