Updating constructors, updating node address helper methods

This commit is contained in:
nossr50 2019-02-20 22:08:46 -08:00
parent b81ca84a99
commit 6604f98140
17 changed files with 96 additions and 73 deletions

View File

@ -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;

View File

@ -12,8 +12,14 @@ public abstract class ConfigCollection<T> extends Config implements Registers, G
//The collection held by this class
protected Collection<T> 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<T> 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<T> getLoadedCollection() {
return this.genericCollection;

View File

@ -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();
}

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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;
}

View File

@ -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);
}
/**

View File

@ -45,7 +45,7 @@ public class MultiConfigContainer<T> implements Unload {
//Load Configs
//Vanilla Config
initConfigAndAddCollection(getVanillaConfigName(configPrefix));
initConfigAndAddCollection(getVanillaConfigName(configPrefix), true);
//Custom Configs
loadCustomCollections(configPrefix);
@ -92,13 +92,13 @@ public class MultiConfigContainer<T> 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<T> implements Unload {
continue;
//Load and add the collections
initConfigAndAddCollection(fileName);
initConfigAndAddCollection(fileName, false);
}
}

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -28,7 +28,7 @@ public class PotionConfig extends ConfigCollection {
private Map<String, AlchemyPotion> potionMap = new HashMap<String, AlchemyPotion>();
public PotionConfig() {
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true);
register();
}

View File

@ -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())};
}
/**

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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<String> itemLore = new ArrayList<String>();
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<String> itemLore = new ArrayList<String>();
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);
}