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

Cancellable peer connections #399

Merged
merged 3 commits into from
Feb 10, 2024

Conversation

Mindgamesnl
Copy link
Owner

Allow api consumers to cancel specific peer connections. An example implementation would be a case where spectators can hear everyone, but no one can hear spectators (unless the peer is also a spectator)

EventApi.getInstance().registerHandler(ClientPeerAddedEvent.class, event -> {
    // First, convert both users to a Player
    Player client = Bukkit.getPlayer(event.getClient().getActor().getUniqueId()); // listener
    Player peer = Bukkit.getPlayer(event.getPeer().getActor().getUniqueId()); // speaker

    // safety check
    if (client == null || peer == null) return;

    // is the peer in spectator mode, and are we in something else
    if (peer.getGameMode() == GameMode.SPECTATOR && client.getGameMode() != GameMode.SPECTATOR) {
        // alright, we only want the spectator to hear the listener, and not the other way around
        event.setCancelled(true);
    }
});

Copy link

cloudflare-pages bot commented Feb 10, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: a6ea8cd
Status: ✅  Deploy successful!
Preview URL: https://7061fc92.openaudiomc.pages.dev
Branch Preview URL: https://feature-cancellable-peer-con.openaudiomc.pages.dev

View logs

@Mindgamesnl Mindgamesnl merged commit 8d01072 into development Feb 10, 2024
2 checks passed
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.

None yet

1 participant