ConfigLib icon indicating copy to clipboard operation
ConfigLib copied to clipboard

Native support for Adventure API Component

Open zvyap opened this issue 1 year ago • 2 comments
trafficstars

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

zvyap avatar Jan 29 '24 23:01 zvyap

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?

Exlll avatar Jan 30 '24 07:01 Exlll

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 "<sound_id>:[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.

zvyap avatar Jan 30 '24 14:01 zvyap