Exlll / ConfigLib

A Minecraft library for saving, loading, updating, and commenting YAML configuration files
MIT License
135 stars 17 forks source link

Native support for Adventure API Component #29

Open zvyap opened 8 months ago

zvyap commented 8 months ago

It would be beneficial for this library to include native support for commonly used Adventure API objects such as TextComponent, Sound, and Key.

In my experience, I've used this library in two different projects, and the first task I always undertake is copying the ComponentSerializer, SoundSerializer, and KeySerializer modules.

The Adventure API also provides support, some of which is even native on other platforms. It would be advantageous to integrate similar support into this library. You can find more information about Adventure API support on other platforms here: https://docs.advntr.dev/platform/native.html

Exlll commented 8 months ago

Hi, thanks for your suggestion!

To get support for these additional serializers, you'll probably have to use a custom ConfigurationProperties object (similar to what you already have to do currently to get support for Bukkit's ConfigurationSerializable), i.e.:

YamlConfigurationProperties properties = ConfigLib.PAPER_DEFAULT_PROPERTIES.toBuilder()
     // ...further configure the builder...
    .build();

 // ...use builder to save/load configurations

What do you think about this approach? Perhaps you have a different idea in mind?

I've used this library in two different projects, and the first task I always undertake is copying the ComponentSerializer, SoundSerializer, and KeySerializer modules.

Could you perhaps share the relevant parts of your code/config to give me an idea of how you currently do it?

zvyap commented 8 months ago

Hi, thanks for your suggestion!

To get support for these additional serializers, you'll probably have to use a custom ConfigurationProperties object (similar to what you already have to do currently to get support for Bukkit's ConfigurationSerializable), i.e.:

YamlConfigurationProperties properties = ConfigLib.PAPER_DEFAULT_PROPERTIES.toBuilder()
     // ...further configure the builder...
    .build();

 // ...use builder to save/load configurations

What do you think about this approach? Perhaps you have a different idea in mind?

I think you should change the way that add support to a platform. Currently, we are using ConfigLib.PAPER_DEFAULT_PROPERTIES to add support to paper/bukkit stuff, but Adventure API is supported in various platform.

How about using this way to add specify support to a platform

ConfigLib.newBuilder()
      .addBundle(ConfigLibBundles.PAPER)
      .addBundle(ConfigLibBundles.ADVENTURE_API)

I've used this library in two different projects, and the first task I always undertake is copying the ComponentSerializer, SoundSerializer, and KeySerializer modules.

Could you perhaps share your the relevant parts of your code/config do give me an idea of how you currently do it?

I just make my own class that implements Serializer<Component, String>, nothing special For sound, I deserialize string format ":[pitch]:[volume]:[source]" For component, I just deserialize String with https://docs.advntr.dev/serializer/index.html. For Key, just deserialize string to Key object, nothing special.