👨‍💻
Utils Library
  • Welcome!
  • Getting Started
  • Examples
  • Docs
    • ⌨️Commands
    • ⚙️Configuration
    • ☎️Events
    • 🛠️Items
    • 🖥️Menus
    • 📖PlaceholderAPI
    • 📦Resources
    • 🎯Schedulers
    • 📅Sidebar/Scoreboard
Powered by GitBook
On this page
  • File-related methods
  • Retrieving values
  • Modifying values
  • Updating/Setting
  • Deletion
  • Sections
  • Retrieving Values
  • Modifying Values
  • Selection

Was this helpful?

  1. Docs

Configuration

Modifying/retrieving values from the configuration file (config.yml).

File-related methods

Config.init();
Config.reload();
Config.save();
  • init() - Creates the configuration file if it doesn't exist and then saves the configuration file.

  • reload() - Reloads (reads) the configuration from the file.

  • save() - Saves (writes) the current configuration to the file.

Retrieving values

The Jetbrains IntelliJ IDEA Lombok plugin will cause issues with the method name of val. You can disable this in your IDE settings.

Types

  • boolean

  • double

  • float

  • int

  • ItemBuilder

  • ItemStack

  • List<...> (ConfigList)

  • Location

  • Material

  • Text

  • UUID

  • Object

  • T (if you provide Class<T>)

Anyways let's retrieve a join message.

Component component = Config.key("join.join_message") // ConfigKey
        .val() // ConfigVal
        .asText() // Text
        .component(); // Component

Modifying values

Updating/Setting

There are 3 methods all named set(). The one without any parameters will lead you to a builder, and the rest are just shorter methods to do the same thing as the builder.

Types

  • Object

  • Text

  • Location

  • ItemStack

  • ItemBuilder

  • List<?>

  • int

  • double

  • long

  • float

  • boolean

Default value will make it so what you set is going to be the default for the config if the value ever disappears, instead of returning null.

We'll use the builder for this.

Config.set()
        .key(Config.key("join.join_message"))
        .defaultVal(true)
        .val(Text.text("<green>A mysterious player has joined..."))
        .build();

Deletion

Config has 2 methods.

  1. delete(ConfigKey)

  2. delete(ConfigSection)

I don't think I need to document those self explanatory methods.

Sections

A ConfigSection is a key which holds keys inside of it.

In our case, in join.join_message the join key is a configuration section.

So we can retrieve a configuration section by doing:

ConfigSection /* ... */ = Config.section("join");

Retrieving Values

If we want to retrieve the join_message key from the join configuration section:

Object object = Config.section("join").get("join_message");
String miniMessage = (String) object;
Component component = TextStyle.style(miniMessage);

Modifying Values

Updating/Setting

Use section.set()

Same as setting a normal key to a value. It will return a ConfigSectionSetter.

Deletion

Use section.delete()

This will delete both the section and also the keys inside of it.

If you want to delete just a key, use section.set() and make the value null.

Selection

This accepts a ConfigSection. It lets you iterate over it easily (using a forEach() method)

Config.selection(Config.section("join")).forEach(keyVal -> {
    ConfigKey key = keyVal.key();
    ConfigVal val = keyVal.val();

    // prints out the name of the key.
    System.out.println(key.path);
});

PreviousCommandsNextEvents

Last updated 1 year ago

Was this helpful?

⚙️
Page cover image