From d583427f790c75aed265b5f9a569c6c6683f4bea Mon Sep 17 00:00:00 2001
From: Spexx
Date: Sun, 5 Apr 2026 12:03:11 +0200
Subject: [PATCH 1/2] feat: add safe typed access methods to YamlConfig
---
.../configurationAPI/config/YamlConfig.java | 155 ++++++++++++------
1 file changed, 108 insertions(+), 47 deletions(-)
diff --git a/src/main/java/dev/spexx/configurationAPI/config/YamlConfig.java b/src/main/java/dev/spexx/configurationAPI/config/YamlConfig.java
index 50c72a0..1987621 100644
--- a/src/main/java/dev/spexx/configurationAPI/config/YamlConfig.java
+++ b/src/main/java/dev/spexx/configurationAPI/config/YamlConfig.java
@@ -4,6 +4,8 @@
import org.jetbrains.annotations.NotNull;
import java.io.File;
+import java.util.List;
+import java.util.Optional;
/**
* Immutable snapshot of a YAML configuration file.
@@ -28,73 +30,132 @@
* cache instances long-term if they require access to the most up-to-date
* configuration state.
*
- * @apiNote
- * To obtain the latest configuration, retrieve a new instance from the managing
- * component instead of reusing previously obtained references.
- *
- * @implSpec
- * Thread-safety is achieved through immutability and atomic replacement of
- * instances at a higher level (for example, by the configuration manager).
- *
- * @implNote
- * The underlying {@link FileConfiguration} instance is assumed to be used in a
- * read-only manner. Modifying it directly may lead to inconsistent behavior.
- *
- * @since 1.0.0
+ * @since 1.1.0
*/
-public final class YamlConfig {
+public record YamlConfig(@NotNull File file, @NotNull FileConfiguration config) {
/**
- * The underlying configuration file on disk.
+ * Returns the underlying configuration file.
*/
- private final @NotNull File file;
+ @Override
+ public @NotNull File file() {
+ return file;
+ }
/**
- * Parsed configuration snapshot.
+ * Returns the parsed configuration snapshot.
+ *
+ *
The returned {@link FileConfiguration} represents a stable, immutable
- * view of the configuration at the time this {@code YamlConfig} instance
- * was created.
- *
- *
This object should be treated as read-only.
+ * Returns a boolean value at the given path.
+ */
+ public @NotNull Optional getBoolean(@NotNull String path) {
+ return config.contains(path)
+ ? Optional.of(config.getBoolean(path))
+ : Optional.empty();
+ }
+
+ /**
+ * Returns a double value at the given path.
+ */
+ public @NotNull Optional getDouble(@NotNull String path) {
+ return config.contains(path)
+ ? Optional.of(config.getDouble(path))
+ : Optional.empty();
+ }
+
+ /**
+ * Returns a float value at the given path.
+ */
+ public @NotNull Optional getFloat(@NotNull String path) {
+ return config.contains(path)
+ ? Optional.of((float) config.getDouble(path))
+ : Optional.empty();
+ }
+
+ /**
+ * Returns a string list at the given path.
+ */
+ public @NotNull Optional> getStringList(@NotNull String path) {
+ return config.contains(path)
+ ? Optional.of(config.getStringList(path))
+ : Optional.empty();
+ }
+
+ /**
+ * Returns a raw object at the given path.
+ */
+ public @NotNull Optional