Class ConfigHandler

java.lang.Object
top.magstar.framework.configs.ConfigHandler

public abstract class ConfigHandler extends Object
Abstract base class for handling and managing MagstarConfig instances.

A ConfigHandler provides a mechanism for discovering, registering, and retrieving configuration objects. It uses the Reflections library to automatically scan target packages and instantiate all subclasses of MagstarConfig.

Responsibilities

  • Maintain a set of MagstarConfig implementations.
  • Dynamically discover and register config classes from packages.
  • Provide access to loaded config instances by class type.

Usage Example


 public class ConfigHandlers extends ConfigHandler {
     @Override
     public Set<MagstarConfig> initSet() {
         return new HashSet<>();
     }
     public ConfigHandlers() {
         registerInstance("top.magstar.lib.utils.fileutils");
     }
 }
 

Usage Example


 public class MyInstance implements ConfigSubscriber {
     @Subscribe(MyConfig.class)
     private static FileConfiguration config = Main.getInstance().getConfig(MyConfig.class);

     public MyInstance() {
         subscribe();
         String str = config.getString("example.node");
     }
 }
 
Since:
1.0.0
Author:
Magstar
  • Constructor Details

    • ConfigHandler

      public ConfigHandler(T plugin)
    • ConfigHandler

      public ConfigHandler(MagstarPlugin plugin, org.bukkit.plugin.Plugin instance)
  • Method Details

    • getPlugin

      public final MagstarPlugin getPlugin()
    • addSubscriber

      public final <T extends ConfigSubscriber> void addSubscriber(T subscriber)
    • uploadSubscribers

      public final <T extends MagstarConfig<?>> void uploadSubscribers(T config, org.bukkit.configuration.file.FileConfiguration cfg)
    • registerInstance

      protected final void registerInstance(String pack)
      Automatically discover and register MagstarConfig implementations within the given package name.

      This method uses the Reflections library to scan all classes in the target package, find subclasses of MagstarConfig, and instantiate them via their no-argument constructors.

      Parameters:
      pack - the base package name to scan for config classes
      Throws:
      RuntimeException - if instantiation of a configuration class fails
    • getConfig

      public final <T extends MagstarConfig<?>> T getConfig(Class<T> clazz)
      Retrieve a specific configuration instance by its class type.

      If multiple configurations of the same type exist, the first matching instance in the registered set will be returned. If none is found, null is returned.

      Parameters:
      clazz - the class type of the configuration to fetch
      Returns:
      the matching MagstarConfig instance, or null if not registered
    • getMessageTemplate

      public final <T extends MessageTemplate<?, ?>> T getMessageTemplate(Class<T> clazz)
    • getMessageTemplate

      public final MessageTemplate<?,?> getMessageTemplate()
    • getCommandMessageProvider

      public final CommandMessageProvider getCommandMessageProvider()
    • getCommandMessageProvider

      public final CommandMessageProvider getCommandMessageProvider(Class<? extends MessageTemplate<?,?>> clazz)