Skip to content

Plugin Component

com.eu.habbo.api.plugins.PluginComponent

The PluginComponent class in the Arcturus project is responsible for managing plugins and their events. It provides methods to load, unload, and interact with plugins. This documentation will guide you on how to use the different methods and functionalities provided by this component.

Accessing the Plugin Component

To access the Plugin Component, you need to retrieve an instance of it from the Emulator class. Here's an example of how you can do it:

java
PluginComponent pluginComponent = Emulator.getComponent(PluginComponent.class);

Methods

The PluginComponent class provides the following methods:

reloadComponent

java
void reloadComponent()

This method is responsible for reloading the Plugin Component. It reloads all plugins. It is called automatically when the Plugin Component is reloaded.

loadAllPluginsInDir

java
void loadAllPluginsInDir(String dirPath) throws RuntimeException

Loads all the plugins located in the specified directory. The plugins must be in JAR file format and contain a valid plugin.json file. This method unloads all existing plugins before loading the new ones. It throws a RuntimeException if there is an error loading the plugins.

loadPluginFromURL

java
CompletableFuture<HabboPlugin> loadPluginFromURL(URL fileUrl, Boolean... dontAdd)

Loads a plugin from the specified file URL. The plugin must be in JAR file format and contain a valid plugin.json file. Optionally, you can specify whether to add the plugin to the Plugin Manager or not. This method returns a CompletableFuture that completes when the plugin has been loaded or throws a PluginLoadException.

unloadPlugin

java
CompletableFuture<HabboPlugin> unloadPlugin(HabboPlugin plugin, Boolean... dontRemove)

Unloads a plugin, calling its onDisable() method and unregistering any event listeners. Optionally, you can specify whether to remove the plugin from the Plugin Manager or not. This method returns a CompletableFuture that completes when the plugin has been unloaded.

fireEvent

java
<T extends PluginEvent> T fireEvent(T event)

Fires a plugin event, invoking the corresponding event listeners in the loaded plugins. This method iterates through all the loaded plugins and invokes the event listeners that are registered for the specific event. It returns the event object.

isRegistered

java
boolean isRegistered(Class<? extends PluginEvent> clazz, boolean pluginsOnly)

Checks if a specific event class is registered in the Plugin Component. Optionally, you can specify whether to check only the loaded plugins or include default event listeners as well. This method returns true if the event class is registered, false otherwise.

findPluginForClassName

java
HabboPlugin findPluginForClassName(String className)

Finds the plugin that contains the specified class. This method iterates through all the loaded plugins and checks if the class exists in each plugin. It returns the plugin that contains the class, or null if no plugin is found.

getPlugins

java
THashSet<HabboPlugin> getPlugins()

Returns a set of all the loaded plugins. This method returns a new THashSet containing all the loaded plugins.

Example Usage

Here's an example of how you can use the PluginComponent methods to load and interact with plugins:

java
// Get the Plugin Component instance
PluginComponent pluginComponent = Emulator.getComponent(PluginComponent.class);

// Load all plugins in the specified directory
pluginComponent.loadAllPluginsInDir("plugins");

// Fire an event and execute the corresponding event listeners in the loaded plugins
CustomEvent customEvent = new CustomEvent();
pluginComponent.fireEvent(customEvent);

// Check if a specific event class is registered in the Plugin Component
boolean isRegistered = pluginComponent.isRegistered(CustomEvent.class, true);

// Find the plugin that contains a specific class
HabboPlugin plugin = pluginComponent.findPluginForClassName("com.plugin.Main");

// Unload a specific plugin
pluginComponent.unloadPlugin(plugin);

// Get a set of all the loaded plugins
THashSet<HabboPlugin> plugins = pluginComponent.getPlugins();