Overview
The ConfigManager class manages all of Runway’s configuration files including the main config, language strings, and custom placeholders. It provides access to configuration objects and handles reloading.
Package: me.mrafonso.runway.config
Getting an Instance
Runway does not expose public methods to access ConfigManager directly. If you need configuration access in your own plugin, create your own instance:
Runway runwayPlugin = (Runway) Bukkit.getPluginManager().getPlugin("Runway");
ConfigManager configManager = new ConfigManager(runwayPlugin);
Constructor
public ConfigManager(Runway plugin)
The Runway plugin instance. Required to access the plugin’s resource files and data folder.
ConfigManager automatically initializes all three configuration files (config.yml, lang.yml, placeholders.yml) when constructed.
Methods
reload
Reloads all configuration files from disk. This includes config.yml, lang.yml, and placeholders.yml.
This method forces a reload of all configuration files and updates the in-memory configuration objects.
Example
// Reload all configuration files
configManager.reload();
// Don't forget to reload placeholders in ProcessHandler
processHandler.reloadPlaceholders();
After calling reload(), you should also call ProcessHandler.reloadPlaceholders() to ensure custom placeholders are updated.
config
Returns the main configuration object for config.yml.
The Config object representing config.yml. Use this to read configuration values for Runway’s behavior.
Example
Config config = configManager.config();
// Read configuration values
boolean requirePrefix = config.getOrDefault("require-prefix.minimessage", true);
boolean placeholderAPI = config.getOrDefault("placeholder-hook.placeholderapi", false);
boolean disableItalics = config.getOrDefault("disable-italics", true);
// Check if a key exists
if (config.contains("custom-setting")) {
String value = config.getString("custom-setting");
}
lang
Returns the language configuration object for lang.yml.
The Config object representing lang.yml. Use this to access language strings and messages.
Example
Config lang = configManager.lang();
// Get language strings
String welcomeMessage = lang.getString("messages.welcome");
String errorMessage = lang.getString("errors.invalid-command");
// You can then process these strings with ProcessHandler
ProcessHandler handler = processHandler;
Component welcome = handler.processComponent(welcomeMessage, player);
player.sendMessage(welcome);
placeholders
Returns the placeholders configuration object for placeholders.yml.
public Config placeholders()
The Config object representing placeholders.yml. Use this to access custom placeholder definitions.
Example
Config placeholders = configManager.placeholders();
// Get all custom placeholder keys
Set<String> placeholderKeys = placeholders.singleLayerKeySet("custom-placeholders");
// Get a specific placeholder value
String serverName = placeholders.getString("custom-placeholders.server_name");
// List all placeholders
for (String key : placeholderKeys) {
String value = placeholders.getString("custom-placeholders." + key);
getLogger().info("Placeholder: " + key + " = " + value);
}
Configuration File Structure
config.yml
The main configuration file controls Runway’s behavior:
require-prefix:
minimessage: true # Require [mm] prefix for MiniMessage
placeholders: true # Require [p] prefix for placeholders
placeholder-hook:
placeholderapi: false # Enable PlaceholderAPI
miniplaceholders: false # Enable MiniPlaceholders
ignore-legacy: false # Ignore legacy color codes (§)
disable-italics: true # Auto-disable italics
lang.yml
Stores all language strings and messages for your plugin.
placeholders.yml
Defines custom placeholders:
custom-placeholders:
server_name: "<gradient:blue:aqua>My Server</gradient>"
website: "<click:open_url:'https://example.com'>example.com</click>"
rules: "<hover:show_text:'Click to view'>📜 Rules</hover>"
Config Object Methods
The Config class from LightningStorage provides these commonly used methods:
// Reading values
String getString(String key);
int getInt(String key);
boolean getBoolean(String key);
List<String> getStringList(String key);
<T> T getOrDefault(String key, T defaultValue);
// Checking values
boolean contains(String key);
// Writing values
void set(String key, Object value);
// Getting key sets
Set<String> singleLayerKeySet(String key);
Set<String> singleLayerKeySet();
// Reloading
void forceReload();
Complete Example
Here’s a comprehensive example showing how to use ConfigManager in your plugin:
import me.mrafonso.runway.Runway;
import me.mrafonso.runway.config.ConfigManager;
import me.mrafonso.runway.util.ProcessHandler;
import de.leonhard.storage.Config;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
// Get ConfigManager
ConfigManager configManager = configManager;
ProcessHandler handler = processHandler;
// Access main config
Config config = configManager.config();
boolean usePrefix = config.getOrDefault("require-prefix.minimessage", true);
// Access language strings
Config lang = configManager.lang();
String welcomeMsg = lang.getString("messages.welcome");
// Send formatted welcome message
Player player = // ... get player
Component welcome = handler.processComponent(welcomeMsg, player);
player.sendMessage(welcome);
// Access custom placeholders
Config placeholders = configManager.placeholders();
String serverName = placeholders.getString("custom-placeholders.server_name");
// Create message with custom placeholder
Component info = handler.processComponent(
"Welcome to <server_name>!",
null
);
player.sendMessage(info);
}
// Command to reload configs
public void reloadConfigs() {
ConfigManager configManager = configManager;
ProcessHandler handler = processHandler;
// Reload all configurations
configManager.reload();
handler.reloadPlaceholders();
getLogger().info("Runway configurations reloaded!");
}
// Read custom configuration values
public void readCustomConfig() {
Config config = configManager.config();
// Get various types of values
String stringValue = config.getString("my-plugin.setting");
int intValue = config.getInt("my-plugin.number");
boolean boolValue = config.getBoolean("my-plugin.enabled");
List<String> listValue = config.getStringList("my-plugin.items");
// Use default values
int timeout = config.getOrDefault("my-plugin.timeout", 30);
// Check if key exists
if (config.contains("my-plugin.advanced.feature")) {
boolean advanced = config.getBoolean("my-plugin.advanced.feature");
}
}
// Programmatically modify config
public void modifyConfig() {
Config config = configManager.config();
// Set new values
config.set("my-plugin.last-reload", System.currentTimeMillis());
config.set("my-plugin.reload-count",
config.getOrDefault("my-plugin.reload-count", 0) + 1);
// Note: Changes are saved automatically
}
}
Integration with Other Plugins
If you’re developing a plugin that uses Runway, add it as a dependency in your plugin.yml:
name: MyPlugin
version: 1.0.0
main: com.example.myplugin.MyPlugin
depend: [Runway]
Then access Runway’s API:
@Override
public void onEnable() {
// Check if Runway is available
if (getServer().getPluginManager().getPlugin("Runway") == null) {
getLogger().severe("Runway not found! Disabling plugin.");
getServer().getPluginManager().disablePlugin(this);
return;
}
// Use Runway's API
ConfigManager configManager = configManager;
ProcessHandler handler = processHandler;
// Your plugin logic here
}
See Also