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; //private static AdvancedConfig instance;
public AdvancedConfig() { public AdvancedConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true); //super(mcMMO.getDataFolderPath().getAbsoluteFile(), "advanced.yml", true);
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true); super(mcMMO.p.getDataFolder().getAbsoluteFile(), "advanced.yml", true, true);
} }
@Override @Override
@ -509,7 +509,7 @@ public class AdvancedConfig extends ConfigValidated {
* @return the level at which abilities stop increasing in length * @return the level at which abilities stop increasing in length
*/ */
public int getAbilityLengthCap() { public int getAbilityLengthCap() {
if(!McmmoCore.isRetroModeEnabled()) if(!mcMMO.isRetroModeEnabled())
return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, STANDARD, CAP_LEVEL); return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, STANDARD, CAP_LEVEL);
else else
return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, RETRO_MODE, CAP_LEVEL); 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 * @return the number of levels required per ability length increase
*/ */
public int getAbilityLength() { public int getAbilityLength() {
if(!McmmoCore.isRetroModeEnabled()) if(!mcMMO.isRetroModeEnabled())
return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, STANDARD, INCREASE_LEVEL); return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, STANDARD, INCREASE_LEVEL);
else else
return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, RETRO_MODE, INCREASE_LEVEL); return getIntValue(SKILLS, GENERAL, ABILITY, LENGTH, RETRO_MODE, INCREASE_LEVEL);
@ -539,7 +539,7 @@ public class AdvancedConfig extends ConfigValidated {
public int getMaxBonusLevel(SubSkillType subSkillType) { public int getMaxBonusLevel(SubSkillType subSkillType) {
String[] category = subSkillType.getAdvConfigAddress(); String[] category = subSkillType.getAdvConfigAddress();
if(!McmmoCore.isRetroModeEnabled()) if(!mcMMO.isRetroModeEnabled())
return getIntValue(category[0], category[1], category[2], MAX_BONUS_LEVEL, STANDARD); return getIntValue(category[0], category[1], category[2], MAX_BONUS_LEVEL, STANDARD);
else else
return getIntValue(category[0], category[1], category[2], MAX_BONUS_LEVEL, RETRO_MODE); 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() { public int getArmorImpactIncreaseLevel() {
int increaseLevel = getIntValue(SKILLS, AXES, ARMOR_IMPACT, INCREASE_LEVEL); int increaseLevel = getIntValue(SKILLS, AXES, ARMOR_IMPACT, INCREASE_LEVEL);
if(McmmoCore.isRetroModeEnabled()) if(mcMMO.isRetroModeEnabled())
return increaseLevel * 10; return increaseLevel * 10;
return increaseLevel; return increaseLevel;

View File

@ -12,8 +12,14 @@ public abstract class ConfigCollection<T> extends Config implements Registers, G
//The collection held by this class //The collection held by this class
protected Collection<T> genericCollection; 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 //init
initCollection(); initCollection();
@ -22,21 +28,30 @@ public abstract class ConfigCollection<T> extends Config implements Registers, G
register(); 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() { private void initCollection() {
if (genericCollection == null) if (genericCollection == null)
genericCollection = new ArrayList<>(); genericCollection = new ArrayList<>();
} }
public ConfigCollection(File pathToParentFolder, String relativePath, boolean mergeNewKeys) {
super(pathToParentFolder, relativePath, mergeNewKeys);
//init
initCollection();
//load
register();
}
@Override @Override
public Collection<T> getLoadedCollection() { public Collection<T> getLoadedCollection() {
return this.genericCollection; return this.genericCollection;

View File

@ -10,15 +10,27 @@ import java.util.List;
* This class is used for config files that validate their entries * This class is used for config files that validate their entries
*/ */
public abstract class ConfigValidated extends Config implements DefaultKeys { 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(); 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(); validateEntries();
} }

View File

@ -11,7 +11,7 @@ public class CoreSkillsConfig extends Config {
public CoreSkillsConfig() { public CoreSkillsConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"coreskills.yml", true); //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() { public MainConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "config.yml", true); //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() { public RankConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true); //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; //this.instance = this;
} }

View File

@ -11,7 +11,7 @@ public class SoundConfig extends ConfigValidated {
public SoundConfig() { public SoundConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "sounds.yml", true); //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 //Load Configs
//Vanilla Config //Vanilla Config
initConfigAndAddCollection(getVanillaConfigName(configPrefix)); initConfigAndAddCollection(getVanillaConfigName(configPrefix), true);
//Custom Configs //Custom Configs
loadCustomCollections(configPrefix); loadCustomCollections(configPrefix);
@ -92,13 +92,13 @@ public class MultiConfigContainer<T> implements Unload {
* Initializes a config and attempts to load add its collection * Initializes a config and attempts to load add its collection
* @param configFileName the filename of the config to load * @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); mcMMO.p.getLogger().info("Reading from collection config - "+configFileName);
ConfigCollection configCollection = null; ConfigCollection configCollection = null;
try { 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) { } catch (InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -145,7 +145,7 @@ public class MultiConfigContainer<T> implements Unload {
continue; continue;
//Load and add the collections //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) { public RepairConfig(String fileName, boolean merge) {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); //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) { public SalvageConfig(String fileName, boolean merge) {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), fileName, false); //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.. //TODO: Should merge be false? Seems okay to leave it as true..
public ExperienceConfig() { public ExperienceConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "experience.yml", true); //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() { public ItemWeightConfig() {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(), "itemweights.yml"); //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>(); private Map<String, AlchemyPotion> potionMap = new HashMap<String, AlchemyPotion>();
public PotionConfig() { public PotionConfig() {
super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true); super(mcMMO.p.getDataFolder().getAbsoluteFile(), "potions.yml", true, true);
register(); register();
} }

View File

@ -138,16 +138,20 @@ public enum SubSkillType {
* Returns the root address for this skill in the advanced.yml file * Returns the root address for this skill in the advanced.yml file
* @return the root address for this skill in advanced.yml * @return the root address for this skill in advanced.yml
*/ */
public String getAdvConfigAddress() { public String[] getAdvConfigAddress() {
return "Skills." + StringUtils.getCapitalized(getParentSkill().toString()) + "." + getConfigName(toString()); //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 * Returns the root address for this skill in the rankskills.yml file
* @return the root address for this skill in rankskills.yml * @return the root address for this skill in rankskills.yml
*/ */
public String getRankConfigAddress() { public String[] getRankConfigAddress() {
return StringUtils.getCapitalized(getParentSkill().toString()) + "." + getConfigName(toString()); //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.MainConfig;
import com.gmail.nossr50.config.WorldBlacklist; 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.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; 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) { 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); 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.handleAbilitySpeedDecrease(player);
} }
}
}
} }

View File

@ -1,7 +1,9 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.config.WorldBlacklist; 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.meta.OldName;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.util.skills; package com.gmail.nossr50.util.skills;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.MainConfig; import com.gmail.nossr50.config.MainConfig;
import com.gmail.nossr50.datatypes.experience.XPGainReason; import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource; import com.gmail.nossr50.datatypes.experience.XPGainSource;
@ -129,7 +130,6 @@ public class SkillUtils {
} }
public static void handleAbilitySpeedIncrease(Player player) { 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) { if (heldItem == null || heldItem.getType() == Material.AIR) {
@ -149,8 +149,8 @@ public class SkillUtils {
itemMeta.setLore(itemLore); itemMeta.setLore(itemLore);
heldItem.setItemMeta(itemMeta); heldItem.setItemMeta(itemMeta);
}
else { /*else {
int duration = 0; int duration = 0;
int amplifier = 0; int amplifier = 0;
@ -183,14 +183,10 @@ public class SkillUtils {
PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10); PotionEffect abilityBuff = new PotionEffect(PotionEffectType.FAST_DIGGING, duration + ticks, amplifier + 10);
player.addPotionEffect(abilityBuff, true); player.addPotionEffect(abilityBuff, true);
} }*/
} }
public static void handleAbilitySpeedDecrease(Player player) { public static void handleAbilitySpeedDecrease(Player player) {
if (!HiddenConfig.getInstance().useEnchantmentBuffs()) {
return;
}
for (ItemStack item : player.getInventory().getContents()) { for (ItemStack item : player.getInventory().getContents()) {
removeAbilityBuff(item); removeAbilityBuff(item);
} }