Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,45 @@ public ConfigManager(@NotNull JavaPlugin plugin) {
return load(file);
}

/**
* Returns the latest configuration snapshot for a file located
* relative to the plugin's data folder.
*
* <p>This is a convenience method that resolves the provided path
* against {@link JavaPlugin#getDataFolder()}.</p>
*
* <p>Example usage:</p>
* <pre>
* YamlConfig config = manager.getByPath("configs/example.yml");
* </pre>
*
* @param path relative file path using forward slashes, must not be {@code null}
* @return latest {@link YamlConfig} snapshot
*
* @throws IllegalStateException if the configuration is not loaded
*/
public @NotNull YamlConfig getByPath(@NotNull String path) {
File file = resolvePath(path);
return get(file);
}

/**
* Returns an existing configuration or loads it if not already tracked,
* using a path relative to the plugin's data folder.
*
* <p>Example usage:</p>
* <pre>
* YamlConfig config = manager.getOrLoadByPath("configs/example.yml");
* </pre>
*
* @param path relative file path using forward slashes, must not be {@code null}
* @return latest {@link YamlConfig} snapshot
*/
public @NotNull YamlConfig getOrLoadByPath(@NotNull String path) {
File file = resolvePath(path);
return getOrLoad(file);
}

/**
* Loads a configuration file from plugin resources if necessary.
*
Expand Down Expand Up @@ -194,6 +233,24 @@ private void ensureFileExists(@NotNull File file) {
}
}

/**
* Resolves a relative path against the plugin's data folder.
*
* <p>Backslashes are normalized to forward slashes to ensure
* cross-platform compatibility.</p>
*
* @param path relative path, must not be {@code null}
* @return resolved file
*/
private @NotNull File resolvePath(@NotNull String path) {
Objects.requireNonNull(path, "path");

// Normalize separators (Windows → Unix style)
String normalized = path.replace("\\", "/");

return new File(plugin.getDataFolder(), normalized);
}

/**
* Normalizes a path to ensure consistent identity.
*
Expand Down