diff --git a/pom.xml b/pom.xml index 381c6a7a6..3ce57ef23 100755 --- a/pom.xml +++ b/pom.xml @@ -125,10 +125,10 @@ com.flowpowered com.gmail.nossr50.flow --> - + diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index 728ba801d..d332e8979 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -122,20 +122,22 @@ public class AdvancedConfig extends ConfigValidated { public static final String SEND_COPY_OF_MESSAGE_TO_CHAT = "SendCopyOfMessageToChat"; public static final String EVENTS = "Events"; public static final String SEND_TITLES = "SendTitles"; - private static AdvancedConfig instance; + //private static AdvancedConfig instance; - private AdvancedConfig() { + public AdvancedConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true); super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true); } - public static AdvancedConfig getInstance() { + + + /*public static AdvancedConfig getInstance() { if (instance == null) { instance = new AdvancedConfig(); } return instance; - } + }*/ /** * The version of this config diff --git a/src/main/java/com/gmail/nossr50/config/ChildConfig.java b/src/main/java/com/gmail/nossr50/config/ChildConfig.java index 0de422596..2220bfe69 100644 --- a/src/main/java/com/gmail/nossr50/config/ChildConfig.java +++ b/src/main/java/com/gmail/nossr50/config/ChildConfig.java @@ -7,13 +7,13 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.util.EnumSet; -public class ChildConfig extends ConfigCollections { +public class ChildConfig extends ConfigCollection { public ChildConfig() { super("child.yml"); } @Override - protected void loadKeys() { + protected void register() { config.setDefaults(YamlConfiguration.loadConfiguration(plugin.getResourceAsReader("child.yml"))); FamilyTree.clearRegistrations(); // when reloading, need to clear statics diff --git a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java index 3ca201a20..8f65e8839 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java @@ -1,7 +1,49 @@ package com.gmail.nossr50.config; +import java.io.File; +import java.util.ArrayList; import java.util.Collection; -public interface ConfigCollection { - Collection getLoadedCollection(); +/** + * Represents a config file that registers keys after its initialized + */ +public abstract class ConfigCollection extends Config implements Registers, GenericCollectionContainer { + + //The collection held by this class + protected Collection genericCollection; + + public ConfigCollection(String pathToParentFolder, String relativePath, boolean mergeNewKeys) { + super(pathToParentFolder, relativePath, mergeNewKeys); + + //init + initCollection(); + + //load + register(); + } + + private void initCollection() { + if (genericCollection == null) + genericCollection = new ArrayList<>(); + } + + public ConfigCollection(File pathToParentFolder, String relativePath, boolean mergeNewKeys) { + super(pathToParentFolder, relativePath, mergeNewKeys); + + //init + initCollection(); + + //load + register(); + } + + @Override + public Collection getLoadedCollection() { + return this.genericCollection; + } + + @Override + public void unload() { + genericCollection.clear(); + } } diff --git a/src/main/java/com/gmail/nossr50/config/ConfigCollections.java b/src/main/java/com/gmail/nossr50/config/ConfigCollections.java deleted file mode 100644 index b6031a6d9..000000000 --- a/src/main/java/com/gmail/nossr50/config/ConfigCollections.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.gmail.nossr50.config; - -import java.io.File; - -/** - * Represents a config file that registers keys after its initialized - */ -public abstract class ConfigCollections extends Config implements RegistersKeys, ConfigCollection { - - public ConfigCollections(String pathToParentFolder, String relativePath, boolean mergeNewKeys) { - super(pathToParentFolder, relativePath, mergeNewKeys); - loadKeys(); - } - - public ConfigCollections(File pathToParentFolder, String relativePath, boolean mergeNewKeys) { - super(pathToParentFolder, relativePath, mergeNewKeys); - loadKeys(); - } -} diff --git a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java index b450541e2..0318b90dc 100644 --- a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java +++ b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java @@ -6,19 +6,19 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; public class CoreSkillsConfig extends Config { - private static CoreSkillsConfig instance; + //private static CoreSkillsConfig instance; public CoreSkillsConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true); super(mcMMO.p.getDataFolder().getAbsoluteFile(),"coreskills.yml", true); } - public static CoreSkillsConfig getInstance() { + /*public static CoreSkillsConfig getInstance() { if (instance == null) return new CoreSkillsConfig(); return instance; - } + }*/ /** * The version of this config diff --git a/src/main/java/com/gmail/nossr50/config/GenericCollectionContainer.java b/src/main/java/com/gmail/nossr50/config/GenericCollectionContainer.java new file mode 100644 index 000000000..973ea5795 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/GenericCollectionContainer.java @@ -0,0 +1,15 @@ +package com.gmail.nossr50.config; + +import java.util.Collection; + +/** + * Represents a class that contains a generic collection + * @param + */ +public interface GenericCollectionContainer { + /** + * Grab the collection held by this class + * @return the collection held by this class + */ + Collection getLoadedCollection(); +} diff --git a/src/main/java/com/gmail/nossr50/config/RankConfig.java b/src/main/java/com/gmail/nossr50/config/RankConfig.java index 299535119..d88932e2c 100644 --- a/src/main/java/com/gmail/nossr50/config/RankConfig.java +++ b/src/main/java/com/gmail/nossr50/config/RankConfig.java @@ -8,20 +8,20 @@ import java.util.ArrayList; import java.util.List; public class RankConfig extends ConfigValidated { - private static RankConfig instance; + //private static RankConfig instance; public RankConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true); super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true); - this.instance = this; + //this.instance = this; } - public static RankConfig getInstance() { + /*public static RankConfig getInstance() { if (instance == null) return new RankConfig(); return instance; - } + }*/ @Override public void unload() { diff --git a/src/main/java/com/gmail/nossr50/config/Registers.java b/src/main/java/com/gmail/nossr50/config/Registers.java new file mode 100644 index 000000000..ce1bd13a0 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/Registers.java @@ -0,0 +1,11 @@ +package com.gmail.nossr50.config; + +/** + * A class that is expected to register one thing into another thing + */ +public interface Registers { + /** + * Register stuff + */ + void register(); +} diff --git a/src/main/java/com/gmail/nossr50/config/RegistersKeys.java b/src/main/java/com/gmail/nossr50/config/RegistersKeys.java deleted file mode 100644 index 4ef2048e9..000000000 --- a/src/main/java/com/gmail/nossr50/config/RegistersKeys.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.gmail.nossr50.config; - -/** - * A class that registers keys - */ -public interface RegistersKeys { - /** - * Loads up keys - */ - void loadKeys(); -} diff --git a/src/main/java/com/gmail/nossr50/config/SoundConfig.java b/src/main/java/com/gmail/nossr50/config/SoundConfig.java index 3fbd499eb..f74f1e219 100644 --- a/src/main/java/com/gmail/nossr50/config/SoundConfig.java +++ b/src/main/java/com/gmail/nossr50/config/SoundConfig.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.List; public class SoundConfig extends ConfigValidated { - private static SoundConfig instance; + //private static SoundConfig instance; public SoundConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true); @@ -15,12 +15,12 @@ public class SoundConfig extends ConfigValidated { this.instance = this; } - public static SoundConfig getInstance() { + /*public static SoundConfig getInstance() { if (instance == null) return new SoundConfig(); return instance; - } + }*/ @Override public void unload() { diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/ConfigManager.java new file mode 100644 index 000000000..dbb3b86a6 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/ConfigManager.java @@ -0,0 +1,166 @@ +package com.gmail.nossr50.config.collectionconfigs; + +import com.gmail.nossr50.config.*; +import com.gmail.nossr50.config.mods.ArmorConfigManager; +import com.gmail.nossr50.config.mods.BlockConfigManager; +import com.gmail.nossr50.config.mods.EntityConfigManager; +import com.gmail.nossr50.config.mods.ToolConfigManager; +import com.gmail.nossr50.config.skills.alchemy.PotionConfig; +import com.gmail.nossr50.config.treasure.TreasureConfig; +import com.gmail.nossr50.skills.child.ChildConfig; +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.util.ArrayList; + +/** + * + * The Config Manager handles initializing, loading, and unloading registers for all configs that mcMMO uses + * This makes sure that mcMMO properly loads and unloads its values on reload + * + * Config Manager also holds all of our MultiConfigContainers + * + * MultiConfigContainers + * Represents a collection of config files that serve a similar purpose + * As an example, with Repair you can have an unlimited number of files named repair.*.yml and each one will be treated the same and have its collections registered + * The master file is always named x.vanilla.yml, for example "repair.vanilla.yml" + * To be honest I'm not sure how many people make use of this system, but I'm keeping it since its been in mcMMO for like 6+ years + */ +public final class ConfigManager { + + /* UNLOAD REGISTER */ + + private ArrayList unloadables; + + /* MULTI CONFIG INSTANCES */ + + private MultiConfigContainer repairableMultiConfigContainer; + private MultiConfigContainer salvageableMultiConfigContainer; + + /* COLLECTION MANAGERS */ + + private SimpleRepairableManager simpleRepairableManager; + private SimpleSalvageableManager simpleSalvageableManager; + + /* CONFIG INSTANCES */ + + private TreasureConfig treasureConfig; + private AdvancedConfig advancedConfig; + private PotionConfig potionConfig; + private CoreSkillsConfig coreSkillsConfig; + private SoundConfig soundConfig; + private RankConfig rankConfig; + + public ConfigManager() + { + unloadables = 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 + treasureConfig = new TreasureConfig(); + unloadables.add(treasureConfig); + + advancedConfig = new AdvancedConfig(); + unloadables.add(advancedConfig); + + potionConfig = new PotionConfig(); + unloadables.add(potionConfig); + + coreSkillsConfig = new CoreSkillsConfig(); + unloadables.add(coreSkillsConfig); + + soundConfig = new SoundConfig(); + unloadables.add(soundConfig); + + rankConfig = new RankConfig(); + unloadables.add(rankConfig); + + //TODO: This config serves no purpose so its getting removed + new ChildConfig(); + + if (MainConfig.getInstance().getToolModsEnabled()) { + new ToolConfigManager(); + } + + if (MainConfig.getInstance().getArmorModsEnabled()) { + new ArmorConfigManager(); + } + + if (MainConfig.getInstance().getBlockModsEnabled()) { + new BlockConfigManager(); + } + + if (MainConfig.getInstance().getEntityModsEnabled()) { + new EntityConfigManager(); + } + + // Multi Config Containers + initMultiConfigContainers(); + + // Register Managers + initCollectionManagers(); + } + + /** + * Initializes all of our Multi Config Containers + */ + private void initMultiConfigContainers() + { + //Repair + repairableMultiConfigContainer = new MultiConfigContainer<>("repair", CollectionClassType.REPAIR); + unloadables.add(repairableMultiConfigContainer); + + //Salvage + salvageableMultiConfigContainer = new MultiConfigContainer<>("salvage", CollectionClassType.SALVAGE); + unloadables.add(salvageableMultiConfigContainer); + } + + /** + * Initializes any managers related to config collections + */ + private void initCollectionManagers() + { + // Handles registration of repairables + simpleRepairableManager = new SimpleRepairableManager(getRepairables()); + unloadables.add(simpleRepairableManager); + + // Handles registration of salvageables + simpleSalvageableManager = new SimpleSalvageableManager(getSalvageables()); + unloadables.add(simpleSalvageableManager); + } + + /** + * Get all loaded repairables (loaded from all repairable configs) + * @return the currently loaded repairables + */ + public ArrayList getRepairables() + { + return (ArrayList) repairableMultiConfigContainer.getCollection(); + } + + /** + * Get all loaded salvageables (loaded from all salvageable configs) + * @return the currently loaded salvageables + */ + public ArrayList getSalvageables() + { + return (ArrayList) salvageableMultiConfigContainer.getCollection(); + } + + /** + * Unloads all config options (prepares for reload) + */ + public void unloadAllConfigsAndRegisters() + { + //Unload + for(Unload unloadable : unloadables) + { + unloadable.unload(); + } + + //Clear + unloadables.clear(); + } +} diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java new file mode 100644 index 000000000..c2e485889 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java @@ -0,0 +1,155 @@ +package com.gmail.nossr50.config.collectionconfigs; + +import com.gmail.nossr50.config.ConfigCollection; +import com.gmail.nossr50.config.Unload; +import com.gmail.nossr50.mcMMO; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.regex.Pattern; + +/** + * Represents a type of config collection, these config collections are spread across multiple config files potentially + * @param + */ +public class MultiConfigContainer implements Unload { + + /* CONSTANTS */ + public static final String DEFAULT_MULTICONFIG_FILENAME_SUFFIX = ".vanilla.yml"; + + /* VARS */ + private final String configPrefix; + private Collection collection; + public final CollectionClassType collectionClassType; + private ConfigCollection vanillaConfig; + + @Override + public void unload() { + collection.clear(); + vanillaConfig.unload(); + } + + public MultiConfigContainer(String configPrefix, CollectionClassType collectionClassType) + { + //Define Config Class + this.collectionClassType = collectionClassType; + + //Define Config Filename Prefix + this.configPrefix = configPrefix; + + //Init Collection + collection = new ArrayList(); + + //Load Configs + + //Vanilla Config + initConfigAndAddCollection(getVanillaConfigName(configPrefix)); + + //Custom Configs + loadCustomCollections(configPrefix); + } + + /** + * Add another collection to this collection + * @param otherCollection + */ + private void addCollection(Collection otherCollection) + { + collection.addAll(otherCollection); + } + + /** + * Grabs the Class to instance for this config collection + * @param collectionClassType the type of class + * @return the class to instance for this config collection + */ + private Class getConfigClass(CollectionClassType collectionClassType) + { + switch(collectionClassType) { + case REPAIR: + return RepairConfig.class; + case SALVAGE: + return SalvageConfig.class; + default: + mcMMO.p.getLogger().severe("[DEBUG] Config Class type is undefined!"); + return null; + } + } + + /** + * Gets the name of the vanilla config which is always present + * @param configPrefix the prefix to the filename, for example "repair" or "salvage" + * @return the name of the vanilla config file for this collection + */ + private String getVanillaConfigName(String configPrefix) + { + return configPrefix+DEFAULT_MULTICONFIG_FILENAME_SUFFIX; + } + + /** + * Initializes a config and attempts to load add its collection + * @param configFileName the filename of the config to load + */ + private void initConfigAndAddCollection(String configFileName) + { + mcMMO.p.getLogger().info("Reading from collection config - "+configFileName); + ConfigCollection configCollection = null; + + try { + configCollection = (ConfigCollection) getConfigClass(collectionClassType).getConstructor(String.class).newInstance(configFileName); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + + //Add the collection loaded from this config + addCollection(configCollection.getLoadedCollection()); + } + + /** + * mcMMO allows collection config files to be named things like repair.whatevernameyouwanthere.yml and so on, + * these files are treated in the same way as the vanilla file. They serve the purpose of organization + * @param configPrefix the prefix of the file name, for example "repair", "salvage", etc + */ + public void loadCustomCollections(String configPrefix) + { + String vanillaConfigFileName = getVanillaConfigName(configPrefix); + + //Find other files + Pattern pattern = Pattern.compile(configPrefix+"\\.(?:.+)\\.yml"); + //File dataFolder = McmmoCore.getDataFolderPath(); + File dataFolder = mcMMO.p.getDataFolder(); + + for (String fileName : dataFolder.list()) { + //Vanilla Config is already loaded + if(fileName.equalsIgnoreCase(vanillaConfigFileName)) + continue; + + //Find files that match the pattern + if (!pattern.matcher(fileName).matches()) { + continue; + } + + //Init file + File currentFile = new File(dataFolder, fileName); + + //Make sure its not a directory (needed?) + if(currentFile.isDirectory()) + continue; + + //Load and add the collections + initConfigAndAddCollection(fileName); + } + } + + public Collection getCollection() { + return collection; + } +} diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigManager.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigManager.java deleted file mode 100644 index 4790afb9a..000000000 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigManager.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.gmail.nossr50.config.collectionconfigs; - -import com.gmail.nossr50.config.ConfigCollection; -import com.gmail.nossr50.config.ConfigCollections; -import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.skills.repair.repairables.Repairable; -import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.regex.Pattern; - -/** - * Represents a collection of config files that serve a similar purpose - * For example, files named repair.*.yml are all loaded into memory, this lets admins keep their config files clean - * - * To be honest I'm not sure how many people make use of this system, but I'm keeping it since its been in mcMMO for like 6+ years - */ -public final class MultiConfigManager { - - public static final String DEFAULT_MULTICONFIG_FILENAME_SUFFIX = ".vanilla.yml"; - - //Configs - public com.gmail.nossr50.config.collectionconfigs.RepairConfig vanillaRepairConfig; //This is the main config file that mcMMO will copy out - public com.gmail.nossr50.config.collectionconfigs.SalvageConfig vanillaSalvageConfig; - - private static List repairables; - private static List salvageables; - - public MultiConfigManager(String fileNamePrefix) - { - //init Collections - repairables = new ArrayList<>(); - salvageables = new ArrayList<>(); - - //init vanilla configs - vanillaRepairConfig = new com.gmail.nossr50.config.collectionconfigs.RepairConfig(getVanillaConfigName("repair")); - vanillaSalvageConfig = new com.gmail.nossr50.config.collectionconfigs.SalvageConfig(getVanillaConfigName("salvage")); - - //add valid vanilla collections to main collection - repairables.addAll(vanillaRepairConfig.getLoadedCollection()); - salvageables.addAll(vanillaSalvageConfig.getLoadedCollection()); - - //add valid custom collections to main collection - loadCustomCollections("repair", repairables, com.gmail.nossr50.config.collectionconfigs.RepairConfig.class); - loadCustomCollections("salvage", salvageables, com.gmail.nossr50.config.collectionconfigs.SalvageConfig.class); - } - - /** - * mcMMO allows collection config files to be named things like repair.whatevernameyouwanthere.yml and so on, - * these files are treated in the same way as the vanilla file. They serve the purpose of organization - * @param configPrefix the prefix of the file name, for example "repair", "salvage", etc - * @param collection the collection that will be added to - */ - public void loadCustomCollections(String configPrefix, Collection collection, Class configClass) - { - String vanillaConfigFileName = getVanillaConfigName(configPrefix); - - //Find other files - Pattern pattern = Pattern.compile(configPrefix+"\\.(?:.+)\\.yml"); - //File dataFolder = McmmoCore.getDataFolderPath(); - File dataFolder = mcMMO.p.getDataFolder(); - - for (String fileName : dataFolder.list()) { - //Vanilla Config is already loaded - if(fileName.equalsIgnoreCase(vanillaConfigFileName)) - continue; - - //Find files that match the pattern - if (!pattern.matcher(fileName).matches()) { - continue; - } - - //Init file - File currentFile = new File(dataFolder, fileName); - - //Make sure its not a directory (needed?) - if(currentFile.isDirectory()) - continue; - - try { - //TODO: Valid? - ConfigCollections customConfig = (ConfigCollections) getConfigClass(configPrefix).getConstructor(String.class).newInstance(configPrefix); - collection.addAll(customConfig.getLoadedCollection()); - - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - } - } - - private String getVanillaConfigName(String configPrefix) - { - return configPrefix+DEFAULT_MULTICONFIG_FILENAME_SUFFIX; - } - - private Class getConfigClass(String configPrefix) - { - switch(configPrefix) { - case "repair": - return RepairConfig.class; - case "salvage": - return SalvageConfig.class; - default: - mcMMO.p.getLogger().severe("[DEBUG] Config Class is null!"); - return null; - } - } - -} diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java index 6452832ff..3b3a26b05 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java @@ -1,7 +1,8 @@ package com.gmail.nossr50.config.collectionconfigs; -import com.gmail.nossr50.config.ConfigCollections; +import com.gmail.nossr50.config.ConfigCollection; import com.gmail.nossr50.datatypes.skills.MaterialType; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.repairables.RepairableFactory; import com.gmail.nossr50.util.ItemUtils; @@ -12,28 +13,16 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; import java.util.List; /** * This config */ -public class RepairConfig extends ConfigCollections { - private List repairables; - +public class RepairConfig extends ConfigCollection { public RepairConfig(String fileName) { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); - } - - @Override - public void unload() { - repairables = null; - } - - @Override - public Collection getLoadedCollection() { - return repairables == null ? new ArrayList() : repairables; + //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, false); } /** @@ -47,9 +36,7 @@ public class RepairConfig extends ConfigCollections { } @Override - public void loadKeys() { - repairables = new ArrayList(); - + public void register() { ConfigurationNode repairablesNode = getUserRootNode().getNode("Repairables"); List repairablesNodeChildrenList = repairablesNode.getChildrenList(); Iterator configIter = repairablesNodeChildrenList.iterator(); @@ -164,7 +151,7 @@ public class RepairConfig extends ConfigCollections { if (noErrorsInRepairable(reason)) { Repairable repairable = RepairableFactory.getRepairable(itemType, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairConfigItemCategory, repairMaterialType, xpMultiplier); - repairables.add(repairable); + genericCollection.add(repairable); } } } diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java index 2eacad58a..5f314b353 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java @@ -1,8 +1,9 @@ package com.gmail.nossr50.config.collectionconfigs; -import com.gmail.nossr50.config.ConfigCollections; +import com.gmail.nossr50.config.ConfigCollection; import com.gmail.nossr50.datatypes.skills.ItemType; import com.gmail.nossr50.datatypes.skills.MaterialType; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; import com.gmail.nossr50.skills.salvage.salvageables.SalvageableFactory; import com.gmail.nossr50.util.ItemUtils; @@ -12,25 +13,14 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Set; -public class SalvageConfig extends ConfigCollections { - private List salvageables; +public class SalvageConfig extends ConfigCollection { public SalvageConfig(String fileName) { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); - } - - @Override - public Collection getLoadedCollection() { - return salvageables == null ? new ArrayList() : salvageables; - } - - @Override - public void unload() { - salvageables = null; + //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, false); } /** @@ -44,9 +34,7 @@ public class SalvageConfig extends ConfigCollections { } @Override - protected void loadKeys() { - salvageables = new ArrayList(); - + public void register() { ConfigurationSection section = config.getConfigurationSection("Salvageables"); Set keys = section.getKeys(false); @@ -149,7 +137,7 @@ public class SalvageConfig extends ConfigCollections { if (noErrorsInSalvageable(reason)) { Salvageable salvageable = SalvageableFactory.getSalvageable(itemMaterial, salvageMaterial, salvageMetadata, minimumLevel, maximumQuantity, maximumDurability, salvageItemType, salvageMaterialType, xpMultiplier); - salvageables.add(salvageable); + genericCollection.add(salvageable); } } } diff --git a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java index 2858cb264..78fd9476f 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -5,8 +5,9 @@ import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.skills.MaterialType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.alchemy.PotionStage; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.StringUtils; -import com.sk89q.worldedit.world.block.BlockType; +import org.bukkit.Material; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; import org.bukkit.entity.EntityType; @@ -77,7 +78,8 @@ public class ExperienceConfig extends ConfigValidated { //TODO: Should merge be false? Seems okay to leave it as true.. private ExperienceConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true); + //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "experience.yml", true); } public static ExperienceConfig getInstance() { @@ -305,11 +307,11 @@ public class ExperienceConfig extends ConfigValidated { /* Combat XP Multipliers */ public double getCombatXP(EntityType entity) { - return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, entity.getConfigName()); + return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity)); } public double getAnimalsXP(EntityType entity) { - return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, entity.getConfigName()); + return getDoubleValue(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity)); } public double getAnimalsXP() { @@ -317,7 +319,7 @@ public class ExperienceConfig extends ConfigValidated { } public boolean hasCombatXP(EntityType entity) { - return hasNode(EXPERIENCE, COMBAT, MULTIPLIER1, entity.getConfigName()); + return hasNode(EXPERIENCE, COMBAT, MULTIPLIER1, StringUtils.getEntityConfigName(entity)); } /* Materials */ @@ -328,9 +330,10 @@ public class ExperienceConfig extends ConfigValidated { * @param blockType the type of block * @return the raw amount of XP for this block before modifiers */ - public int getXp(PrimarySkillType skill, BlockType blockType) { + //public int getXp(PrimarySkillType skill, BlockType blockType) { + public int getXp(PrimarySkillType skill, Material blockType) { //TODO: This is going to need to be changed, this code here is only placeholder - String[] path = new String[]{ EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.getConfigName() }; + String[] path = new String[]{ EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.toString()}; return getIntValue(path); } @@ -342,10 +345,10 @@ public class ExperienceConfig extends ConfigValidated { * @param blockType the type of block * @return true if the block does give XP */ - public boolean doesBlockGiveSkillXP(PrimarySkillType skill, BlockType blockType) { + public boolean doesBlockGiveSkillXP(PrimarySkillType skill, Material blockType) { //TODO: This used to support wildcard characters, seems a bit unnecessary to do so. //TODO: This is going to need to be changed, this code here is only placeholder - String[] path = new String[] {EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.getConfigName()}; + String[] path = new String[] {EXPERIENCE, StringUtils.getCapitalized(skill.toString()), blockType.toString()}; return hasNode(path); } @@ -443,6 +446,6 @@ public class ExperienceConfig extends ConfigValidated { /* Taming */ public int getTamingXP(EntityType type) { - return getIntValue(EXPERIENCE, TAMING, ANIMAL_TAMING, type.getConfigName()); + return getIntValue(EXPERIENCE, TAMING, ANIMAL_TAMING, StringUtils.getEntityConfigName(type)); } } diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java index a8b44428e..10c64ea8d 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomArmorConfig.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.config.mods; -import com.gmail.nossr50.config.ConfigCollections; +import com.gmail.nossr50.config.ConfigCollection; import com.gmail.nossr50.datatypes.skills.MaterialType; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.repair.repairables.Repairable; @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -public class CustomArmorConfig extends ConfigCollections { +public class CustomArmorConfig extends ConfigCollection { public List customBoots = new ArrayList(); public List customChestplates = new ArrayList(); public List customHelmets = new ArrayList(); @@ -24,7 +24,7 @@ public class CustomArmorConfig extends ConfigCollections { protected CustomArmorConfig(String fileName) { //super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false); - super(mcMMO.p.getDataFolder().getPath() + "mods", fileName, false); loadKeys(); + super(mcMMO.p.getDataFolder().getPath() + "mods", fileName, false); register(); } /** @@ -38,7 +38,7 @@ public class CustomArmorConfig extends ConfigCollections { } @Override - public void loadKeys() { + public void register() { loadArmor("Boots", customBoots); loadArmor("Chestplates", customChestplates); loadArmor("Helmets", customHelmets); diff --git a/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java b/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java index 66fc5ec7e..c3e905fef 100644 --- a/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java +++ b/src/main/java/com/gmail/nossr50/config/mods/CustomBlockConfig.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.config.mods; -import com.gmail.nossr50.config.ConfigCollections; +import com.gmail.nossr50.config.ConfigCollection; import com.gmail.nossr50.datatypes.mods.CustomBlock; import com.gmail.nossr50.mcMMO; import org.bukkit.Material; @@ -11,7 +11,7 @@ import java.util.HashMap; import java.util.List; import java.util.Set; -public class CustomBlockConfig extends ConfigCollections { +public class CustomBlockConfig extends ConfigCollection { public List customExcavationBlocks = new ArrayList<>(); public List customHerbalismBlocks = new ArrayList<>(); public List customMiningBlocks = new ArrayList<>(); @@ -25,11 +25,11 @@ public class CustomBlockConfig extends ConfigCollections { protected CustomBlockConfig(String fileName) { //super(McmmoCore.getDataFolderPath().getPath() + "mods", fileName, false); super(mcMMO.p.getDataFolder().getPath() + "mods", fileName, false); - loadKeys(); + register(); } @Override - protected void loadKeys() { + protected void register() { loadBlocks("Excavation", customExcavationBlocks); loadBlocks("Herbalism", customHerbalismBlocks); loadBlocks("Mining", customMiningBlocks); diff --git a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java index bc92933a2..f2591a037 100644 --- a/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java +++ b/src/main/java/com/gmail/nossr50/config/skills/alchemy/PotionConfig.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.config.skills.alchemy; -import com.gmail.nossr50.config.ConfigCollections; +import com.gmail.nossr50.config.ConfigCollection; import com.gmail.nossr50.datatypes.skills.alchemy.AlchemyPotion; import com.gmail.nossr50.mcMMO; import org.bukkit.Color; @@ -14,8 +14,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class PotionConfig extends ConfigCollections { - private static PotionConfig instance; +public class PotionConfig extends ConfigCollection { private List concoctionsIngredientsTierOne = new ArrayList(); private List concoctionsIngredientsTierTwo = new ArrayList(); @@ -28,21 +27,23 @@ public class PotionConfig extends ConfigCollections { private Map potionMap = new HashMap(); - private PotionConfig() { - super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"potions.yml"); - loadKeys(); + public PotionConfig() { + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true); + register(); } - public static PotionConfig getInstance() { - if (instance == null) { - instance = new PotionConfig(); - } - - return instance; + /** + * The version of this config + * + * @return + */ + @Override + public double getConfigVersion() { + return 1; } @Override - protected void loadKeys() { + public void register() { loadConcoctions(); loadPotionMap(); } diff --git a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java index 9813d7b2b..502aee78b 100755 --- a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.config.treasure; -import com.gmail.nossr50.config.ConfigCollections; +import com.gmail.nossr50.config.ConfigCollection; import com.gmail.nossr50.datatypes.treasure.*; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.util.EnchantmentUtils; @@ -20,9 +20,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -public class TreasureConfig extends ConfigCollections { +public class TreasureConfig extends ConfigCollection { - private static TreasureConfig instance; + //private static TreasureConfig instance; public HashMap> excavationMap = new HashMap>(); @@ -32,18 +32,18 @@ public class TreasureConfig extends ConfigCollections { public HashMap> fishingRewards = new HashMap>(); public HashMap> fishingEnchantments = new HashMap>(); - private TreasureConfig() { + public TreasureConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"treasures.yml"); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "treasures.yml"); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "treasures.yml", true); } - public static TreasureConfig getInstance() { + /*public static TreasureConfig getInstance() { if (instance == null) { instance = new TreasureConfig(); } return instance; - } + }*/ @Override protected boolean validateKeys() { @@ -82,7 +82,7 @@ public class TreasureConfig extends ConfigCollections { } @Override - protected void loadKeys() { + protected void register() { if (config.getConfigurationSection("Treasures") != null) { backup(); return; diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java index 95f54c7c3..8140b5527 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/subskills/AbstractSubSkill.java @@ -41,7 +41,7 @@ public abstract class AbstractSubSkill implements SubSkill, Interaction, Rank, S @Override @Deprecated public boolean isEnabled() { //TODO: This might be troublesome... - return CoreSkillsMainConfig.getInstance().isSkillEnabled(this); + return CoreSkillConfig.getInstance().isSkillEnabled(this); } /** diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 4443c49c2..c9ea1a464 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -1,13 +1,8 @@ package com.gmail.nossr50; -import com.gmail.nossr50.config.MainConfig; -import com.gmail.nossr50.config.WorldBlacklist; -import com.gmail.nossr50.config.mods.ArmorConfigManager; -import com.gmail.nossr50.config.mods.BlockConfigManager; -import com.gmail.nossr50.config.mods.EntityConfigManager; -import com.gmail.nossr50.config.mods.ToolConfigManager; -import com.gmail.nossr50.config.skills.repair.RepairConfigManager; -import com.gmail.nossr50.config.skills.salvage.SalvageConfigManager; +import com.gmail.nossr50.config.*; +import com.gmail.nossr50.config.collectionconfigs.ConfigManager; +import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.database.DatabaseManager; import com.gmail.nossr50.database.DatabaseManagerFactory; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; @@ -24,13 +19,8 @@ import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask; import com.gmail.nossr50.runnables.player.PowerLevelUpdatingTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.skills.alchemy.Alchemy; -import com.gmail.nossr50.skills.child.ChildConfig; -import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.repairables.RepairableManager; -import com.gmail.nossr50.skills.repair.repairables.SimpleRepairableManager; -import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; import com.gmail.nossr50.skills.salvage.salvageables.SalvageableManager; -import com.gmail.nossr50.skills.salvage.salvageables.SimpleSalvageableManager; import com.gmail.nossr50.util.*; import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager; import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory; @@ -54,14 +44,11 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; public class mcMMO extends JavaPlugin { /* Managers */ private static ChunkManager placeStore; - private static RepairableManager repairableManager; - private static SalvageableManager salvageableManager; + private static ConfigManager configManager; private static ModManager modManager; private static DatabaseManager databaseManager; private static FormulaManager formulaManager; @@ -217,7 +204,7 @@ public class mcMMO extends JavaPlugin { } //Init the blacklist - worldBlacklist = new WorldBlacklist(this); + worldBlacklist = new WorldBlacklist(); } @Override @@ -274,6 +261,11 @@ public class mcMMO extends JavaPlugin { } databaseManager.onDisable(); + + //Unload configs last + configManager.unloadAllConfigsAndRegisters(); + + debug("Was disabled."); // How informative! } @@ -412,54 +404,9 @@ public class mcMMO extends JavaPlugin { } private void loadConfigFiles() { - // New Config System - - ConfigurableTest.getInstance(); //Init - - // End New Config System + configManager = new ConfigManager(); - // Force the loading of config files - TreasureConfig.getInstance(); - HiddenConfig.getInstance(); - AdvancedConfig.getInstance(); - PotionConfig.getInstance(); - CoreSkillsMainConfig.getInstance(); - SoundConfig.getInstance(); - RankConfig.getInstance(); - - new ChildConfig(); - - List repairables = new ArrayList(); - List salvageables = new ArrayList(); - - if (MainConfig.getInstance().getToolModsEnabled()) { - new ToolConfigManager(this); - } - - if (MainConfig.getInstance().getArmorModsEnabled()) { - new ArmorConfigManager(this); - } - - if (MainConfig.getInstance().getBlockModsEnabled()) { - new BlockConfigManager(this); - } - - if (MainConfig.getInstance().getEntityModsEnabled()) { - new EntityConfigManager(this); - } - - // Load repair configs, make manager, and register them at this time - repairables.addAll(new RepairConfigManager(this).getLoadedRepairables()); - repairables.addAll(modManager.getLoadedRepairables()); - repairableManager = new SimpleRepairableManager(repairables.size()); - repairableManager.registerRepairables(repairables); - - // Load salvage configs, make manager and register them at this time - SalvageConfigManager sManager = new SalvageConfigManager(this); - salvageables.addAll(sManager.getLoadedSalvageables()); - salvageableManager = new SimpleSalvageableManager(salvageables.size()); - salvageableManager.registerSalvageables(salvageables); } private void registerEvents() { @@ -483,13 +430,13 @@ public class mcMMO extends JavaPlugin { * Acrobatics skills */ - if(CoreSkillsMainConfig.getInstance().isPrimarySkillEnabled(PrimarySkillType.ACROBATICS)) + if(CoreSkillsConfig.getInstance().isPrimarySkillEnabled(PrimarySkillType.ACROBATICS)) { System.out.println("[mcMMO]" + " enabling Acrobatics Skills"); //TODO: Should do this differently Roll roll = new Roll(); - CoreSkillsMainConfig.getInstance().isSkillEnabled(roll); + CoreSkillsConfig.getInstance().isSkillEnabled(roll); InteractionManager.registerSubSkill(new Roll()); } } diff --git a/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java b/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java index 91a0c419f..e350e798d 100644 --- a/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java +++ b/src/main/java/com/gmail/nossr50/skills/child/ChildConfig.java @@ -1,6 +1,5 @@ package com.gmail.nossr50.skills.child; -import com.gmail.nossr50.config.AutoUpdateConfigLoader; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.util.StringUtils; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java index 901b8442f..119ad2108 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/RepairManager.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.skills.repair; +import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.MainConfig; +import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.interactions.NotificationType; import com.gmail.nossr50.datatypes.player.McMMOPlayer; diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableManager.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableManager.java index fff27e718..82cac0145 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/RepairableManager.java @@ -1,11 +1,12 @@ package com.gmail.nossr50.skills.repair.repairables; +import com.gmail.nossr50.config.Unload; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.List; -public interface RepairableManager { +public interface RepairableManager extends Unload { /** * Register a repairable with the RepairManager * diff --git a/src/main/java/com/gmail/nossr50/skills/repair/repairables/SimpleRepairableManager.java b/src/main/java/com/gmail/nossr50/skills/repair/repairables/SimpleRepairableManager.java index 8fe95d830..37bd0305a 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/repairables/SimpleRepairableManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/repairables/SimpleRepairableManager.java @@ -1,20 +1,24 @@ package com.gmail.nossr50.skills.repair.repairables; +import com.gmail.nossr50.config.Unload; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import java.util.Collection; import java.util.HashMap; import java.util.List; public class SimpleRepairableManager implements RepairableManager { private HashMap repairables; - public SimpleRepairableManager() { - this(55); + @Override + public void unload() { + repairables.clear(); } - public SimpleRepairableManager(int repairablesSize) { - this.repairables = new HashMap(repairablesSize); + public SimpleRepairableManager(List repairablesCollection) { + this.repairables = new HashMap(repairablesCollection.size()); + registerRepairables(repairablesCollection); } @Override diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SalvageableManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SalvageableManager.java index fb9f4b84e..76f673992 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SalvageableManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SalvageableManager.java @@ -1,11 +1,12 @@ package com.gmail.nossr50.skills.salvage.salvageables; +import com.gmail.nossr50.config.Unload; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.List; -public interface SalvageableManager { +public interface SalvageableManager extends Unload { /** * Register a salvageable with the SalvageManager * diff --git a/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SimpleSalvageableManager.java b/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SimpleSalvageableManager.java index 872364e64..48c2f6d39 100644 --- a/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SimpleSalvageableManager.java +++ b/src/main/java/com/gmail/nossr50/skills/salvage/salvageables/SimpleSalvageableManager.java @@ -10,12 +10,18 @@ import java.util.List; public class SimpleSalvageableManager implements SalvageableManager { private HashMap salvageables; - public SimpleSalvageableManager() { + /*public SimpleSalvageableManager() { this(55); + }*/ + + @Override + public void unload() { + salvageables.clear(); } - public SimpleSalvageableManager(int salvageablesSize) { - this.salvageables = new HashMap(salvageablesSize); + public SimpleSalvageableManager(List salvageablesCollection) { + this.salvageables = new HashMap(salvageablesCollection.size()); + registerSalvageables(salvageablesCollection); } @Override diff --git a/src/main/java/com/gmail/nossr50/util/StringUtils.java b/src/main/java/com/gmail/nossr50/util/StringUtils.java index 31d1e77d4..6de3dcf5a 100644 --- a/src/main/java/com/gmail/nossr50/util/StringUtils.java +++ b/src/main/java/com/gmail/nossr50/util/StringUtils.java @@ -20,6 +20,16 @@ public class StringUtils { return target.substring(0, 1).toUpperCase() + target.substring(1).toLowerCase(); } + /** + * Gets the name of the entity that the config file is expecting + * @param entityType target entity type + * @return the config friendly entity type string + */ + public static String getEntityConfigName(EntityType entityType) + { + return entityType.toString(); + } + public static String getPrettyItemString(Material material) { return createPrettyString(material.toString()); }