From 9e53755c0cb337ad51efd43494072cc3a157ded2 Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Sat, 15 Jun 2024 13:41:46 +0200 Subject: [PATCH] Downgrade to java8 for 1.16.5 --- .../alexcrea/cuanvil/update/AtomicUpdate.java | 72 +++++++++++-------- .../xyz/alexcrea/cuanvil/update/Version.java | 14 +++- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/AtomicUpdate.java b/src/main/java/xyz/alexcrea/cuanvil/update/AtomicUpdate.java index 6b3ca71..09c9dc4 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/AtomicUpdate.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/AtomicUpdate.java @@ -9,21 +9,32 @@ import xyz.alexcrea.cuanvil.config.ConfigHolderEnum; import java.util.List; -public record AtomicUpdate ( - @NotNull AtomicUpdateType type, - @NotNull ConfigHolderEnum configType, - @NotNull String path, - @Nullable String expected, // Ignored on list - @Nullable String value // Ignored on unset. not null if not unset - -){ - +public class AtomicUpdate{ private static final String UPDATE_TYPE = "type"; private static final String CONFIG_TYPE_PATH = "config_type"; private static final String PATH_PATH = "path"; private static final String EXPECTED_PATH = "expected"; private static final String VALUE_PATH = "value"; + private final @NotNull AtomicUpdateType type; + private final @NotNull ConfigHolderEnum configType; + private final @NotNull String path; + private final @Nullable String expected; // Ignored on list + private final @Nullable String value; // Ignored on unset. not null if not unset + + public AtomicUpdate( + @NotNull AtomicUpdateType type, + @NotNull ConfigHolderEnum configType, + @NotNull String path, + @Nullable String expected, // Ignored on list + @Nullable String value) { + this.type = type; + this.configType = configType; + this.path = path; + this.expected = expected; + this.value = value; + } + public static @Nullable AtomicUpdate fromConfig(@NotNull ConfigurationSection section){ String typeString = section.getString(UPDATE_TYPE); String configTypeString = section.getString(CONFIG_TYPE_PATH); @@ -64,24 +75,22 @@ public record AtomicUpdate ( } public boolean isExpected(boolean ignoreIfOperationIsDone){ + String value; + List values; switch (this.type){ - case SET -> { - String value = this.configType.getConfigHolder().getConfig().getString(this.path); + case SET: + value = this.configType.getConfigHolder().getConfig().getString(this.path); return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && isStringEqual(value, this.value)); - } - case UNSET -> { - String value = this.configType.getConfigHolder().getConfig().getString(this.path); + case UNSET: + value = this.configType.getConfigHolder().getConfig().getString(this.path); return (isStringEqual(value, this.expected)) || (ignoreIfOperationIsDone && (value == null)); - } - case LIST_ADD -> { - List values = this.configType.getConfigHolder().getConfig().getStringList(this.path); + case LIST_ADD: + values = this.configType.getConfigHolder().getConfig().getStringList(this.path); return ignoreIfOperationIsDone || !values.contains(this.value); - } - case LIST_REMOVE -> { - List values = this.configType.getConfigHolder().getConfig().getStringList(this.path); + case LIST_REMOVE: + values = this.configType.getConfigHolder().getConfig().getStringList(this.path); return ignoreIfOperationIsDone || values.contains(this.value); - } } return false; @@ -95,23 +104,24 @@ public record AtomicUpdate ( ConfigHolder configHolder = this.configType.getConfigHolder(); FileConfiguration config = configHolder.getConfig(); + List values; switch (this.type){ - case SET -> { + case SET: config.set(this.path, this.value); - } - case UNSET -> { + break; + case UNSET: config.set(this.path, null); - } - case LIST_ADD -> { - List values = config.getStringList(this.path); + break; + case LIST_ADD: + values = config.getStringList(this.path); values.add(this.value); config.set(this.path, this.value); - } - case LIST_REMOVE -> { - List values = config.getStringList(this.path); + break; + case LIST_REMOVE: + values = config.getStringList(this.path); values.remove(this.value); config.set(this.path, this.value); - } + break; } return true; diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/Version.java b/src/main/java/xyz/alexcrea/cuanvil/update/Version.java index e0c38a9..7c8245f 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/Version.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/Version.java @@ -4,7 +4,16 @@ import com.google.common.primitives.Ints; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public record Version(int major, int minor, int build) implements Comparable{ +public class Version implements Comparable{ + int major; + int minor; + int build; + + public Version(int major, int minor, int build) { + this.major = major; + this.minor = minor; + this.build = build; + } public static @Nullable Version versionOf(@Nullable String version){ if(version == null) return null; @@ -52,7 +61,8 @@ public record Version(int major, int minor, int build) implements Comparable