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

[feature] New event driver + api #396

Merged
merged 9 commits into from
Feb 8, 2024

Conversation

Mindgamesnl
Copy link
Owner

Setup new event api which is actually usable for the separate API maven package.
Goals:

  • platform agnostic
  • only depend on whats available within the api package
  • "internal" events which must include internal classes, such as state changes, should be in the plugin package itself and not exposed to the API
  • current events should be marked as deprecated, and translated where possible (not fully baked because this will be deleted eventually)

@Mindgamesnl Mindgamesnl marked this pull request as draft February 7, 2024 22:20
@Mindgamesnl Mindgamesnl changed the title New event driver + api [feature] New event driver + api Feb 7, 2024
Copy link

cloudflare-workers-and-pages bot commented Feb 8, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 30316d2
Status: ✅  Deploy successful!
Preview URL: https://f2612058.openaudiomc.pages.dev
Branch Preview URL: https://feature-event-api-and-servic.openaudiomc.pages.dev

View logs

@Mindgamesnl
Copy link
Owner Author

Mindgamesnl commented Feb 8, 2024

State of event changes. This comment will be updated as I continue to migrate them.

All events:

  • All old events have been deprecated
  • New events reference the new Client interface.

Breaking changes to the public api

  • MediaError has been moved to com.craftmend.openaudiomc.api.media.MediaError

Re-implementations

The following events are implemented in the new system with the same name but carry the new Client interface.
The counterparts of these events are still fired through the old system for now, but it will print warnings in the console and they will be removed in the future.

  • ClientConnectEvent
  • ClientDisconnectEvent
  • ClientErrorEvent's new version has been renamed to MediaErrorEvent
  • ClientPreAuthEvent's new version has been renamed to ClientAuthenticationEvent
  • ClientRequestVoiceEvent's new version has been renamed to ClientEnableVoiceEvent
  • MicrophoneMuteEvent
  • MicrophoneUnmuteEvent
  • VoicechatDeafenEvent
  • VoicechatUndeafenEvent
  • PlayerConnectVoicechatEvent's new version has been renamed to VoicechatReadyEvent
  • PlayerEnterVoiceProximityEvent is being replaced by ClientPeerAddedEvent, which also includes the options of the peer
  • PlayerLeaveVoiceProximityEvent is being replaced by ClientPeerRemovedEvent, which also includes the options of the peer
  • SystemReloadEvent
  • VoiceChatPeerTickEvent is being replaced by VoicechatPeerTickEvent which now only fires post tick, removing the pre-tick state.

Removed or made private

These events have either been removed because they served no extra purpose or are only available within the plugin package

  • AccountAddTagEvent
  • AccountRemoveTagEvent
  • ClientPreAuthEvent
  • SpigotAudioCommandEvent
  • StateChangeEvent
  • TimeServiceUpdateEvent

Examples

Here's an example of how the old essentials integration worked, and how the new API is used in the new implementation.

Old

ApiEventDriver driver = AudioApi.getInstance().getEventDriver();
Essentials ess = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
if (driver.isSupported(ClientRequestVoiceEvent.class)) {
    driver.on(ClientRequestVoiceEvent.class)
            .setHandler(event -> {

                User usr = ess.getUser(event.getRequester().getOwner().getUniqueId());
                if (usr == null) return;
                boolean isMuted = usr.isMuted();

                if (isMuted) {
                    OpenAudioLogger.toConsole("Blocking voicechat for " + event.getRequester().getUser().getName() + " because they are muted on Essentials");
                    event.setCanceled(true);
                }
            });
}

New

EventApi.getInstance().registerHandler(ClientEnableVoiceEvent.class, event -> {
    User user = ((Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials")).getUser(event.getClient().getActor().getUniqueId());
    if (user == null) return;
    if (user.isMuted()) {
        OpenAudioLogger.toConsole("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on Essentials");
        event.setCancelled(true);
    }
});

@Mindgamesnl Mindgamesnl marked this pull request as ready for review February 8, 2024 18:08
@Mindgamesnl Mindgamesnl merged commit 48a7029 into development Feb 8, 2024
3 checks passed
@Mindgamesnl Mindgamesnl deleted the feature/event-api-and-service branch February 8, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant