Repository navigation
The DPlugin Class
darksoldier1404 edited this page Jan 28, 2026
·
1 revision
For a full list of wiki pages, see the Home page.
DPlugin is an abstract class that extends Bukkit's JavaPlugin. It serves as the base for all plugins using DPP-Core, providing a foundation with integrated features for configuration, data handling, and language management.
-
Automatic Configuration Loading: Automatically loads and saves a
config.ymlfile. - Prefix Management: A customizable prefix for plugin messages, loaded from the config.
-
Data Handling: A built-in map to manage
IDataHandlerinstances, allowing for organized data persistence. -
Language Support: Integrated
DLangfor easy multi-language support. -
Logging: A dedicated
DLogNodefor structured and manageable logging.
To use DPlugin, simply extend it in your main plugin class instead of JavaPlugin.
public class MyPlugin extends DPlugin {
public MyPlugin() {
super(true); // Pass true to enable DLang
}
@Override
public void onEnable() {
// Your plugin startup logic
init(); // Initialize DPlugin features
}
}-
public DPlugin(boolean useDLang): The constructor takes a boolean to determine whether to initialize theDLangsystem. Iftrue, it will look for language files in thelangfolder.
It is crucial to call init() in your onEnable method. This method performs several key setup tasks:
-
ConfigUtils.loadDefaultPluginConfig(this): Loads theconfig.yml, creates it from resources if it doesn't exist, and fixes any missing keys from the default config. -
ColorUtils.applyColor(config.getString("Settings.prefix")): Loads theprefixfrom the config and applies color codes. -
initDLang(): Initializes the language manager ifuseDLangwas set totrue.
| Method | Description |
|---|---|
init() |
Initializes the configuration, prefix, and language manager. Must be called in onEnable. |
getConfig() |
Returns the YamlConfiguration for the plugin's config.yml. |
getPrefix() |
Returns the colored prefix string loaded from the config. |
getLog() |
Returns the DLogNode instance for this plugin, used for logging. |
getLang() |
Returns the DLang instance if enabled, allowing access to language strings. |
saveAllData() |
Saves the main config.yml and calls saveAll() on every registered IDataHandler (like DataContainers). Also saves the log file. |
loadDataContainer(T container, ...) |
Loads a DataContainer or SingleDataContainer and registers it with the plugin's data handler map. See Data Management. |
Here is a more complete example of a main plugin class extending DPlugin.
import com.darksoldier1404.dppc.data.DPlugin;
import com.darksoldier1404.dppc.data.DataContainer;
import com.darksoldier1404.dppc.data.DataType;
import org.bukkit.configuration.file.YamlConfiguration;
import java.util.UUID;
public class MyAwesomePlugin extends DPlugin {
private DataContainer<UUID, YamlConfiguration> userData;
public MyAwesomePlugin() {
super(true); // Enable DLang
}
@Override
public void onEnable() {
// 1. Initialize DPlugin (config, prefix, lang)
init();
// 2. Load your data containers
userData = loadDataContainer(new DataContainer<>(this, DataType.USER));
// 3. Register commands, listeners, etc.
getCommand("mycommand").setExecutor(new MyCommand(this));
getServer().getPluginManager().registerEvents(new MyListener(this), this);
// 4. Use the logger
getLog().info("MyAwesomePlugin has been enabled!", true);
}
@Override
public void onDisable() {
// Save all plugin data on shutdown
saveAllData();
getLog().info("MyAwesomePlugin has been disabled.", true);
}
// Getter for your data container
public DataContainer<UUID, YamlConfiguration> getUserData() {
return userData;
}
}