I have an issue cancelling the Join or Quit Message. I do know that you can place a “null” in the paramater to cancel the Message. But that is working only in Bukkit/Spigot. When I try: e.setMessage(null) i just get an error.
But if I insert Text.of(""), then I get an empty ChatLine ingame.
The join/part messages by default will send a message to MessageChannel.TO_ALL - you can change this to be specific players with a custom channel, or use null to disable it entirely.
better use event.setChannel(MessageChannel.TO_NONE) instead.
That way you get a valid channel that just sends to nobody. Less likely to break stuff in case null arguments lead to problems
The API specifically mentions that null is a supported argument.
If you’re a plugin listening to a message event, a super simple way to check if a message will be sent to anyone is the null check. You can be certain that if the channel is null, no message will be sent.
Plugins may implement their own version of TO_NONE, or have a dynamic channel that is empty at the time of sending. You simply can’t account for all those implementations.
The javadocs do specifically mention that null has different meaning (and different uses) than TO_NONE.
Yeah, I asked on IRC - something @Saladoc can clear up in documentation? Haha
Basically, it’s certain if the channel is null that nobody will be sent a message. TO_NONE can be checked as well, but you could potentially have mods/vanilla having a channel which is empty, but is not the same as TO_NONE (say, for example, a selector which targets those in an empty team).
So while you could use TO_NONE to mark a message channel as empty, null would be the most “universal” way, I guess.