Package dev.demeng.pluginbase.plugin
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 -
Method Summary
Modifier and TypeMethodDescription<T extends AutoCloseable>
Tbind(T terminable) Binds with the given terminable.<T extends TerminableModule>
TbindModule(T module) Binds with the given terminable module.protected @NotNull DependencyContainerConfigures 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 voiddisable()Executes on plugin disable.protected voidenable()Executes on plugin enable.net.kyori.adventure.platform.bukkit.BukkitAudiencesGets the BukkitAudiences instance to use for Adventure.@NotNull BaseSettingsGets the settings the library should use.<T> TgetDependency(@NotNull Class<T> type) Gets an instance from the DI container.@NotNull DependencyContainerGets the dependency injection container.<T> TgetService(@NotNull Class<T> service) Gets a service provided by the ServiceManager.Gets the translator.booleanisPluginPresent(@NotNull String name) Gets if a given plugin is enabled.protected voidload()Executes at early plugin startup.final voidfinal voidonEnable()final voidonLoad()<T> TprovideService(@NotNull Class<T> clazz, T instance) Provides a service to the ServiceManager, bound to this plugin atServicePriority.Normal.<T> TprovideService(@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>
TregisterListener(T listener) Register a listener with the server.voidsetBaseSettings(@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, toStringMethods inherited from class org.bukkit.plugin.PluginBase
equals, getName, hashCode
-
Constructor Details
-
BasePlugin
public BasePlugin()
-
-
Method Details
-
onLoad
public final void onLoad()- Specified by:
onLoadin interfaceorg.bukkit.plugin.Plugin- Overrides:
onLoadin classorg.bukkit.plugin.java.JavaPlugin
-
onEnable
public final void onEnable()- Specified by:
onEnablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onEnablein classorg.bukkit.plugin.java.JavaPlugin
-
onDisable
public final void onDisable()- Specified by:
onDisablein interfaceorg.bukkit.plugin.Plugin- Overrides:
onDisablein classorg.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
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
@Componentwill 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
Gets the dependency injection container.- Returns:
- The dependency container
-
getDependency
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
Description copied from interface:TerminableConsumerBinds with the given terminable.- Specified by:
bindin interfaceTerminableConsumer- Type Parameters:
T- the terminable type- Parameters:
terminable- the terminable to bind with- Returns:
- the same terminable
-
bindModule
Description copied from interface:TerminableConsumerBinds with the given terminable module.- Specified by:
bindModulein interfaceTerminableConsumer- 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.Eventsshould 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
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 classinstance- The instancepriority- The priority to register the service at- Returns:
- The instance
-
provideService
Provides a service to the ServiceManager, bound to this plugin atServicePriority.Normal.- Type Parameters:
T- The service class type- Parameters:
clazz- The service classinstance- The instance- Returns:
- The instance
-
isPluginPresent
Gets if a given plugin is enabled.- Parameters:
name- The name of the plugin- Returns:
- If the plugin is enabled
-
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
Gets the settings the library should use.- Returns:
- The settings the library should use
-
setBaseSettings
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
-