-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New broadcast subscriber API #5353
Conversation
this allows removing some specialized hacks, such as that for the coloured italic audit messages.
rename to ChatBroadcastReceiver instead? It is ambiguous what exactly you are broadcasting, for example, sound packets. |
You could make the same argument about broadcast channels. I don't want the terminology to be inconsistent. |
Never mind, it's assumed that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is channel ID supposed to be something that plugins can define their own? Also, would it be a better idea to use singleton objects instead of IDs?
Yes, they are entirely arbitrary. I don't know if there's a particular reason to use objects though... seems like a probably unnecessary complication, since I'm not concerned about channel IDs being stored on disk. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me. The fact that you can set an arbitrary channel ID allows good flexibility if plugins want to use this system to define channels.
…ongst other things this ended up turning into a rewrite of the broadcast system. It now also supports specialized broadcast handlers capable of handling tips, popups and titles.
d772b19
Changing this to draft as there's still a few design issues here. This turned out to be a lot more complicated to complete than I imagined. |
Closing this as the basic concept seems to be flawed. We could achieve the same thing by adding a simple However, most of the follow-ups still apply and I'll submit them as issues separately. |
Introduction
This PR introduces the following:
MessageBroadcastSubscriber
: allows subscribing tobroadcastMessage()
without being aCommandSender
MinecraftMessageBroadcastSubscriber
: allows subscribing tobroadcastTip()
,broadcastPopup()
andbroadcastTitle()
in a similar manner tobroadcastMessage()
(previously entirely impossible)broadcastMessage()
,broadcastTitle()
,broadcastTip()
andbroadcastPopup()
now require specifying aCommandSender $source
- this is to allow subscribers to process messages differently based on who sent them (useful for implementing blocking features)broadcastMessage()
,broadcastTitle()
,broadcastTip()
andbroadcastPopup()
now support providing a custom channel - this simplifies various use-cases, but was mainly needed to allow subscribers to know what the intended destination of the message wasServer
that used to acceptCommandSender
now acceptMessageBroadcastSubscriber
Server
that used to acceptPlayer
now acceptMinecraftMessageBroadcastSubscriber
Player
now implementsMinecraftMessageBroadcastSubscriber
Relevant issues
#5352
Changes
API changes
MessageBroadcastSubscriber[] $recipients
instead ofCommandSender[]
:Server::subscribeToBroadcastChannel()
Server::unsubscribeFromBroadcastChannel()
Server::unsubscribeFromAllBroadcastChannels()
Server::broadcastMessage()
PlayerChatEvent::__construct()
PlayerChatEvent::setRecipients()
MinecraftMessageBroadcastSubscriber[] $recipients
instead ofPlayer[]
Server::broadcastTip()
Server::broadcastPopup()
Server::broadcastTitle()
CommandSender $source
as their first argument, and have a newstring $channelId = Server::BROADCAST_CHANNEL_USERS
argument before$recipients
:Server::broadcastMessage()
Server::broadcastTip()
Server::broadcastPopup()
Server::broadcastTitle()
MessageBroadcastSubscriber
in place ofCommandSender
:Server::getBroadcastChannelSubscribers()
PlayerChatEvent::getRecipients()
Player
now implementsMinecraftMessageBroadcastSubscriber
Note: The introduction of source CommandSender and channel ID were not strictly necessary to achieve the base functionality of this PR. However, the broadcast subscriber interfaces are far more useful with this information included for reasons mentioned above.
I'm open to allowing these functions to accept
null
for a source. It would obviously be best for BC if the source params were optional, but in the case ofbroadcastTitle()
specifically, that will be very messy and inconsistent.Behavioural changes
None. This PR is not supposed to change observable behaviour.
Backwards compatibility
BC breaks described above.
Follow-up
BROADCAST_CHANNEL_USERS
into more channels, e.g.CHAT
,JOIN_QUIT
,GAME_EVENTS
(death, skin change, etc)Player
that unsubscribes itself from channels when it doesn't have permissionsTranslatable
inbroadcastTip()
,broadcastPopup()
andbroadcastTitle()
Title
structure or similarTests
This has been tested under the following situations: