Hi, I am looking to make a chat plugin for Sponge but I am struggeling to find the right approach to implement it the best way possible in sponge. I am hoping to find some more experienced developers to help me out with some of my questions.
The general idea of the chat plugin is to have the following features. I will include the way I intend to approach solving the issue but I am not sure all of them are the best way to ensure cross compatibility with other plugins.
Multiple chat channels which players can manually leave/join or based on permissions
Solution: Use
MessageChannel
Each channel has their own template. Example: global chat will be [G] {guild} {name}: {message}
and a guild channel would be [{guild}] {name}: {message}
. These channels can be configured by the server owner.
Solution: Listen to
MessageChannelEvent.Chat
and check what the current channel of the player is withgetMessageChannel()
. If the channel is one of my channels, set the message withevent.setMessage(Text.EMPTY, myChannel.getTemplate().parse(chatEvent), Text.EMPTY)
I was first looking into
MessageChannel.transformMessage()
but this does not seem to be designed for this idea as you get the result text of the event. On a vanilla server you could use this as you know the text will start with "<{name}> " and you could extract the original message, but other plugins may change the message so this is no longer reliable.
Allowing other plugins to supply values for the templates
I have seen the
TextTemplate
which is something I though would be the key to many of my problems, but either I haven’t tested it propperly or it seems to be lacking for what I want to achieve.
An example: A placeholder could be the name of the player (TextTemplate.Arg
) but the name could have a hover over message with other placeholders and I don’t see howTextTemplate
would solve that issue.
I didn’t seem to find a solution in sponge for this and the only way to accomplish it woud be trough a custom template implementation and using the PlaceholderAPI library.
Maybe I am looking at this at a completely wrong angle so any feedback would be appriciated