What is this? ;)
Opened this issue · 2 comments
Just small API for messages, this is build-in in diorite project, but I often use this system in my private plugins and I was just coping it to new project manually... So I finally created stand-alone plugin for bukkit and bungee.
Features?
- You can use multiple languages at once, like load en_EN, pl_pl, and then every player may use own language.
- Huge amount of placeholders with epic features, (currently there is no default ones, but I will add them later)
In many plugins we just have "PlayerName" placeholder, and we pass player name to API to replace it, here we have "Player" placeholder, we pass player object and name to api, and api will replace ALL possible placeholders, and we can register new ones, or create child placeholders (we can access different group of placeholders)
Examples:
$<player.name> - player name, simplest placeholder, will be default one ofc.
$<player.prefix> - chat plugin may add this placeholder, and it will now work in EVERY message handled by API, even from other plugins using this API that didn't know about "prefix" placeholder.
$<player.guild.name> - here we access "guild" object from player object, and use name placeholder from it, so we don't need pass guild object to API to allow using guild placeholders, this give even more possibilities as after installing guilds that use this API, we can use guild data in every message that have access to player.
$ - simple placeholder, no groups, no object, just text to text. (or json) - Random messages.
By default every message in .yml file looks like this:
playerJoin: "Welcome [$<player.guild.tag>]$<player.name> to the server!"
but we can just change it to this:
playerJoin:
- "Welcome [$<player.guild.tag>]$<player.name> to the server!"
- "Yey [$<player.guild.tag>]$<player.name> joined to the server again!"
and now players will see random message from list.
PS: player placeholder don't needs to be named "player", we can have "player1" and "player2" placeholders at once. message.sendMessage(player, MessageData.create("name", player));
- Support for json messages.
Plugin have full support for json messages, also on API level, we can create chat plugin with format like that:
ChatFormat: '{"text": "$<player.chatName>: $<message>"}'
and$<player.chatName>
may be json message too, api contains own BaseComponent API, that support replace operations (String to string, or sring to BaseComponent) on every element: https://github.com/GotoFinal/MessagesAPI/blob/master/src/main/java/com/gotofinal/messages/api/chat/component/ReplacableComponent.java
so we can change that chatName placeholder to something like player name that we can click on hover to see more information about player. - Global placeholders
You can register placeholder that will be available in every message, like "bukkit" one, this placeholders ofc need to use static name.
And before someone ask: no. it will not lag trying to replace 39562 placeholders, when messages are loaded API parse every message and create list of used placeholders for each message, so it can also detect invalid placeholders on load.
It is also easy to add support for other stuff like sponge etc, the hardest part is creating BaseComponent converter, function that will change that api chat object, to sponge one. (you can always just parse it to json, and parse it back to object, but that may be laggy)
I sill need/want change few things here:
- add default global storage for player language (one of plugins may override it)
- add default placeholders for bukkit and bungee. (maybe with support for few plugins)
- advanced placeholders like that:
$<math.sub(player.guild.money, item.price)>
$<math.add(player.guild.money, 5)>
so, just support for methods, that may be a bit hard to add, but it isn't also something really needed,. - Support for sending raw messages without using converter, like just manually send chat packet to skip that converter.
- Support for action messages.
- Fix loading messages, to add missing messages if possible.
Nah, too much text :D I hope you will understand everything here.
AutoIn 4.x use this too, but I need now remove old code and replace it with this stand-alone library.
Even if no one will want to use this when I post this to spigot... I still need that for myself :)
There is maven repo, and CI too.