diff --git a/pom.xml b/pom.xml
index 7509333..2471081 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,22 +36,7 @@
This class is managed by the Bukkit/Paper plugin system and is responsible - * for initializing the plugin lifecycle.
+ *This class is created and managed by the Bukkit/Paper plugin loader. + * It initializes the internal configuration manager and starts the file watcher + * during the plugin lifecycle.
* - *It does not expose the API directly. Use the API classes from the - * {@code dev.spexx.configurationAPI.api} package instead.
+ *Plugin consumers should access the public API through {@link #api()}.
* * @since 1.3.1 */ public final class ConfigurationAPI extends JavaPlugin { /** - * Creates the plugin instance. + * Creates the plugin entry point. * - *This constructor is called by the server and should not be used manually.
+ *This constructor is invoked by the Bukkit/Paper plugin loader and should + * not be called directly by plugin consumers.
+ * + * @since 1.3.2 */ public ConfigurationAPI() { } + + /** + * The internal configuration manager instance. + * + * @since 1.3.2 + */ + private ConfigManager configManager; + + @Override + public void onEnable() { + this.configManager = new ConfigManager(this); + this.configManager.startFileWatcher(); + } + + @Override + public void onDisable() { + if (configManager != null) { + configManager.stopFileWatcher(); + } + } + + /** + * Returns the core {@link ConfigManager} API. + * + *This provides access to configuration registration, retrieval, + * and file watching functionality.
+ * + * @return the {@link ConfigManager} instance + * @since 1.3.2 + */ + @Contract(pure = true) + public @NotNull ConfigManager api() { + return this.configManager; + } } \ No newline at end of file diff --git a/src/main/java/dev/spexx/configurationAPI/api/config/yaml/YamlConfigWatcher.java b/src/main/java/dev/spexx/configurationAPI/api/config/yaml/YamlConfigWatcher.java index bd6bbd3..af6f783 100644 --- a/src/main/java/dev/spexx/configurationAPI/api/config/yaml/YamlConfigWatcher.java +++ b/src/main/java/dev/spexx/configurationAPI/api/config/yaml/YamlConfigWatcher.java @@ -239,6 +239,7 @@ private void run() { pluginManager.callEvent( new ConfigReloadedEvent( config.getFile().getName(), + filePath, config.get(), oldChecksum, updatedChecksum diff --git a/src/main/java/dev/spexx/configurationAPI/api/event/ConfigReloadedEvent.java b/src/main/java/dev/spexx/configurationAPI/api/event/ConfigReloadedEvent.java index b603eba..ad2b17f 100644 --- a/src/main/java/dev/spexx/configurationAPI/api/event/ConfigReloadedEvent.java +++ b/src/main/java/dev/spexx/configurationAPI/api/event/ConfigReloadedEvent.java @@ -4,12 +4,15 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; /** * Event fired when a configuration has been reloaded. * - *This event provides access to the updated configuration state - * as well as checksum information for change comparison.
+ *This event provides access to the updated configuration state, + * checksum comparison data, and the absolute configuration file path.
* * @since 1.3.0 */ @@ -18,24 +21,28 @@ public class ConfigReloadedEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); private final @NotNull String configName; + private final @NotNull Path configPath; private final @NotNull FileConfiguration newConfig; - private final String oldChecksum; - private final String newChecksum; + private final @Nullable String oldChecksum; + private final @Nullable String newChecksum; /** * Creates a new configuration reload event. * * @param configName the name of the configuration file (including extension) + * @param configPath the absolute path to the configuration file * @param newConfig the updated {@link FileConfiguration} instance * @param oldChecksum the previous checksum, or {@code null} if not available * @param newChecksum the new checksum, or {@code null} if generation failed * @since 1.3.0 */ public ConfigReloadedEvent(@NotNull String configName, + @NotNull Path configPath, @NotNull FileConfiguration newConfig, - String oldChecksum, - String newChecksum) { + @Nullable String oldChecksum, + @Nullable String newChecksum) { this.configName = configName; + this.configPath = configPath; this.newConfig = newConfig; this.oldChecksum = oldChecksum; this.newChecksum = newChecksum; @@ -63,6 +70,19 @@ public ConfigReloadedEvent(@NotNull String configName, return configName; } + /** + * Returns the full path to the configuration file. + * + *This path can be used to uniquely identify which configuration + * triggered this reload event.
+ * + * @return the absolute configuration {@link Path} + * @since 1.3.0 + */ + public @NotNull Path getConfigPath() { + return configPath; + } + /** * Returns the updated configuration. * @@ -76,10 +96,10 @@ public ConfigReloadedEvent(@NotNull String configName, /** * Returns the checksum before the reload. * - * @return the previous checksum, or {@code null} if not available + * @return the previous checksum, or {@code null} if unavailable * @since 1.3.0 */ - public String getOldChecksum() { + public @Nullable String getOldChecksum() { return oldChecksum; } @@ -89,7 +109,7 @@ public String getOldChecksum() { * @return the new checksum, or {@code null} if generation failed * @since 1.3.0 */ - public String getNewChecksum() { + public @Nullable String getNewChecksum() { return newChecksum; } diff --git a/src/main/java/dev/spexx/configurationAPI/api/manager/ConfigManager.java b/src/main/java/dev/spexx/configurationAPI/api/manager/ConfigManager.java index 014ffca..a243f56 100644 --- a/src/main/java/dev/spexx/configurationAPI/api/manager/ConfigManager.java +++ b/src/main/java/dev/spexx/configurationAPI/api/manager/ConfigManager.java @@ -132,16 +132,14 @@ public ConfigManager(@NotNull JavaPlugin javaPlugin) throws ConfigException { * *Existing values are never overwritten.
* - * @param file the configuration file + * @param file the configuration file * @param defaults a map of default key-value pairs to apply if missing * @return the managed {@link YamlConfig} instance - * * @throws ConfigException if: - *This ensures consistent lookup regardless of relative paths, + *
This ensures a consistent lookup regardless of relative paths, * redundant segments, or platform differences.
* * @param file the file @@ -319,4 +317,20 @@ public void stopFileWatcher() { private @NotNull String getNormalizedPath(@NotNull File file) { return file.toPath().toAbsolutePath().normalize().toString(); } + + /** + * Returns all registered configurations. + * + *The returned map is an immutable snapshot of the currently + * registered configurations, keyed by their normalized absolute paths.
+ * + *Modifications to the returned map will not affect the internal + * configuration registry.
+ * + * @return an immutable copy of all registered configurations + * @since 1.3.3 + */ + public @NotNull Map