KyoriPowered / adventure

A user-interface library, formerly known as text, for Minecraft: Java Edition
https://docs.advntr.dev/
MIT License
678 stars 103 forks source link

API for "caching" MiniMessage strings (or other serializer specific data) for ease of sending #1065

Open kezz opened 2 months ago

kezz commented 2 months ago

Related to https://github.com/KyoriPowered/adventure/pull/848, there seems to be some desire to remove the common usage of audience.sendMessage(MiniMessage.miniMessage().deserialize("my string")) in favour of a shorthand method for this. The MiniMessageAudience proposed in that PR is nice, but fails to be generic enough to be useful.

I think providing a wrapper for ComponentLike that accepts a serializer and the data to be serialized (open for extensions such as additional MiniMessage tag resolvers or context objects) would be quite nice, allowing for a replacement of the common pattern above:

// Stored centrally somewhere.
public static MiniMessageString myMiniMessageString = MiniMessage.miniMessage().createString("my string", tagResolvers);

// Sent at a later date (optionally adding additional context).
player.sendMessage(myMiniMessageString);
player.sendMessage(myMiniMessageString.withContext(player).withExtraTags(additionalTags));