From 6a81dcbcc6add3fa8c5d00fc7fae660e31d3fb44 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sun, 26 Jan 2025 01:27:49 -0500 Subject: [PATCH 1/3] Initial Commit --- src/main/java/ch/njol/skript/SkriptConfig.java | 4 ++++ src/main/java/ch/njol/skript/config/Config.java | 6 ++++-- .../ch/njol/skript/variables/FlatFileStorage.java | 15 ++++++++++++++- src/main/resources/config.sk | 8 ++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) 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/config/Config.java b/src/main/java/ch/njol/skript/config/Config.java index 82d370e1a39..db7efca8e35 100644 --- a/src/main/java/ch/njol/skript/config/Config.java +++ b/src/main/java/ch/njol/skript/config/Config.java @@ -223,6 +223,7 @@ public boolean updateNodes(@NotNull Config newer) { if (nodesToUpdate.isEmpty()) return false; + int pushed = 0; for (Node node : nodesToUpdate) { /* prevents nodes that are already in the config from being added again @@ -271,8 +272,9 @@ public boolean updateNodes(@NotNull Config newer) { if (existing != null) { // there's already something at the node we want to add the new node - Skript.debug("Adding node %s to %s at index %s", node, parent, index); - parent.add(index, node); + Skript.debug("Adding node %s to %s at index %s", node, parent, index + pushed); + parent.add(index + pushed, node); + pushed++; } else { // there's nothing at the index we want to add the new node 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 ==== From 573bb0689fa11f7769e89b9d019b82e827907506 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sun, 26 Jan 2025 01:46:33 -0500 Subject: [PATCH 2/3] Fix JUnit --- src/main/java/ch/njol/skript/config/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/config/Config.java b/src/main/java/ch/njol/skript/config/Config.java index db7efca8e35..c5b522c7639 100644 --- a/src/main/java/ch/njol/skript/config/Config.java +++ b/src/main/java/ch/njol/skript/config/Config.java @@ -269,7 +269,7 @@ public boolean updateNodes(@NotNull Config newer) { } Node existing = parent.getAt(index); - if (existing != null) { + if (existing != null && parent.size() >= index + pushed) { // there's already something at the node we want to add the new node Skript.debug("Adding node %s to %s at index %s", node, parent, index + pushed); From fbe9c538350ba5698dffa2135ff3b6e8a9480f03 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sat, 1 Feb 2025 05:13:10 -0500 Subject: [PATCH 3/3] Revert Config class --- src/main/java/ch/njol/skript/config/Config.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/njol/skript/config/Config.java b/src/main/java/ch/njol/skript/config/Config.java index c5b522c7639..82d370e1a39 100644 --- a/src/main/java/ch/njol/skript/config/Config.java +++ b/src/main/java/ch/njol/skript/config/Config.java @@ -223,7 +223,6 @@ public boolean updateNodes(@NotNull Config newer) { if (nodesToUpdate.isEmpty()) return false; - int pushed = 0; for (Node node : nodesToUpdate) { /* prevents nodes that are already in the config from being added again @@ -269,12 +268,11 @@ public boolean updateNodes(@NotNull Config newer) { } Node existing = parent.getAt(index); - if (existing != null && parent.size() >= index + pushed) { + if (existing != null) { // there's already something at the node we want to add the new node - Skript.debug("Adding node %s to %s at index %s", node, parent, index + pushed); - parent.add(index + pushed, node); - pushed++; + Skript.debug("Adding node %s to %s at index %s", node, parent, index); + parent.add(index, node); } else { // there's nothing at the index we want to add the new node