diff --git a/src/main/java/ch/njol/skript/SkriptConfig.java b/src/main/java/ch/njol/skript/SkriptConfig.java index 279c6242485..207f2b11a24 100644 --- a/src/main/java/ch/njol/skript/SkriptConfig.java +++ b/src/main/java/ch/njol/skript/SkriptConfig.java @@ -21,6 +21,7 @@ import ch.njol.skript.util.Version; import ch.njol.skript.util.chat.ChatMessages; import ch.njol.skript.util.chat.LinkParseMode; +import ch.njol.skript.variables.FlatFileStorage; import ch.njol.skript.variables.Variables; import co.aikar.timings.Timings; import org.bukkit.event.EventPriority; @@ -371,6 +372,9 @@ private static void userDisableHooks(Class> hookClass, boolean public static final Option runtimeErrorTimeoutDuration = new Option<>("runtime errors.error timeout length", 10); public static final Option runtimeWarningTimeoutDuration = new Option<>("runtime errors.warning timeout length", 10); + public static final Option variableChangesUntilSave = new Option<>("variable changes until save", 1000) + .setter(FlatFileStorage::setRequiredChangesForResave); + /** * This should only be used in special cases */ diff --git a/src/main/java/ch/njol/skript/variables/FlatFileStorage.java b/src/main/java/ch/njol/skript/variables/FlatFileStorage.java index 7c7eaa5e71e..f0ae21a4fe7 100644 --- a/src/main/java/ch/njol/skript/variables/FlatFileStorage.java +++ b/src/main/java/ch/njol/skript/variables/FlatFileStorage.java @@ -76,7 +76,7 @@ public class FlatFileStorage extends VariablesStorage { * The amount of {@link #changes} needed * for a new {@link #saveVariables(boolean) save}. */ - private static final int REQUIRED_CHANGES_FOR_RESAVE = 1000; + private static int REQUIRED_CHANGES_FOR_RESAVE = 1000; /** * The amount of variable changes written since the last full save. @@ -606,4 +606,17 @@ private static void writeCSV(PrintWriter printWriter, String... values) { printWriter.println(); } + /** + * Change the required amount of variable changes until variables are saved. + * Cannot be zero or less. + * @param value + */ + public static void setRequiredChangesForResave(int value) { + if (value <= 0) { + Skript.warning("Variable changes until save cannot be zero or less. Using default of 1000."); + value = 1000; + } + REQUIRED_CHANGES_FOR_RESAVE = value; + } + } diff --git a/src/main/resources/config.sk b/src/main/resources/config.sk index 5364643cfaf..9125aa033ec 100644 --- a/src/main/resources/config.sk +++ b/src/main/resources/config.sk @@ -234,6 +234,14 @@ long parse time warning threshold: 0 seconds # stating that the statement has taken a long time to parse. # A value of 0 seconds means that this warning should be disabled. +variable changes until save: 1000 +# This setting controls the total number of times that global variables need to be changed +# until saving variables to 'variables.csv'. +# 'set {a} to 1' is one change, 'set {b} to 2' now makes it two. +# You cannot provide a value of zero or less. +# WARNING: This setting should be used at your own discretion. +# This setting can lag your server depending on how often variables get saved and +# the number of variables needing to be saved. # ==== Runtime Errors ====