Skip to content

The DPlugin Class

darksoldier1404 edited this page Jan 28, 2026 · 1 revision

For a full list of wiki pages, see the Home page.

The DPlugin Class

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.

Core Features

  • Automatic Configuration Loading: Automatically loads and saves a config.yml file.
  • Prefix Management: A customizable prefix for plugin messages, loaded from the config.
  • Data Handling: A built-in map to manage IDataHandler instances, allowing for organized data persistence.
  • Language Support: Integrated DLang for easy multi-language support.
  • Logging: A dedicated DLogNode for structured and manageable logging.

Getting Started

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
    }
}

Constructor

  • public DPlugin(boolean useDLang): The constructor takes a boolean to determine whether to initialize the DLang system. If true, it will look for language files in the lang folder.

Initialization

It is crucial to call init() in your onEnable method. This method performs several key setup tasks:

  1. ConfigUtils.loadDefaultPluginConfig(this): Loads the config.yml, creates it from resources if it doesn't exist, and fixes any missing keys from the default config.
  2. ColorUtils.applyColor(config.getString("Settings.prefix")): Loads the prefix from the config and applies color codes.
  3. initDLang(): Initializes the language manager if useDLang was set to true.

Key Methods

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.

Example Usage

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;
    }
}

Clone this wiki locally