Skip to content

Config Component ​

com.eu.habbo.core.config.ConfigComponent

The ConfigComponent class in the Arcturus project is responsible for managing configuration settings. This documentation will guide you on how to access and use the different methods provided by this component.

Accessing the Config Component ​

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

java
ConfigComponent config = Emulator.getComponent(ConfigComponent.class);

Methods ​

The ConfigComponent class provides the following methods:

getValue ​

java
String getValue(String key)

Returns the value associated with the given key if it exists. Otherwise, it returns an empty string.

getValue with Default Value ​

java
String getValue(String key, String defaultValue)

Returns the value associated with the given key if it exists. If the key is not found, it returns the defaultValue provided.

getBoolean ​

java
boolean getBoolean(String key)

Returns the boolean representation of the value associated with the given key. If the key is not found or the value cannot be converted to a boolean, it returns false.

getBoolean with Default Value ​

java
boolean getBoolean(String key, boolean defaultValue)

Returns the boolean representation of the value associated with the given key. If the key is not found or the value cannot be converted to a boolean, it returns the defaultValue provided.

getInt ​

java
int getInt(String key)

Returns the integer representation of the value associated with the given key. If the key is not found or the value cannot be converted to an integer, it returns 0.

getInt with Default Value ​

java
int getInt(String key, int defaultValue)

Returns the integer representation of the value associated with the given key. If the key is not found or the value cannot be converted to an integer, it returns the defaultValue provided.

getDouble ​

java
double getDouble(String key, double defaultValue)

Returns the double representation of the value associated with the given key. If the key is not found or the value cannot be converted to a double, it returns the defaultValue provided.

update ​

java
void update(String key, String value)

Updates the value associated with the given key to the provided value.

register ​

java
void register(String key, String value)

Registers a new configuration key and value. If the key already exists, the method will not replace the existing value.

Note: Please refer to the code comments for detailed explanations and use cases of each method.

Events ​

The ConfigComponent.EventHandler class provides two types of events related to the configuration settings:

ConfigChangedEvent ​

  • Fires when any configuration is changed.
  • Add a listener using the addListener method and remove it using the removeListener method.
  • You can also listen to the event once using the onNextEvent method.
  • To fire the event, use the fireEvent method.

ConfigRegisteredEvent ​

  • Fires when a new configuration value is registered.
  • Add a listener using the addListener method and remove it using the removeListener method.
  • You can also listen to the event once using the onNextEvent method.
  • To fire the event, use the fireEvent method.

Example Usage ​

Here's an example of how you can use the ConfigComponent methods and events:

java
// Get a configuration value
String host = config.getValue("db.hostname");

// Get a configuration value with a default value
int port = config.getInt("db.port", 3306);

// Update a configuration value
config.update("game.host", "new_host");

// Register a new configuration value
config.register("new_key", "new_value");

// Listen to the ConfigChangedEvent
ConfigComponent.EventHandler.ConfigChangedEvent.addListener(event -> {
    // Handle config changed event
});

// Listen to the ConfigRegisteredEvent
ConfigComponent.EventHandler.ConfigRegisteredEvent.addListener(event -> {
    // Handle config registered event
});