From 6604f981404bd08da863dcd468bcfc951f640909 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 20 Feb 2019 22:08:46 -0800 Subject: [PATCH] Updating constructors, updating node address helper methods --- .../gmail/nossr50/config/AdvancedConfig.java | 12 ++--- .../nossr50/config/ConfigCollection.java | 39 +++++++++++----- .../gmail/nossr50/config/ConfigValidated.java | 20 ++++++-- .../nossr50/config/CoreSkillsConfig.java | 2 +- .../com/gmail/nossr50/config/MainConfig.java | 2 +- .../com/gmail/nossr50/config/RankConfig.java | 2 +- .../com/gmail/nossr50/config/SoundConfig.java | 2 +- .../MultiConfigContainer.java | 8 ++-- .../collectionconfigs/RepairConfig.java | 2 +- .../collectionconfigs/SalvageConfig.java | 2 +- .../config/experience/ExperienceConfig.java | 2 +- .../config/party/ItemWeightConfig.java | 2 +- .../config/skills/alchemy/PotionConfig.java | 2 +- .../datatypes/skills/SubSkillType.java | 12 +++-- .../nossr50/listeners/BlockListener.java | 12 ++--- .../nossr50/listeners/EntityListener.java | 2 + .../gmail/nossr50/util/skills/SkillUtils.java | 46 +++++++++---------- 17 files changed, 96 insertions(+), 73 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index b9af9bf72..6b0d436fc 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -125,8 +125,8 @@ public class AdvancedConfig extends ConfigValidated { //private static AdvancedConfig instance; public AdvancedConfig() { - //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true); + //super(mcMMO.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true, true); } @Override @@ -509,7 +509,7 @@ public class AdvancedConfig extends ConfigValidated { * @return the level at which abilities stop increasing in length */ public int getAbilityLengthCap() { - if(!McmmoCore.isRetroModeEnabled()) + if(!mcMMO.isRetroModeEnabled()) return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, STANDARD, CAP_LEVEL); else return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, RETRO_MODE, CAP_LEVEL); @@ -521,7 +521,7 @@ public class AdvancedConfig extends ConfigValidated { * @return the number of levels required per ability length increase */ public int getAbilityLength() { - if(!McmmoCore.isRetroModeEnabled()) + if(!mcMMO.isRetroModeEnabled()) return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, STANDARD, INCREASE_LEVEL); else return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, RETRO_MODE, INCREASE_LEVEL); @@ -539,7 +539,7 @@ public class AdvancedConfig extends ConfigValidated { public int getMaxBonusLevel(SubSkillType subSkillType) { String[] category = subSkillType.getAdvConfigAddress(); - if(!McmmoCore.isRetroModeEnabled()) + if(!mcMMO.isRetroModeEnabled()) return getIntValue(category[0], category[1], category[2], MAX_BONUS_LEVEL, STANDARD); else return getIntValue(category[0], category[1], category[2], MAX_BONUS_LEVEL, RETRO_MODE); @@ -635,7 +635,7 @@ public class AdvancedConfig extends ConfigValidated { public int getArmorImpactIncreaseLevel() { int increaseLevel = getIntValue(SKILLS, AXES, ARMOR_IMPACT, INCREASE_LEVEL); - if(McmmoCore.isRetroModeEnabled()) + if(mcMMO.isRetroModeEnabled()) return increaseLevel * 10; return increaseLevel; diff --git a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java index 8f65e8839..16a4131e1 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigCollection.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigCollection.java @@ -12,8 +12,14 @@ public abstract class ConfigCollection extends Config implements Registers, G //The collection held by this class protected Collection genericCollection; - public ConfigCollection(String pathToParentFolder, String relativePath, boolean mergeNewKeys) { - super(pathToParentFolder, relativePath, mergeNewKeys); + /** + * @param parentFolderPath Path to the "parent" folder on disk + * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files + * @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load + * @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path + */ + public ConfigCollection(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults) { + super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults); //init initCollection(); @@ -22,21 +28,30 @@ public abstract class ConfigCollection extends Config implements Registers, G register(); } + /** + * @param parentFolderPath Path to the "parent" folder on disk + * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files + * @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load + * @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path + */ + public ConfigCollection(File parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults) { + super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults); + + //init + initCollection(); + + //load + register(); + } + + /** + * Initializes the generic collection held by this class + */ 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; diff --git a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java index 2b779233e..a5cbec0c9 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigValidated.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigValidated.java @@ -10,15 +10,27 @@ import java.util.List; * This class is used for config files that validate their entries */ public abstract class ConfigValidated extends Config implements DefaultKeys { - public ConfigValidated(String parentFolderPath, String relativePath, boolean mergeNewKeys) + /** + * @param parentFolderPath Path to the "parent" folder on disk + * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files + * @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load + * @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path + */ + public ConfigValidated(String parentFolderPath, String relativePath, boolean mergeNewKeys, boolean copyDefaults) { - super(parentFolderPath, relativePath, mergeNewKeys); + super(parentFolderPath, relativePath, mergeNewKeys, copyDefaults); validateEntries(); } - public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys) + /** + * @param parentFolderFile File for the "parent" folder on disk + * @param relativePath Path to the config relative to the "parent" folder, this should mirror internal structure of resource files + * @param mergeNewKeys if true, the users config will add keys found in the internal file that are missing from the users file during load + * @param copyDefaults if true, the users config file when it is first made will be a copy of an internal resource file of the same name and path + */ + public ConfigValidated(File parentFolderFile, String relativePath, boolean mergeNewKeys, boolean copyDefaults) { - super(parentFolderFile, relativePath, mergeNewKeys); + super(parentFolderFile, relativePath, mergeNewKeys, copyDefaults); validateEntries(); } diff --git a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java index 1cbd22f6c..6a94fa7c4 100644 --- a/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java +++ b/src/main/java/com/gmail/nossr50/config/CoreSkillsConfig.java @@ -11,7 +11,7 @@ public class CoreSkillsConfig extends Config { public CoreSkillsConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(),"coreskills.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(),"coreskills.yml", true, true); } /** diff --git a/src/main/java/com/gmail/nossr50/config/MainConfig.java b/src/main/java/com/gmail/nossr50/config/MainConfig.java index 1c3fd9081..c1814f95c 100644 --- a/src/main/java/com/gmail/nossr50/config/MainConfig.java +++ b/src/main/java/com/gmail/nossr50/config/MainConfig.java @@ -204,7 +204,7 @@ public class MainConfig extends ConfigValidated { public MainConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "config.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "config.yml", true, true); } /** diff --git a/src/main/java/com/gmail/nossr50/config/RankConfig.java b/src/main/java/com/gmail/nossr50/config/RankConfig.java index 855689573..ebaa76f73 100644 --- a/src/main/java/com/gmail/nossr50/config/RankConfig.java +++ b/src/main/java/com/gmail/nossr50/config/RankConfig.java @@ -12,7 +12,7 @@ public class RankConfig extends ConfigValidated { public RankConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(),"skillranks.yml", true, true); //this.instance = this; } diff --git a/src/main/java/com/gmail/nossr50/config/SoundConfig.java b/src/main/java/com/gmail/nossr50/config/SoundConfig.java index d3d465a34..4f4a4f0a0 100644 --- a/src/main/java/com/gmail/nossr50/config/SoundConfig.java +++ b/src/main/java/com/gmail/nossr50/config/SoundConfig.java @@ -11,7 +11,7 @@ public class SoundConfig extends ConfigValidated { public SoundConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "sounds.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "sounds.yml", true, true); } /** diff --git a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java index c2e485889..ca8bc44f8 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/MultiConfigContainer.java @@ -45,7 +45,7 @@ public class MultiConfigContainer implements Unload { //Load Configs //Vanilla Config - initConfigAndAddCollection(getVanillaConfigName(configPrefix)); + initConfigAndAddCollection(getVanillaConfigName(configPrefix), true); //Custom Configs loadCustomCollections(configPrefix); @@ -92,13 +92,13 @@ public class MultiConfigContainer implements Unload { * Initializes a config and attempts to load add its collection * @param configFileName the filename of the config to load */ - private void initConfigAndAddCollection(String configFileName) + private void initConfigAndAddCollection(String configFileName, Boolean copyDefaults) { mcMMO.p.getLogger().info("Reading from collection config - "+configFileName); ConfigCollection configCollection = null; try { - configCollection = (ConfigCollection) getConfigClass(collectionClassType).getConstructor(String.class).newInstance(configFileName); + configCollection = (ConfigCollection) getConfigClass(collectionClassType).getConstructor(String.class, Boolean.class).newInstance(configFileName, copyDefaults); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { @@ -145,7 +145,7 @@ public class MultiConfigContainer implements Unload { continue; //Load and add the collections - initConfigAndAddCollection(fileName); + initConfigAndAddCollection(fileName, false); } } 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 71650c48c..f44e0cc75 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/RepairConfig.java @@ -35,7 +35,7 @@ public class RepairConfig extends ConfigCollection { public RepairConfig(String fileName, boolean merge) { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, merge); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, false, merge); } /** 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 3f96ee91a..fa10c1564 100644 --- a/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java +++ b/src/main/java/com/gmail/nossr50/config/collectionconfigs/SalvageConfig.java @@ -32,7 +32,7 @@ public class SalvageConfig extends ConfigCollection { public SalvageConfig(String fileName, boolean merge) { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, merge); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), fileName, false, merge); } /** 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 543d303aa..8f68091e6 100644 --- a/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java +++ b/src/main/java/com/gmail/nossr50/config/experience/ExperienceConfig.java @@ -79,7 +79,7 @@ public class ExperienceConfig extends ConfigValidated { //TODO: Should merge be false? Seems okay to leave it as true.. public ExperienceConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "experience.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "experience.yml", true, true); } /** diff --git a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java index 6ec03aeec..ac19a8849 100644 --- a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java +++ b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java @@ -16,7 +16,7 @@ public class ItemWeightConfig extends Config { public ItemWeightConfig() { //super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml"); - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "itemweights.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "itemweights.yml", true, true); } /** 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 f2591a037..2dd004424 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 @@ -28,7 +28,7 @@ public class PotionConfig extends ConfigCollection { private Map potionMap = new HashMap(); public PotionConfig() { - super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true); + super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true); register(); } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java b/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java index 5495d5336..39111a8ba 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java @@ -138,16 +138,20 @@ public enum SubSkillType { * Returns the root address for this skill in the advanced.yml file * @return the root address for this skill in advanced.yml */ - public String getAdvConfigAddress() { - return "Skills." + StringUtils.getCapitalized(getParentSkill().toString()) + "." + getConfigName(toString()); + public String[] getAdvConfigAddress() { + //return "Skills." + StringUtils.getCapitalized(getParentSkill().toString()) + "." + getConfigName(toString()); + //TODO: Reduce string operations + return new String[]{"Skills", StringUtils.getCapitalized(getParentSkill().toString()), getConfigName(toString())}; } /** * Returns the root address for this skill in the rankskills.yml file * @return the root address for this skill in rankskills.yml */ - public String getRankConfigAddress() { - return StringUtils.getCapitalized(getParentSkill().toString()) + "." + getConfigName(toString()); + public String[] getRankConfigAddress() { + //return StringUtils.getCapitalized(getParentSkill().toString()) + "." + getConfigName(toString()); + //TODO: Reduce string operations + return new String[]{StringUtils.getCapitalized(getParentSkill().toString()), getConfigName(toString())}; } /** diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 61af32fd4..80e827ae4 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -2,6 +2,7 @@ package com.gmail.nossr50.listeners; import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.config.WorldBlacklist; +import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType; @@ -611,15 +612,8 @@ public class BlockListener implements Listener { } public void cleanupAbilityTools(Player player, McMMOPlayer mcMMOPlayer, BlockState blockState, ItemStack heldItem) { - if (HiddenConfig.getInstance().useEnchantmentBuffs()) { - if ((ItemUtils.isPickaxe(heldItem) && !mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER)) || (ItemUtils.isShovel(heldItem) && !mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER))) { - SkillUtils.removeAbilityBuff(heldItem); - } - } else { - if ((mcMMOPlayer.getAbilityMode(SuperAbilityType.SUPER_BREAKER) && !BlockUtils.affectedBySuperBreaker(blockState)) || (mcMMOPlayer.getAbilityMode(SuperAbilityType.GIGA_DRILL_BREAKER) && !BlockUtils.affectedByGigaDrillBreaker(blockState))) { - SkillUtils.handleAbilitySpeedDecrease(player); - } - } + SkillUtils.removeAbilityBuff(heldItem); + SkillUtils.handleAbilitySpeedDecrease(player); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index d9579a43f..dfe47a032 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -1,7 +1,9 @@ package com.gmail.nossr50.listeners; +import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.config.WorldBlacklist; +import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.meta.OldName; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.SubSkillType; diff --git a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java index 2fbf00146..2357c09e7 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.util.skills; +import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainSource; @@ -129,28 +130,27 @@ public class SkillUtils { } public static void handleAbilitySpeedIncrease(Player player) { - if (HiddenConfig.getInstance().useEnchantmentBuffs()) { - ItemStack heldItem = player.getInventory().getItemInMainHand(); + ItemStack heldItem = player.getInventory().getItemInMainHand(); - if (heldItem == null || heldItem.getType() == Material.AIR) { - return; - } - - int efficiencyLevel = heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED); - ItemMeta itemMeta = heldItem.getItemMeta(); - List itemLore = new ArrayList(); - - if (itemMeta.hasLore()) { - itemLore = itemMeta.getLore(); - } - - itemLore.add("mcMMO Ability Tool"); - itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel + AdvancedConfig.getInstance().getEnchantBuff(), true); - - itemMeta.setLore(itemLore); - heldItem.setItemMeta(itemMeta); + if (heldItem == null || heldItem.getType() == Material.AIR) { + return; } - else { + + int efficiencyLevel = heldItem.getEnchantmentLevel(Enchantment.DIG_SPEED); + ItemMeta itemMeta = heldItem.getItemMeta(); + List itemLore = new ArrayList(); + + if (itemMeta.hasLore()) { + itemLore = itemMeta.getLore(); + } + + itemLore.add("mcMMO Ability Tool"); + itemMeta.addEnchant(Enchantment.DIG_SPEED, efficiencyLevel + AdvancedConfig.getInstance().getEnchantBuff(), true); + + itemMeta.setLore(itemLore); + heldItem.setItemMeta(itemMeta); + + /*else { int duration = 0; int amplifier = 0; @@ -183,14 +183,10 @@ public class SkillUtils { PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10); player.addPotionEffect(abilityBuff, true); - } + }*/ } public static void handleAbilitySpeedDecrease(Player player) { - if (!HiddenConfig.getInstance().useEnchantmentBuffs()) { - return; - } - for (ItemStack item : player.getInventory().getContents()) { removeAbilityBuff(item); }