# Configs

## Starting

For starting, you need to create config class.

Example config's class:

```java
package your.package;

@ConfigFile(
    plugin = YourPlugin.class,
    type = ConfigurationType.JSON, // You need to provide your config type: JSON or YAML
    resource = "config.json",
    path = "plugins/yourPlugin/config.json"
)
public final class YourConfig {
    @ConfigValue(
        path = "welcome.message"
    ) /*
    If config type is json it will look like this:
    {
        welcome: {
            message: "Welcome to the server!"
        }
    }
    Yaml:
    welcome:
        message: "Welcome to the server!"
    */
    public String welcomeMessage = "Welcome to the server!";
}
```

Then, you need to register config to HCore.

How to:

```java
private ConfigContainer<YourConfig> yourContainer;

// Your plugin's onEnable method
@Override
public void onEnable() {
    yourContainer = HCore.loadConfig(new YourConfig());
}
```

Now, you will able to get this config and get values from config's class.\
Example:

```java
@EventHandler
public void join(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    player.sendMessage(yourContainer.getConfig().welcomeMessage);
}
```

## ConfigContainer#save()

Saves your config to file.

## ConfigContainer#update()

Updates your config.

## ConfigContainer#getConfig()

Returns your config's class. You can work with it and store values from it.

## ConfigContainer#setConfig()

You can update config to new and save it.

Example:

```java
public void doStuff() {
    YourConfig config = new YourConfig();
    config.welcomeMessage = "Welcome from new config!"; // Config will update to new with default values and provided welcome message
    yourContainer.setConfig(config);
}
```

## ConfigContainer#getFile()

Returns config's file.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hcore.gitbook.io/wiki/configs/configs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
