Class BasePlugin

java.lang.Object
org.bukkit.plugin.PluginBase
org.bukkit.plugin.java.JavaPlugin
dev.demeng.pluginbase.plugin.BasePlugin
All Implemented Interfaces:
TerminableConsumer, org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter, org.bukkit.command.TabExecutor, org.bukkit.plugin.Plugin

public abstract class BasePlugin extends org.bukkit.plugin.java.JavaPlugin implements TerminableConsumer
An extended version of JavaPlugin. It is recommended that you extend this in your main class, but you can also manually set the values in BaseManager should you wish to use your own loading system.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends AutoCloseable>
    T
    bind(T terminable)
    Binds with the given terminable.
    <T extends TerminableModule>
    T
    bindModule(T module)
    Binds with the given terminable module.
    protected @NotNull DependencyContainer
    Configures dependencies for this plugin.
    revxrsal.commands.Lamp.Builder<revxrsal.commands.bukkit.actor.BukkitCommandActor>
    Creates a new Lamp command handler builder with PluginBase's settings pre-configured.
    protected void
    Executes on plugin disable.
    protected void
    Executes on plugin enable.
    net.kyori.adventure.platform.bukkit.BukkitAudiences
    Gets the BukkitAudiences instance to use for Adventure.
    @NotNull BaseSettings
    Gets the settings the library should use.
    <T> T
    getDependency(@NotNull Class<T> type)
    Gets an instance from the DI container.
    Gets the dependency injection container.
    <T> T
    getService(@NotNull Class<T> service)
    Gets a service provided by the ServiceManager.
    Gets the translator.
    boolean
    isPluginPresent(@NotNull String name)
    Gets if a given plugin is enabled.
    protected void
    Executes at early plugin startup.
    final void
     
    final void
     
    final void
     
    <T> T
    provideService(@NotNull Class<T> clazz, T instance)
    Provides a service to the ServiceManager, bound to this plugin at ServicePriority.Normal.
    <T> T
    provideService(@NotNull Class<T> clazz, T instance, @NotNull org.bukkit.plugin.ServicePriority priority)
    Provides a service to the ServiceManager, bound to this plugin.
    <T extends org.bukkit.event.Listener>
    T
    registerListener(T listener)
    Register a listener with the server.
    void
    setBaseSettings(@Nullable BaseSettings baseSettings)
    Sets the settings the library should use.

    Methods inherited from class org.bukkit.plugin.java.JavaPlugin

    getClassLoader, getCommand, getConfig, getDataFolder, getDefaultBiomeProvider, getDefaultWorldGenerator, getDescription, getFile, getLogger, getPlugin, getPluginLoader, getProvidingPlugin, getResource, getServer, getTextResource, isEnabled, isNaggable, onCommand, onTabComplete, reloadConfig, saveConfig, saveDefaultConfig, saveResource, setEnabled, setNaggable, toString

    Methods inherited from class org.bukkit.plugin.PluginBase

    equals, getName, hashCode

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BasePlugin

      public BasePlugin()
  • Method Details

    • onLoad

      public final void onLoad()
      Specified by:
      onLoad in interface org.bukkit.plugin.Plugin
      Overrides:
      onLoad in class org.bukkit.plugin.java.JavaPlugin
    • onEnable

      public final void onEnable()
      Specified by:
      onEnable in interface org.bukkit.plugin.Plugin
      Overrides:
      onEnable in class org.bukkit.plugin.java.JavaPlugin
    • onDisable

      public final void onDisable()
      Specified by:
      onDisable in interface org.bukkit.plugin.Plugin
      Overrides:
      onDisable in class org.bukkit.plugin.java.JavaPlugin
    • load

      protected void load()
      Executes at early plugin startup.
    • enable

      protected void enable()
      Executes on plugin enable.
    • disable

      protected void disable()
      Executes on plugin disable.
    • configureDependencies

      @NotNull protected @NotNull DependencyContainer configureDependencies()
      Configures dependencies for this plugin.

      Override this method to register your dependencies with the DI container. The default implementation registers the plugin instance.

      You can manually register core services using either concrete types or interfaces. Classes marked with @Component will be auto-created with dependencies injected.

      Example with interface-based registration (recommended):

      
       @Override
       protected DependencyContainer configureDependencies() {
         // Create concrete implementations
         DatabaseConnection db = new MySQLConnection(this);
         CacheService cache = new RedisCacheService();
      
         return DependencyInjection.builder()
             .register(this)  // Register plugin by concrete type
             .register(DatabaseConnection.class, db)  // Register by interface
             .register(CacheService.class, cache)     // Register by interface
             .build();
       }
      
       // Then in enable() - classes with @Component are auto-created:
       @Override
       protected void enable() {
         // Auto-creates PlayerDataManager with interfaces injected
         PlayerDataManager manager = getDependency(PlayerDataManager.class);
       }
      
       // Your @Component class can depend on interfaces:
       @Component
       public class PlayerDataManager {
         private final DatabaseConnection db;  // Interface, not concrete class!
         private final CacheService cache;     // Interface, not concrete class!
      
         public PlayerDataManager(DatabaseConnection db, CacheService cache) {
           this.db = db;
           this.cache = cache;
         }
       }
       
      Returns:
      The configured dependency container
    • getDependencyContainer

      @NotNull public @NotNull DependencyContainer getDependencyContainer()
      Gets the dependency injection container.
      Returns:
      The dependency container
    • getDependency

      @NotNull public <T> T getDependency(@NotNull @NotNull Class<T> type)
      Gets an instance from the DI container.

      This is a convenience method that delegates to DependencyContainer.getInstance(Class).

      Type Parameters:
      T - The type parameter
      Parameters:
      type - The class type
      Returns:
      The instance
    • bind

      @NotNull public <T extends AutoCloseable> T bind(@NotNull T terminable)
      Description copied from interface: TerminableConsumer
      Binds with the given terminable.
      Specified by:
      bind in interface TerminableConsumer
      Type Parameters:
      T - the terminable type
      Parameters:
      terminable - the terminable to bind with
      Returns:
      the same terminable
    • bindModule

      @NotNull public <T extends TerminableModule> T bindModule(@NotNull T module)
      Description copied from interface: TerminableConsumer
      Binds with the given terminable module.
      Specified by:
      bindModule in interface TerminableConsumer
      Type Parameters:
      T - the module type
      Parameters:
      module - the module to bind with
      Returns:
      the same module
    • registerListener

      @NotNull public <T extends org.bukkit.event.Listener> T registerListener(@NotNull T listener)
      Register a listener with the server.

      Events should be used instead of this method in most cases.

      Type Parameters:
      T - the listener class type
      Parameters:
      listener - the listener to register
      Returns:
      the listener
    • getService

      @NotNull public <T> T getService(@NotNull @NotNull Class<T> service)
      Gets a service provided by the ServiceManager.
      Type Parameters:
      T - The class type
      Parameters:
      service - The service class
      Returns:
      The service
    • provideService

      @NotNull public <T> T provideService(@NotNull @NotNull Class<T> clazz, @NotNull T instance, @NotNull @NotNull org.bukkit.plugin.ServicePriority priority)
      Provides a service to the ServiceManager, bound to this plugin.
      Type Parameters:
      T - The service class type
      Parameters:
      clazz - The service class
      instance - The instance
      priority - The priority to register the service at
      Returns:
      The instance
    • provideService

      @NotNull public <T> T provideService(@NotNull @NotNull Class<T> clazz, @NotNull T instance)
      Provides a service to the ServiceManager, bound to this plugin at ServicePriority.Normal.
      Type Parameters:
      T - The service class type
      Parameters:
      clazz - The service class
      instance - The instance
      Returns:
      The instance
    • isPluginPresent

      public boolean isPluginPresent(@NotNull @NotNull String name)
      Gets if a given plugin is enabled.
      Parameters:
      name - The name of the plugin
      Returns:
      If the plugin is enabled
    • getTranslator

      public Translator getTranslator()
      Gets the translator.
      Returns:
      The translator
    • getAdventure

      public net.kyori.adventure.platform.bukkit.BukkitAudiences getAdventure()
      Gets the BukkitAudiences instance to use for Adventure.
      Returns:
      The BukkitAudiences instance to use for Adventure
    • getBaseSettings

      @NotNull public @NotNull BaseSettings getBaseSettings()
      Gets the settings the library should use.
      Returns:
      The settings the library should use
    • setBaseSettings

      public void setBaseSettings(@Nullable @Nullable BaseSettings baseSettings)
      Sets the settings the library should use. Default will be used if not set.
      Parameters:
      baseSettings - The new base settings
    • createCommandHandler

      @NotNull public revxrsal.commands.Lamp.Builder<revxrsal.commands.bukkit.actor.BukkitCommandActor> createCommandHandler()
      Creates a new Lamp command handler builder with PluginBase's settings pre-configured.
      Returns:
      A Lamp builder instance