unldenis / holoeasy

a simple and modern Java and Kotlin minecraft hologram library for 1.8-1.20.4 servers.
https://www.spigotmc.org/resources/api-holoeasy.98899/
GNU Lesser General Public License v3.0
87 stars 28 forks source link

Add support for Adventure components #59

Open checkcast opened 1 month ago

checkcast commented 1 month ago

Hi, I think it would be a great idea to be able to use Adventure components and/or minimessages in Holoeasy.

unldenis commented 1 month ago

I don't quite understand, can you try to give me some examples?

bivashy commented 1 month ago

I don't quite understand, can you try to give me some examples?

Adventure API

Currently, each line could be represented as a String, but we could (optionally) support Adventure Component which represents rich text (clickable, hoverable, HEX colors). In most cases users only need HEX colors and nothing more. Very simple example to create a component:

Component component = MiniMessage.miniMessage().deserialize("<yellow><bold>Hello <reset>world!");

Which will result in: hello-world-minimessage-example


Adventure API in holoeasy

It could be great if we could provide such component as line in holoeasy like:

Component component = MiniMessage.miniMessage().deserialize("<yellow><bold>Hello <reset>world!");

hologramPool.registerHolograms(() -> {
            hologram(location, () -> {
                textline("test");
                componentline(component);
            });
        });

Alternative solutions

Currently we only have a workaround by using dirty hack LegacyComponentSerializer:

private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
            .character(LegacyComponentSerializer.SECTION_CHAR)
            .useUnusualXRepeatedCharacterHexFormat()
            .hexColors()
            .build();

hologramPool.registerHolograms(() -> {
            hologram(location, () -> {
                textline("test");
                textline(SERIALIZER.serialize(MiniMessage.miniMessage().deserialize(("<rainbow>||||||||||||||||||||||||</rainbow>"))));
            });
        });

Result is: rainbow-hologram-example But in my opinion this doesn't look good and might be an unreliable solution.