Skip to content

Configuration system

Bogdan T edited this page Jan 28, 2024 · 15 revisions

##Basics

Here you will find the information how to take advantage of using the AtumCore configuration api

As you have probably already noticed the library has its own Config class, with more methods to use

Create config file

To create a config file you can use the following method:

AtumAPI.getInstance().createLoadableConfig()

image

It is automatically added to the ConfigManager of the AtumMod instance.

Save and Reload config file

Use ConfigManager in AtumMod

image

The parameter is the config file name without extension

How to work with Config object

It is pretty similar to the ConfigurationSection class from bukkit API.

But, unlike bukkit's class, Config has more methods to use that are quite useful for development.

Also, some methods are renamed. For example the method getConfigurationSection() has been renamed to getSubsection(), bcz I didnt like the large name of the bukkit method.

Config Methods

Config Categories

Besides the single config files, you can create Configuration categories.

In a nutshell it is just the folder with configs and the configuration category contains & manages them

How to use it:

getConfigManager().addConfigCategory(ConfigCategory object)

ConfigCategory is an abstract class that has couple of important methods to implement.

Example:

  getConfigManager().addConfigCategory(new ConfigCategory(
            this,
            ConfigType.JSON,
            "display",
            "display",
            true) {
        private List<String> elements = new ArrayList<>();
        @Override
        protected void clear() {
            elements.forEach(it->getDisplayManager().getElementRegistry().unregisterTemplate(it));
        }
        @Override
        protected void acceptConfig(@NotNull String id, @NotNull Config config) {
            getAtumMod().getLogger().info("Loading display element with id " + id);
            if(getDisplayManager().getElementRegistry().getElementTemplate(id) != null) {
                getAtumMod().getLogger().warn("Display element with id " + id + 
                        " already added or is a default element!");
                return;
            }

            DisplayElement element = getDisplayManager().getElementRegistry()
                    .compileCanvasTemplate(id,config);
            if (element != null) {
                getDisplayManager().getElementRegistry().registerTemplate(id, element);
                elements.add(id);
            }
        }
    });

As you can see, here we use the config object to load the display template and on clear remove all loaded elements

Clone this wiki locally