skillranks.yml will automatically fix itself if it finds certain issues

This commit is contained in:
nossr50 2020-11-10 12:05:42 -08:00
parent 592851e80b
commit b0afdccfa5
4 changed files with 107 additions and 5 deletions

View File

@ -1,6 +1,12 @@
Version 2.1.156 Version 2.1.156
Fixed a bug where the admin and party chat toggles in chat.yml didn't function as intended Fixed a bug where the admin and party chat toggles in chat.yml didn't function as intended
Added some errors that trigger if a plugin hooking into mcMMO is grabbing leaderboards for child skills through our SQL/FlatFile class (which don't exist) Added some errors that trigger if a plugin hooking into mcMMO is grabbing leaderboards for child skills through our SQL/FlatFile class (which don't exist)
mcMMO will automatically fix some errors in logic for user settings in skillranks.yml
Corrected some logic errors when checking for oddities in skillranks.yml
* Fixed a bug where Master Angler rank 1 was set too high (default configs)
NOTES:
* - If you haven't manually edited your Master Angler entries in skillranks.yml then the previous mcMMO update has rank 1 for Master Angler too high, this update automatically fixes it. You don't need to do anything.
Version 2.1.155 Version 2.1.155
Master Angler now has 8 ranks Master Angler now has 8 ranks

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.config;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import java.io.*; import java.io.*;
import java.util.HashMap; import java.util.HashMap;
@ -18,6 +19,19 @@ public abstract class AutoUpdateConfigLoader extends ConfigLoader {
super(fileName); super(fileName);
} }
protected void saveConfig() {
try {
plugin.getLogger().info("Saving changes to config file - "+fileName);
config.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
protected @NotNull FileConfiguration getInternalConfig() {
return YamlConfiguration.loadConfiguration(plugin.getResourceAsReader(fileName));
}
@Override @Override
protected void loadFile() { protected void loadFile() {
super.loadFile(); super.loadFile();

View File

@ -10,7 +10,7 @@ import java.util.List;
public abstract class ConfigLoader { public abstract class ConfigLoader {
protected static final mcMMO plugin = mcMMO.p; protected static final mcMMO plugin = mcMMO.p;
protected String fileName; protected String fileName;
private final File configFile; protected final File configFile;
protected FileConfiguration config; protected FileConfiguration config;
public ConfigLoader(String relativePath, String fileName) { public ConfigLoader(String relativePath, String fileName) {

View File

@ -2,8 +2,10 @@ package com.gmail.nossr50.config;
import com.gmail.nossr50.datatypes.skills.SubSkillType; import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill; import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
public class RankConfig extends AutoUpdateConfigLoader { public class RankConfig extends AutoUpdateConfigLoader {
@ -54,6 +56,18 @@ public class RankConfig extends AutoUpdateConfigLoader {
return findRankByRootAddress(rank, key); return findRankByRootAddress(rank, key);
} }
/**
* Returns the unlock level for a subskill depending on the gamemode
* @param subSkillType target subskill
* @param rank the rank we are checking
* @return the level requirement for a subskill at this particular rank
*/
public int getSubSkillUnlockLevel(SubSkillType subSkillType, int rank, boolean retroMode)
{
String key = getRankAddressKey(subSkillType, rank, retroMode);
return config.getInt(key, getInternalConfig().getInt(key));
}
/** /**
* Returns the unlock level for a subskill depending on the gamemode * Returns the unlock level for a subskill depending on the gamemode
* @param abstractSubSkill target subskill * @param abstractSubSkill target subskill
@ -84,12 +98,61 @@ public class RankConfig extends AutoUpdateConfigLoader {
return config.getInt(key); return config.getInt(key);
} }
public String getRankAddressKey(SubSkillType subSkillType, int rank, boolean retroMode) {
String key = subSkillType.getRankConfigAddress();
String scalingKey = retroMode ? ".RetroMode." : ".Standard.";
String targetRank = "Rank_" + rank;
key += scalingKey;
key += targetRank;
return key;
}
public String getRankAddressKey(AbstractSubSkill subSkillType, int rank, boolean retroMode) {
String key = subSkillType.getPrimaryKeyName() + "." + subSkillType.getConfigKeyName();
String scalingKey = retroMode ? ".RetroMode." : ".Standard.";
String targetRank = "Rank_" + rank;
key += scalingKey;
key += targetRank;
return key;
}
private void resetRankValue(@NotNull SubSkillType subSkillType, int rank, boolean retroMode) {
String key = getRankAddressKey(subSkillType, rank, retroMode);
int defaultValue = getInternalConfig().getInt(key);
config.set(key, defaultValue);
plugin.getLogger().info(key +" set to a value of: " + defaultValue);
}
/** /**
* Checks for valid keys for subskill ranks * Checks for valid keys for subskill ranks
*/ */
private void checkKeys(List<String> reasons) private void checkKeys(@NotNull List<String> reasons)
{ {
HashSet<SubSkillType> badSkillSetup = new HashSet<>();
//For now we will only check ranks of stuff I've overhauled //For now we will only check ranks of stuff I've overhauled
checkConfig(reasons, badSkillSetup, true);
checkConfig(reasons, badSkillSetup, false);
//Fix bad entries
if(badSkillSetup.isEmpty())
return;
plugin.getLogger().info("(FIXING CONFIG) mcMMO is correcting a few mistakes found in your skill rank config setup");
for(SubSkillType subSkillType : badSkillSetup) {
plugin.getLogger().info("(FIXING CONFIG) Resetting rank config settings for skill named - "+subSkillType.toString());
fixBadEntries(subSkillType);
}
}
private void checkConfig(@NotNull List<String> reasons, @NotNull HashSet<SubSkillType> badSkillSetup, boolean retroMode) {
for(SubSkillType subSkillType : SubSkillType.values()) for(SubSkillType subSkillType : SubSkillType.values())
{ {
//Keeping track of the rank requirements and making sure there are no logical errors //Keeping track of the rank requirements and making sure there are no logical errors
@ -98,23 +161,42 @@ public class RankConfig extends AutoUpdateConfigLoader {
for(int x = 0; x < subSkillType.getNumRanks(); x++) for(int x = 0; x < subSkillType.getNumRanks(); x++)
{ {
int index = x+1;
if(curRank > 0) if(curRank > 0)
prevRank = curRank; prevRank = curRank;
curRank = getSubSkillUnlockLevel(subSkillType, x); curRank = getSubSkillUnlockLevel(subSkillType, index, retroMode);
//Do we really care if its below 0? Probably not //Do we really care if its below 0? Probably not
if(curRank < 0) if(curRank < 0)
{ {
reasons.add(subSkillType.getAdvConfigAddress() + ".Rank_Levels.Rank_"+curRank+".LevelReq should be above or equal to 0!"); reasons.add("(CONFIG ISSUE) " + subSkillType.toString() + " should not have any ranks that require a negative level!");
badSkillSetup.add(subSkillType);
continue;
} }
if(prevRank > curRank) if(prevRank > curRank)
{ {
//We're going to allow this but we're going to warn them //We're going to allow this but we're going to warn them
plugin.getLogger().info("You have the ranks for the subskill "+ subSkillType.toString()+" set up poorly, sequential ranks should have ascending requirements"); plugin.getLogger().info("(CONFIG ISSUE) You have the ranks for the subskill "+ subSkillType.toString()+" set up poorly, sequential ranks should have ascending requirements");
badSkillSetup.add(subSkillType);
} }
} }
} }
} }
private void fixBadEntries(@NotNull SubSkillType subSkillType) {
for(int x = 0; x < subSkillType.getNumRanks(); x++)
{
int index = x+1;
//Reset Retromode entries
resetRankValue(subSkillType, index, true);
//Reset Standard Entries
resetRankValue(subSkillType, index, false);
}
saveConfig();
}
} }