Format Konfiguracji

SpongeAPI offers support to serialize text directly to a Configurate configuration file through the use of the TypeToken class. Text objects are saved using the same node structure as the Text's JSON representation.

Wskazówka

For information on how to use Configurate to create configuration files for your plugin, please refer to Konfiguracja Pluginów.

For example, the text „Hello World!”, formatted with the color red and and underline would have the following HOCON representation:

{
    underlined=true
    color=red
    text="Hello, world!"
}

Aby zapisać obiekt Text wystarczy ustawić wartość węzła za pomocą kodu:

import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;

ConfigurationNode node = loader.load();
Text text = Text.of(TextColors.RED, TextStyles.UNDERLINE, "Hello World!");
node.getNode("mytext").setValue(TypeToken.of(Text.class), text);
loader.save(node);

Następnie możesz załadować obiekt „Text” za pomocą następującego kodu:

Text text = node.getNode("mytext").getValue(TypeToken.of(Text.class));

Informacja

This strategy is not limited to HoconConfigurationLoader; any ConfigurationLoader will suffice.