mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-02 20:45:28 +02:00
Refactoring code part 1 to prep for adding a bunch of unit tests
This commit is contained in:
@@ -6,25 +6,17 @@ import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AdvancedConfig extends AutoUpdateConfigLoader {
|
||||
private static AdvancedConfig instance;
|
||||
|
||||
private AdvancedConfig() {
|
||||
super("advanced.yml");
|
||||
public AdvancedConfig(File dataFolder) {
|
||||
super("advanced.yml", dataFolder);
|
||||
validate();
|
||||
}
|
||||
|
||||
public static AdvancedConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new AdvancedConfig();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateKeys() {
|
||||
// Validate all the settings!
|
||||
@@ -68,15 +60,6 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
|
||||
reason.add("Skills.Acrobatics.GracefulRoll.DamageThreshold should be at least 0!");
|
||||
}
|
||||
|
||||
/* ALCHEMY */
|
||||
/*if (getCatalysisUnlockLevel() < 0) {
|
||||
reason.add("Skills.Alchemy.Catalysis.UnlockLevel should be at least 0!");
|
||||
}
|
||||
|
||||
if (getCatalysisMaxBonusLevel() <= getCatalysisUnlockLevel()) {
|
||||
reason.add("Skills.Alchemy.Catalysis.MaxBonusLevel should be greater than Skills.Alchemy.Catalysis.UnlockLevel!");
|
||||
}*/
|
||||
|
||||
if (getCatalysisMinSpeed() <= 0) {
|
||||
reason.add("Skills.Alchemy.Catalysis.MinSpeed must be greater than 0!");
|
||||
}
|
||||
@@ -85,21 +68,6 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
|
||||
reason.add("Skills.Alchemy.Catalysis.MaxSpeed should be at least Skills.Alchemy.Catalysis.MinSpeed!");
|
||||
}
|
||||
|
||||
/*List<Alchemy.Tier> alchemyTierList = Arrays.asList(Alchemy.Tier.values());
|
||||
for (Alchemy.Tier tier : alchemyTierList) {
|
||||
if (getConcoctionsTierLevel(tier) < 0) {
|
||||
reason.add("Skills.Alchemy.Rank_Levels.Rank_" + rank + " should be at least 0!");
|
||||
}
|
||||
|
||||
if (tier != Alchemy.Tier.fromNumerical(Alchemy.Tier.values().length)) {
|
||||
Alchemy.Tier nextTier = alchemyTierList.get(alchemyTierList.indexOf(tier) - 1);
|
||||
|
||||
if (getConcoctionsTierLevel(tier) > getConcoctionsTierLevel(nextTier)) {
|
||||
reason.add("Skills.Alchemy.Rank_Levels.Rank_" + rank + " should be less than or equal to Skills.Alchemy.Rank_Levels.Rank_" + nextrank + "!");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/* ARCHERY */
|
||||
|
||||
if (getSkillShotRankDamageMultiplier() <= 0) {
|
||||
|
@@ -11,10 +11,20 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AutoUpdateConfigLoader extends ConfigLoader {
|
||||
public AutoUpdateConfigLoader(String relativePath, String fileName, File dataFolder) {
|
||||
super(relativePath, fileName, dataFolder);
|
||||
}
|
||||
|
||||
public AutoUpdateConfigLoader(String fileName, File dataFolder) {
|
||||
super(fileName, dataFolder);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public AutoUpdateConfigLoader(String relativePath, String fileName) {
|
||||
super(relativePath, fileName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public AutoUpdateConfigLoader(String fileName) {
|
||||
super(fileName);
|
||||
}
|
||||
@@ -136,7 +146,7 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
|
||||
saveName += ".new";
|
||||
}
|
||||
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), saveName)));
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(dataFolder, saveName)));
|
||||
writer.write(output);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
@@ -3,6 +3,7 @@ package com.gmail.nossr50.config;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -12,16 +13,33 @@ public abstract class ConfigLoader {
|
||||
protected String fileName;
|
||||
protected final File configFile;
|
||||
protected FileConfiguration config;
|
||||
protected @NotNull File dataFolder;
|
||||
|
||||
public ConfigLoader(String relativePath, String fileName) {
|
||||
public ConfigLoader(String relativePath, String fileName, @NotNull File dataFolder) {
|
||||
this.fileName = fileName;
|
||||
configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName);
|
||||
this.dataFolder = dataFolder;
|
||||
configFile = new File(dataFolder, relativePath + File.separator + fileName);
|
||||
loadFile();
|
||||
}
|
||||
|
||||
public ConfigLoader(String fileName, @NotNull File dataFolder) {
|
||||
this.fileName = fileName;
|
||||
this.dataFolder = dataFolder;
|
||||
configFile = new File(dataFolder, fileName);
|
||||
loadFile();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ConfigLoader(String relativePath, String fileName) {
|
||||
this.fileName = fileName;
|
||||
configFile = new File(mcMMO.p.getDataFolder(), relativePath + File.separator + fileName);
|
||||
loadFile();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ConfigLoader(String fileName) {
|
||||
this.fileName = fileName;
|
||||
configFile = new File(plugin.getDataFolder(), fileName);
|
||||
configFile = new File(mcMMO.p.getDataFolder(), fileName);
|
||||
loadFile();
|
||||
}
|
||||
|
||||
|
@@ -12,27 +12,19 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class Config extends AutoUpdateConfigLoader {
|
||||
private static Config instance;
|
||||
public class GeneralConfig extends AutoUpdateConfigLoader {
|
||||
|
||||
private Config() {
|
||||
super("config.yml");
|
||||
public GeneralConfig(@NotNull File dataFolder) {
|
||||
super("config.yml", dataFolder);
|
||||
validate();
|
||||
}
|
||||
|
||||
public static Config getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Config();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
|
||||
@@ -63,47 +55,6 @@ public class Config extends AutoUpdateConfigLoader {
|
||||
reason.add("Mob_Healthbar.Display_Time cannot be 0! Set to -1 to disable or set a valid value.");
|
||||
}
|
||||
|
||||
/* Scoreboards */
|
||||
/*if (getRankScoreboardTime() != -1 && getRankScoreboardTime() <= 0) {
|
||||
reason.add("Scoreboard.Types.Rank.Display_Time should be greater than 0, or -1!");
|
||||
}
|
||||
|
||||
if (getStatsScoreboardTime() != -1 && getStatsScoreboardTime() <= 0) {
|
||||
reason.add("Scoreboard.Types.Stats.Display_Time should be greater than 0, or -1!");
|
||||
}
|
||||
|
||||
if (getTopScoreboardTime() != -1 && getTopScoreboardTime() <= 0) {
|
||||
reason.add("Scoreboard.Types.Top.Display_Time should be greater than 0, or -1!");
|
||||
}
|
||||
|
||||
if (getInspectScoreboardTime() != -1 && getInspectScoreboardTime() <= 0) {
|
||||
reason.add("Scoreboard.Types.Inspect.Display_Time should be greater than 0, or -1!");
|
||||
}
|
||||
|
||||
if (getSkillScoreboardTime() != -1 && getSkillScoreboardTime() <= 0) {
|
||||
reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!");
|
||||
}
|
||||
|
||||
if (getSkillLevelUpTime() != -1 && getSkillScoreboardTime() <= 0) {
|
||||
reason.add("Scoreboard.Types.Skill.Display_Time should be greater than 0, or -1!");
|
||||
}
|
||||
|
||||
if (!(getRankUseChat() || getRankUseBoard())) {
|
||||
reason.add("Either Board or Print in Scoreboard.Types.Rank must be true!");
|
||||
}
|
||||
|
||||
if (!(getTopUseChat() || getTopUseBoard())) {
|
||||
reason.add("Either Board or Print in Scoreboard.Types.Top must be true!");
|
||||
}
|
||||
|
||||
if (!(getStatsUseChat() || getStatsUseBoard())) {
|
||||
reason.add("Either Board or Print in Scoreboard.Types.Stats must be true!");
|
||||
}
|
||||
|
||||
if (!(getInspectUseChat() || getInspectUseBoard())) {
|
||||
reason.add("Either Board or Print in Scoreboard.Types.Inspect must be true!");
|
||||
}*/
|
||||
|
||||
/* Database Purging */
|
||||
if (getPurgeInterval() < -1) {
|
||||
reason.add("Database_Purging.Purge_Interval should be greater than, or equal to -1!");
|
||||
@@ -200,42 +151,6 @@ public class Config extends AutoUpdateConfigLoader {
|
||||
reason.add("Cannot use the same item for Repair and Salvage anvils!");
|
||||
}
|
||||
|
||||
// if (getTamingCOTWMaterial(EntityType.WOLF) == null) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Item_Material is invalid!!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWMaterial(EntityType.OCELOT) == null) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Item_Material is invalid!!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWMaterial(EntityType.HORSE) == null) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Item_Material is invalid!!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWCost(EntityType.WOLF) <= 0) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Item_Amount should be greater than 0!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWCost(EntityType.OCELOT) <= 0) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Item_Amount should be greater than 0!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWCost(EntityType.HORSE) <= 0) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Item_Amount should be greater than 0!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWAmount(EntityType.WOLF) <= 0) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Wolf.Summon_Amount should be greater than 0!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWAmount(EntityType.OCELOT) <= 0) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Ocelot.Summon_Amount should be greater than 0!");
|
||||
// }
|
||||
//
|
||||
// if (getTamingCOTWAmount(EntityType.HORSE) <= 0) {
|
||||
// reason.add("Skills.Taming.Call_Of_The_Wild.Horse.Summon_Amount should be greater than 0!");
|
||||
// }
|
||||
|
||||
return noErrorsInConfig(reason);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package com.gmail.nossr50.config;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -88,7 +89,7 @@ public class RankConfig extends AutoUpdateConfigLoader {
|
||||
* @return the level requirement for a subskill at this particular rank
|
||||
*/
|
||||
private int findRankByRootAddress(int rank, String key) {
|
||||
String scalingKey = Config.getInstance().getIsRetroMode() ? ".RetroMode." : ".Standard.";
|
||||
String scalingKey = mcMMO.p.getGeneralConfig().getIsRetroMode() ? ".RetroMode." : ".Standard.";
|
||||
|
||||
String targetRank = "Rank_" + rank;
|
||||
|
||||
|
Reference in New Issue
Block a user