Config files will update automatically again

This commit is contained in:
nossr50
2023-04-11 15:39:01 -07:00
parent 921a0228db
commit 0ab93586fd
45 changed files with 154 additions and 196 deletions

View File

@ -41,7 +41,7 @@ public final class ExperienceAPI {
/**
* Start the task that gives combat XP.
* Processes combat XP like mcMMO normally would, so mcMMO will check whether or not the entity should reward XP when giving out the XP
* Processes combat XP like mcMMO normally would, so mcMMO will check whether the entity should reward XP when giving out the XP
*
* @param mcMMOPlayer The attacking player
* @param target The defending entity
@ -56,7 +56,7 @@ public final class ExperienceAPI {
/**
* Start the task that gives combat XP.
* Processes combat XP like mcMMO normally would, so mcMMO will check whether or not the entity should reward XP when giving out the XP
* Processes combat XP like mcMMO normally would, so mcMMO will check whether the entity should reward XP when giving out the XP
*
* @param mcMMOPlayer The attacking player
* @param target The defending entity

View File

@ -43,7 +43,7 @@ public class ChatManager {
*
* @param mmoPlayer target player
* @param rawMessage the raw message from the player as it was typed
* @param isAsync whether or not this is getting processed via async
* @param isAsync whether this is getting processed via async
*/
public void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull String rawMessage, boolean isAsync) {
processPlayerMessage(mmoPlayer, mmoPlayer.getChatChannel(), rawMessage, isAsync);
@ -69,7 +69,7 @@ public class ChatManager {
* @param mmoPlayer target player
* @param chatChannel target chat channel
* @param rawMessage raw chat message as it was typed
* @param isAsync whether or not this is getting processed via async
* @param isAsync whether this is getting processed via async
*/
private void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull ChatChannel chatChannel, @NotNull String rawMessage, boolean isAsync) {
switch (chatChannel) {
@ -155,7 +155,7 @@ public class ChatManager {
}
/**
* Whether or not the player is allowed to send a message to the chat channel they are targeting
* Whether the player is allowed to send a message to the chat channel they are targeting
* @param mmoPlayer target player
* @return true if the player can send messages to that chat channel
*/
@ -197,7 +197,7 @@ public class ChatManager {
}
/**
* Whether or not a specific chat channel is enabled
* Whether a specific chat channel is enabled
* ChatChannels are enabled/disabled via user config
*
* If chat is disabled, this always returns false

View File

@ -73,7 +73,7 @@ public abstract class AbstractPlayerAuthor implements Author {
* Sanitized names are associated with a {@link ChatChannel} as different chat channels have different chat name settings
*
* @param chatChannel target chat channel
* @param useDisplayName whether or not to use this authors display name
* @param useDisplayName whether to use this authors display name
*/
private void updateSanitizedNameCache(@NotNull ChatChannel chatChannel, boolean useDisplayName) {
if(useDisplayName) {

View File

@ -17,14 +17,14 @@ public interface Author extends Identity {
@NotNull String getAuthoredName(@NotNull ChatChannel chatChannel);
/**
* Whether or not this author is a {@link org.bukkit.command.ConsoleCommandSender}
* Whether this author is a {@link org.bukkit.command.ConsoleCommandSender}
*
* @return true if this author is the console
*/
boolean isConsole();
/**
* Whether or not this author is a {@link org.bukkit.entity.Player}
* Whether this author is a {@link org.bukkit.entity.Player}
* @return true if this author is a player
*/
boolean isPlayer();

View File

@ -73,8 +73,8 @@ public class AdminChatMailer extends AbstractChatMailer {
*
* @param author the author
* @param rawString the raw message as the author typed it before any styling
* @param isAsync whether or not this is being processed asynchronously
* @param canColor whether or not the author can use colors in chat
* @param isAsync whether this is being processed asynchronously
* @param canColor whether the author can use colors in chat
*/
public void processChatMessage(@NotNull Author author, @NotNull String rawString, boolean isAsync, boolean canColor) {
AdminChatMessage chatMessage = new AdminChatMessage(pluginRef, author, constructAudience(), rawString, addStyle(author, rawString, canColor));

View File

@ -27,8 +27,8 @@ public class PartyChatMailer extends AbstractChatMailer {
*
* @param author the author
* @param rawString the raw message as the author typed it before any styling
* @param isAsync whether or not this is being processed asynchronously
* @param canColor whether or not the author can use colors in chat
* @param isAsync whether this is being processed asynchronously
* @param canColor whether the author can use colors in chat
*/
public void processChatMessage(@NotNull Author author, @NotNull String rawString, @NotNull Party party, boolean isAsync, boolean canColor, boolean isLeader) {
PartyChatMessage chatMessage = new PartyChatMessage(pluginRef, author, constructPartyAudience(party), rawString, addStyle(author, rawString, canColor, isLeader), party);

View File

@ -17,11 +17,6 @@ public class AdvancedConfig extends BukkitConfig {
validate();
}
@Override
public void initDefaults() {
config.addDefault("Skills.General.StartingLevel", 0);
}
@Override
protected boolean validateKeys() {
// Validate all the settings!
@ -427,7 +422,7 @@ public class AdvancedConfig extends BukkitConfig {
/**
* This returns the maximum level at which superabilities will stop lengthening from scaling alongside skill level.
* It returns a different value depending on whether or not the server is in retro mode
* It returns a different value depending on whether the server is in retro mode
*
* @return the level at which abilities stop increasing in length
*/
@ -440,7 +435,7 @@ public class AdvancedConfig extends BukkitConfig {
/**
* This returns the frequency at which abilities will increase in length
* It returns a different value depending on whether or not the server is in retro mode
* It returns a different value depending on whether the server is in retro mode
*
* @return the number of levels required per ability length increase
*/

View File

@ -7,53 +7,112 @@ import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.HashSet;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
public abstract class BukkitConfig {
public static final String CONFIG_PATCH_PREFIX = "ConfigPatchVersion:";
public static final String CURRENT_CONFIG_PATCH_VER = "ConfigPatchVersion: 2";
public static final char COMMENT_PREFIX = '#';
boolean copyDefaults = true;
protected final String fileName;
protected final File configFile;
protected YamlConfiguration defaultYamlConfig;
protected YamlConfiguration config;
protected @NotNull
final File dataFolder;
protected @NotNull final File dataFolder;
public BukkitConfig(@NotNull String fileName, @NotNull File dataFolder) {
mcMMO.p.getLogger().info("[config] Initializing config: " + fileName);
this.fileName = fileName;
this.dataFolder = dataFolder;
configFile = new File(dataFolder, fileName);
// purgeComments(true);
this.defaultYamlConfig = copyDefaultConfig();
this.config = initConfig();
updateFile();
mcMMO.p.getLogger().info("[config] Config initialized: " + fileName);
}
public BukkitConfig(@NotNull String fileName, @NotNull File dataFolder, boolean copyDefaults) {
mcMMO.p.getLogger().info("[config] Initializing config: " + fileName);
this.copyDefaults = copyDefaults;
this.fileName = fileName;
this.dataFolder = dataFolder;
configFile = new File(dataFolder, fileName);
this.defaultYamlConfig = copyDefaultConfig();
this.config = initConfig();
initDefaults();
updateFile();
mcMMO.p.getLogger().info("[config] Config initialized: " + fileName);
}
@Deprecated
public BukkitConfig(@NotNull String fileName) {
this(fileName, mcMMO.p.getDataFolder());
}
/**
* Initialize default values for the config
*/
public void initDefaults() {}
public BukkitConfig(@NotNull String fileName, boolean copyDefaults) {
this(fileName, mcMMO.p.getDataFolder(), copyDefaults);
}
/**
* Update the file on the disk by copying out any new and missing defaults
*/
public void updateFile() {
try {
if(copyDefaults) {
copyMissingDefaultsFromResource();
}
config.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
private YamlConfiguration initConfig() {
/**
* Copies missing keys and values from the internal resource config within the JAR
*/
private void copyMissingDefaultsFromResource() {
boolean updated = false;
for (String key : defaultYamlConfig.getKeys(true)) {
if (!config.contains(key)) {
config.set(key, defaultYamlConfig.get(key));
updated = true;
}
}
if (updated) {
updateFile();
}
}
/**
* Copies the config from the JAR to defaults/<fileName>
*/
YamlConfiguration copyDefaultConfig() {
mcMMO.p.getLogger().info("[config] Copying default config to disk: " + fileName + " to defaults/" + fileName);
try(InputStream inputStream = mcMMO.p.getResource(fileName)) {
if(inputStream == null) {
mcMMO.p.getLogger().severe("[config] Unable to copy default config: " + fileName);
return null;
}
//Save default file into defaults/<fileName>
File defaultsFolder = new File(dataFolder, "defaults");
if (!defaultsFolder.exists()) {
defaultsFolder.mkdir();
}
File defaultFile = new File(defaultsFolder, fileName);
Path path = defaultFile.toPath();
Files.copy(inputStream, path, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
// Load file into YAML config
YamlConfiguration defaultYamlConfig = new YamlConfiguration();
defaultYamlConfig.load(defaultFile);
return defaultYamlConfig;
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
return null;
}
YamlConfiguration initConfig() {
if (!configFile.exists()) {
mcMMO.p.getLogger().info("[config] User config file not found, copying a default config to disk: " + fileName);
mcMMO.p.saveResource(fileName, false);
@ -106,8 +165,8 @@ public abstract class BukkitConfig {
}
public void backup() {
mcMMO.p.getLogger().severe("You are using an old version of the " + fileName + " file.");
mcMMO.p.getLogger().severe("Your old file has been renamed to " + fileName + ".old and has been replaced by an updated version.");
mcMMO.p.getLogger().info("You are using an old version of the " + fileName + " file.");
mcMMO.p.getLogger().info("Your old file has been renamed to " + fileName + ".old and has been replaced by an updated version.");
configFile.renameTo(new File(configFile.getPath() + ".old"));
@ -123,98 +182,4 @@ public abstract class BukkitConfig {
public File getFile() {
return configFile;
}
// /**
// * Somewhere between December 2021-January 2022 Spigot updated their
// * SnakeYAML dependency/API and due to our own crappy legacy code
// * this introduced a very problematic bug where comments got duplicated
// * <p>
// * This method hotfixes the problem by just deleting any existing comments
// * it's ugly, but it gets the job done
// *
// * @param silentFail when true mcMMO will report errors during the patch process or debug information
// * the option to have it fail silently is because mcMMO wants to check files before they are parsed as a file with a zillion comments will fail to even load
// */
// private void purgeComments(boolean silentFail) {
// if(!configFile.exists())
// return;
//
// int dupedLines = 0, lineCount = 0, lineCountAfter = 0;
// try (FileReader fileReader = new FileReader(configFile);
// BufferedReader bufferedReader = new BufferedReader(fileReader)) {
// StringBuilder stringBuilder = new StringBuilder();
// String line;
// Set<String> seenBefore = new HashSet<>();
//
// stringBuilder.append(CURRENT_CONFIG_PATCH_VER).append(System.lineSeparator());
// boolean noPatchNeeded = false;
//
// // While not at the end of the file
// while ((line = bufferedReader.readLine()) != null) {
// lineCount++;
//
// if(line.startsWith(CURRENT_CONFIG_PATCH_VER)) {
// noPatchNeeded = true;
// break;
// }
//
// //Older version, don't append this line
// if(line.startsWith(CONFIG_PATCH_PREFIX))
// continue;
//
// if (isFirstCharAsciiCharacter(line, COMMENT_PREFIX)) {
// if(seenBefore.contains(line))
// dupedLines++;
// else
// seenBefore.add(line);
//
// continue; //Delete the line by not appending it
// }
//
// stringBuilder
// .append(line) //Convert existing files into two-spaced format
// .append(System.lineSeparator());
// lineCountAfter++;
// }
//
// if(noPatchNeeded)
// return;
//
// if(lineCount == 0 && !silentFail) {
// mcMMO.p.getLogger().info("[config patcher] Config line count: " + lineCount);
// throw new InvalidConfigurationException("[config patcher] Patching of config file resulted in an empty file, this will not be saved. Contact the mcMMO devs!");
// }
//
// if(dupedLines > 0 && !silentFail) {
// mcMMO.p.getLogger().info("[config patcher] Found "+dupedLines+" duplicate comments in config file: " + configFile.getName());
// mcMMO.p.getLogger().info("[config patcher] Purging the duplicate comments... (Nothing is broken, this is just info used for debugging)");
// mcMMO.p.getLogger().info("[config patcher] Line count before: "+lineCount);
// mcMMO.p.getLogger().info("[config patcher] Line count after: "+lineCountAfter);
// }
//
// // Write out the *patched* file
// // AKA the file without any comments
// try (FileWriter fileWriter = new FileWriter(configFile)) {
// fileWriter.write(stringBuilder.toString());
// }
// } catch (IOException | InvalidConfigurationException ex) {
// mcMMO.p.getLogger().severe("Failed to patch config file: " + configFile.getName());
// ex.printStackTrace();
// }
// }
private boolean isFirstCharAsciiCharacter(String line, char character) {
if(line == null || line.isEmpty()) {
return true;
}
for(Character c : line.toCharArray()) {
if(c.equals(' '))
continue;
return c.equals(character);
}
return false;
}
}

View File

@ -40,7 +40,7 @@ public class ChatConfig extends BukkitConfig {
}
/**
* Whether or not to use display names for players in target {@link ChatChannel}
* Whether to use display names for players in target {@link ChatChannel}
*
* @param chatChannel target chat channel
*

View File

@ -35,7 +35,7 @@ public class CoreSkillsConfig extends BukkitConfig {
*/
/**
* Whether or not a skill is enabled
* Whether a skill is enabled
* Defaults true
*
* @param abstractSubSkill SubSkill definition to check
@ -47,7 +47,7 @@ public class CoreSkillsConfig extends BukkitConfig {
}
/**
* Whether or not this primary skill is enabled
* Whether this primary skill is enabled
*
* @param primarySkillType target primary skill
*

View File

@ -25,12 +25,6 @@ public class ExperienceConfig extends BukkitConfig {
validate();
}
@Override
public void initDefaults() {
config.addDefault("ExploitFix.Combat.XPCeiling.Enabled", true);
config.addDefault("ExploitFix.Combat.XPCeiling.Damage_Limit", 100);
}
public static ExperienceConfig getInstance() {
if (instance == null) {
instance = new ExperienceConfig();

View File

@ -18,7 +18,7 @@ public class RepairConfig extends BukkitConfig {
private List<Repairable> repairables;
public RepairConfig(String fileName) {
super(fileName);
super(fileName, false);
notSupported = new HashSet<>();
loadKeys();
}

View File

@ -28,7 +28,7 @@ public class FishingTreasureConfig extends BukkitConfig {
public @NotNull HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<>();
private FishingTreasureConfig() {
super(FILENAME);
super(FILENAME, false);
loadKeys();
validate();
}

View File

@ -35,7 +35,7 @@ public class TreasureConfig extends BukkitConfig {
public HashMap<String, List<HylianTreasure>> hylianMap = new HashMap<>();
private TreasureConfig() {
super(FILENAME);
super(FILENAME, false);
loadKeys();
validate();
}

View File

@ -577,7 +577,7 @@ public class McMMOPlayer implements Identified {
}
/**
* Whether or not a player is level capped
* Whether a player is level capped
* If they are at the power level cap, this will return true, otherwise it checks their skill level
* @param primarySkillType
* @return
@ -590,7 +590,7 @@ public class McMMOPlayer implements Identified {
}
/**
* Whether or not a player is power level capped
* Whether a player is power level capped
* Compares their power level total to the current set limit
* @return true if they have reached the power level cap
*/
@ -912,7 +912,7 @@ public class McMMOPlayer implements Identified {
return;
}
//These values change depending on whether or not the server is in retro mode
//These values change depending on whether the server is in retro mode
int abilityLengthVar = mcMMO.p.getAdvancedConfig().getAbilityLength();
int abilityLengthCap = mcMMO.p.getAdvancedConfig().getAbilityLengthCap();

View File

@ -6,7 +6,7 @@ import java.util.Collection;
public interface Toolable {
/**
* Whether or not this Skill requires a tool
* Whether this Skill requires a tool
* Not all skills will require a tool
* @return true if tool is required
*/

View File

@ -35,7 +35,7 @@ public abstract class AbstractSubSkill implements SubSkill, Interaction, Rank, S
}
/**
* Whether or not this subskill is enabled
* Whether this subskill is enabled
*
* @return true if enabled
*/

View File

@ -64,7 +64,7 @@ public interface SubSkill extends Skill {
void addStats(TextComponent.Builder componentBuilder, Player player);
/**
* Whether or not this subskill is enabled
* Whether this subskill is enabled
* @return true if enabled
*/
boolean isEnabled();

View File

@ -56,7 +56,7 @@ public class MobMetadataService {
}
/**
* Whether or not a target {@link LivingEntity} has a specific mcMMO mob flags
* Whether a target {@link LivingEntity} has a specific mcMMO mob flags
*
* @param flag the type of mob flag to check for
* @param livingEntity the living entity to check for metadata
@ -76,7 +76,7 @@ public class MobMetadataService {
}
/**
* Whether or not a target {@link LivingEntity} has any mcMMO mob flags
* Whether a target {@link LivingEntity} has any mcMMO mob flags
*
* @param livingEntity the living entity to check for metadata
*

View File

@ -476,7 +476,7 @@ public class TamingManager extends SkillManager {
}
/**
* Whether or not the itemstack is used for COTW
* Whether the itemstack is used for COTW
* @param itemStack target ItemStack
* @return true if it is used for any COTW
*/

View File

@ -303,7 +303,7 @@ public final class Misc {
}
/**
* Whether or not a player is the party leader of a party
* Whether a player is the party leader of a party
*
* @param mmoPlayer target player
* @return true if the player is the party leader

View File

@ -5,7 +5,7 @@ package com.gmail.nossr50.util.compat;
*/
public interface CompatibilityLayer {
/**
* Whether or not this CompatibilityLayer successfully initialized and in theory should be functional
* Whether this CompatibilityLayer successfully initialized and in theory should be functional
* @return true if this CompatibilityLayer is functional
*/
default boolean noErrorsOnInitialize() { return true; };

View File

@ -151,7 +151,10 @@ public class ExperienceBarWrapper {
private void createBossBar()
{
bossBar = mcMMOPlayer.getPlayer().getServer().createBossBar(title, ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType), ExperienceConfig.getInstance().getExperienceBarStyle(primarySkillType));
bossBar = mcMMOPlayer.getPlayer().getServer().createBossBar(
title,
ExperienceConfig.getInstance().getExperienceBarColor(primarySkillType),
ExperienceConfig.getInstance().getExperienceBarStyle(primarySkillType));
bossBar.addPlayer(mcMMOPlayer.getPlayer());
}
}

View File

@ -84,7 +84,7 @@ public abstract class MajorMinorPatchVersion implements Versioned {
}
/**
* Whether or not this version of Minecraft is a patch
* Whether this version of Minecraft is a patch
* a patch version value above 0 will indicate that this is a patch
* @return true if this version is a patch
*/

View File

@ -28,7 +28,7 @@ public class MinecraftGameVersion extends MajorMinorPatchVersion {
}
/**
* Returns whether or not the Minecraft version is at least equal to or higher than a target version
* Returns whether the Minecraft version is at least equal to or higher than a target version
* @param majorVerNumber target major version number - for example 1.16.5 , the 1 is the major version
* @param minorVerNumber target minor version number - for example 1.16.5, the 16 is the minor version
* @param patchVerNumber target patch version number - for example 1.16.5, the 5 is the patch version number

View File

@ -104,7 +104,7 @@ public class RankUtils {
}
/**
* Returns whether or not the player has unlocked the first rank in target subskill
* Returns whether the player has unlocked the first rank in target subskill
* @param player the player
* @param subSkillType the target subskill
* @return true if the player has at least one rank in the skill
@ -118,7 +118,7 @@ public class RankUtils {
}
/**
* Returns whether or not the player has unlocked the first rank in target subskill
* Returns whether the player has unlocked the first rank in target subskill
* @param player the player
* @param abstractSubSkill the target subskill
* @return true if the player has at least one rank in the skill
@ -132,7 +132,7 @@ public class RankUtils {
}
/**
* Returns whether or not the player has reached the specified rank in target subskill
* Returns whether the player has reached the specified rank in target subskill
* @param rank the target rank
* @param player the player
* @param subSkillType the target subskill
@ -144,7 +144,7 @@ public class RankUtils {
}
/**
* Returns whether or not the player has reached the specified rank in target subskill
* Returns whether the player has reached the specified rank in target subskill
* @param rank the target rank
* @param player the player
* @param abstractSubSkill the target subskill