Skip to content
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

Closed
wants to merge 9 commits into from
Closed

Conversation

dktapps
Copy link
Member

@dktapps dktapps commented Oct 18, 2022

Introduction

This PR introduces the following:

  • MessageBroadcastSubscriber: allows subscribing to broadcastMessage() without being a CommandSender
  • MinecraftMessageBroadcastSubscriber: allows subscribing to broadcastTip(), broadcastPopup() and broadcastTitle() in a similar manner to broadcastMessage() (previously entirely impossible)
  • broadcastMessage(), broadcastTitle(), broadcastTip() and broadcastPopup() now require specifying a CommandSender $source - this is to allow subscribers to process messages differently based on who sent them (useful for implementing blocking features)
  • broadcastMessage(), broadcastTitle(), broadcastTip() and broadcastPopup() 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 was
  • All broadcast functions in Server that used to accept CommandSender now accept MessageBroadcastSubscriber
  • All broadcast functions in Server that used to accept Player now accept MinecraftMessageBroadcastSubscriber
  • Player now implements MinecraftMessageBroadcastSubscriber

Relevant issues

#5352

Changes

API changes

  • The following API methods now accept MessageBroadcastSubscriber[] $recipients instead of CommandSender[]:
    • Server::subscribeToBroadcastChannel()
    • Server::unsubscribeFromBroadcastChannel()
    • Server::unsubscribeFromAllBroadcastChannels()
    • Server::broadcastMessage()
    • PlayerChatEvent::__construct()
    • PlayerChatEvent::setRecipients()
  • The following API methods now accept MinecraftMessageBroadcastSubscriber[] $recipients instead of Player[]
    • Server::broadcastTip()
    • Server::broadcastPopup()
    • Server::broadcastTitle()
  • The following API methods now require a CommandSender $source as their first argument, and have a new string $channelId = Server::BROADCAST_CHANNEL_USERS argument before $recipients:
    • Server::broadcastMessage()
    • Server::broadcastTip()
    • Server::broadcastPopup()
    • Server::broadcastTitle()
  • The following API methods now return MessageBroadcastSubscriber in place of CommandSender:
    • Server::getBroadcastChannelSubscribers()
    • PlayerChatEvent::getRecipients()
  • Player now implements MinecraftMessageBroadcastSubscriber

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 of broadcastTitle() 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

  • Split BROADCAST_CHANNEL_USERS into more channels, e.g. CHAT, JOIN_QUIT, GAME_EVENTS (death, skin change, etc)
  • Have permissions tested by the broadcast system instead of the janky hack in Player that unsubscribes itself from channels when it doesn't have permissions
  • Support Translatable in broadcastTip(), broadcastPopup() and broadcastTitle()
  • Consolidate title parameters into a Title structure or similar
  • Implement support for Xbox Live user blocking by passing along XUID with chat messages

Tests

This has been tested under the following situations:

  • Player invokes command & observe player & console messages
  • Console invokes command & observe player and console messages
  • Chat works correctly

this allows removing some specialized hacks, such as that for the coloured italic audit messages.
@dktapps dktapps added Category: API Related to the plugin API Type: Contribution BC break Breaks API compatibility labels Oct 18, 2022
@SOF3
Copy link
Member

SOF3 commented Oct 19, 2022

rename to ChatBroadcastReceiver instead? It is ambiguous what exactly you are broadcasting, for example, sound packets.

@dktapps
Copy link
Member Author

dktapps commented Oct 19, 2022

You could make the same argument about broadcast channels. I don't want the terminology to be inconsistent.

@dktapps dktapps added Type: Enhancement Contributes features or other improvements to PocketMine-MP and removed Type: Contribution labels Nov 26, 2022
@dktapps
Copy link
Member Author

dktapps commented Dec 1, 2022

We could even just throw out the interface entirely and require a closure. The only downside to closures is that they are a bit nasty to describe the type of.

Never mind, it's assumed that Player is an instance of ChatBroadcastSubscriber in some places...

SOF3
SOF3 previously approved these changes Dec 3, 2022
Copy link
Member

@SOF3 SOF3 left a 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?

@dktapps
Copy link
Member Author

dktapps commented Dec 4, 2022

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.

Copy link
Member

@ShockedPlot7560 ShockedPlot7560 left a 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.

src/command/Command.php Outdated Show resolved Hide resolved
@dktapps dktapps added Status: Blocked Depends on other changes which are yet to be completed Opinions Wanted Request for comments & opinions from the community labels Nov 12, 2024
@dktapps dktapps requested a review from a team as a code owner November 16, 2024 14:15
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 16, 2024
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 16, 2024
…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.
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 16, 2024
@dktapps dktapps removed the Status: Blocked Depends on other changes which are yet to be completed label Nov 16, 2024
@dktapps dktapps changed the title Broadcast subscriber interface Rewrite server message broadcast system Nov 16, 2024
@dktapps dktapps marked this pull request as draft November 16, 2024 21:08
@dktapps
Copy link
Member Author

dktapps commented Nov 16, 2024

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.

pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 16, 2024
pmmp-admin-bot[bot]
pmmp-admin-bot bot previously approved these changes Nov 16, 2024
@dktapps dktapps changed the title Rewrite server message broadcast system New broadcast subscriber API Nov 16, 2024
@dktapps
Copy link
Member Author

dktapps commented Nov 17, 2024

Closing this as the basic concept seems to be flawed. We could achieve the same thing by adding a simple MessageBroadcastEvent and adding some extra parameters to broadcastMessage(), and I'm sure plugin devs would rather have an event than a weird esoteric interface.

However, most of the follow-ups still apply and I'll submit them as issues separately.

@dktapps dktapps closed this Nov 17, 2024
@dktapps dktapps deleted the broadcast-subscriber branch November 17, 2024 01:06
@dktapps dktapps added Resolution: Abandoned PR has been abandoned by its author and removed Opinions Wanted Request for comments & opinions from the community labels Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BC break Breaks API compatibility Category: API Related to the plugin API Resolution: Abandoned PR has been abandoned by its author Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants