Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,7 @@

<configuration>
<source>${java.version}</source>
<tags>
<tag>
<name>apiNote</name>
<head>API Note:</head>
</tag>
<tag>
<name>implSpec</name>
<head>Implementation Requirements:</head>
</tag>
<tag>
<name>implNote</name>
<head>Implementation Note:</head>
</tag>
</tags>
<encoding>UTF-8</encoding>

<doctitle>ConfigurationAPI ${project.version}</doctitle>
<windowtitle>ConfigurationAPI Docs</windowtitle>
</configuration>
Expand Down
54 changes: 47 additions & 7 deletions src/main/java/dev/spexx/configurationAPI/ConfigurationAPI.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
package dev.spexx.configurationAPI;

import dev.spexx.configurationAPI.api.manager.ConfigManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

/**
* Main plugin entry point for ConfigurationProvider.
* Main plugin entry point for ConfigurationAPI.
*
* <p>This class is managed by the Bukkit/Paper plugin system and is responsible
* for initializing the plugin lifecycle.</p>
* <p>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.</p>
*
* <p>It does not expose the API directly. Use the API classes from the
* {@code dev.spexx.configurationAPI.api} package instead.</p>
* <p>Plugin consumers should access the public API through {@link #api()}.</p>
*
* @since 1.3.1
*/
public final class ConfigurationAPI extends JavaPlugin {

/**
* Creates the plugin instance.
* Creates the plugin entry point.
*
* <p>This constructor is called by the server and should not be used manually.</p>
* <p>This constructor is invoked by the Bukkit/Paper plugin loader and should
* not be called directly by plugin consumers.</p>
*
* @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.
*
* <p>This provides access to configuration registration, retrieval,
* and file watching functionality.</p>
*
* @return the {@link ConfigManager} instance
* @since 1.3.2
*/
@Contract(pure = true)
public @NotNull ConfigManager api() {
return this.configManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private void run() {
pluginManager.callEvent(
new ConfigReloadedEvent(
config.getFile().getName(),
filePath,
config.get(),
oldChecksum,
updatedChecksum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>This event provides access to the updated configuration state
* as well as checksum information for change comparison.</p>
* <p>This event provides access to the updated configuration state,
* checksum comparison data, and the absolute configuration file path.</p>
*
* @since 1.3.0
*/
Expand All @@ -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;
Expand Down Expand Up @@ -63,6 +70,19 @@ public ConfigReloadedEvent(@NotNull String configName,
return configName;
}

/**
* Returns the full path to the configuration file.
*
* <p>This path can be used to uniquely identify which configuration
* triggered this reload event.</p>
*
* @return the absolute configuration {@link Path}
* @since 1.3.0
*/
public @NotNull Path getConfigPath() {
return configPath;
}

/**
* Returns the updated configuration.
*
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,14 @@ public ConfigManager(@NotNull JavaPlugin javaPlugin) throws ConfigException {
*
* <p>Existing values are never overwritten.</p>
*
* @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:
* <ul>
* <li>the configuration is already registered</li>
* <li>initialization or saving fails</li>
* </ul>
*
* <ul>
* <li>the configuration is already registered</li>
* <li>initialization or saving fails</li>
* </ul>
* @since 1.3.3
*/
public @NotNull YamlConfig registerWithDefaults(
Expand Down Expand Up @@ -309,7 +307,7 @@ public void stopFileWatcher() {
/**
* Resolves a normalized key for the given file.
*
* <p>This ensures consistent lookup regardless of relative paths,
* <p>This ensures a consistent lookup regardless of relative paths,
* redundant segments, or platform differences.</p>
*
* @param file the file
Expand All @@ -319,4 +317,20 @@ public void stopFileWatcher() {
private @NotNull String getNormalizedPath(@NotNull File file) {
return file.toPath().toAbsolutePath().normalize().toString();
}

/**
* Returns all registered configurations.
*
* <p>The returned map is an immutable snapshot of the currently
* registered configurations, keyed by their normalized absolute paths.</p>
*
* <p>Modifications to the returned map will not affect the internal
* configuration registry.</p>
*
* @return an immutable copy of all registered configurations
* @since 1.3.3
*/
public @NotNull Map<String, YamlConfig> getConfigs() {
return Map.copyOf(configs);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: '1.3.2'

main: dev.spexx.configurationAPI.ConfigurationAPI

api-version: '1.21.11'
api-version: '26.1.2'
load: STARTUP

authors: [ Spexx ]
Expand Down
Loading