From 285e36e801e48bd3b8eee71734d42f1dc8faf260 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 15 Jun 2023 22:08:39 +0200 Subject: [PATCH] If startTracking and set --- .../java/fr/altarik/toolbox/core/data/DataTracker.java | 10 ++++++++-- gradle.properties | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java b/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java index a655928..2e625c5 100644 --- a/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java +++ b/Core/src/main/java/fr/altarik/toolbox/core/data/DataTracker.java @@ -11,7 +11,13 @@ public class DataTracker { } public void startTracking(TrackedData data) { - trackedData.put(data, data.defaultValue()); + String v = trackedData.get(data); + if(v == null) { + trackedData.put(data, data.defaultValue()); + } else { + throw new IllegalArgumentException("Data " + data.name() + " has already been initialized"); + } + } public String getOrDefault(TrackedData data) { @@ -21,7 +27,7 @@ public class DataTracker { public void set(TrackedData data, String value) { String v = trackedData.get(data); if(v != null) { - trackedData.putIfAbsent(data, value); + trackedData.put(data, value); } else { throw new IllegalArgumentException("Data " + data.name() + " is not tracked, please initialize it with DataTracker#startTracking(TrackedData, String) first"); } diff --git a/gradle.properties b/gradle.properties index c093845..f7f7fb2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,5 +8,5 @@ loader_version=0.14.14 fabric_version=0.75.1+1.19.3 maven_group=fr.altarik.toolbox -maven_version=4.2.0-SNAPSHOT +maven_version=4.2.1-SNAPSHOT repo_username=Altarik