Voice Chat - CheatBreakerV2/CheatBreakerAPI GitHub Wiki

The CheatBreaker API allows you to enable voice chat for your server. Voice Data is sent to the game server and forwarded to users in the incoming players' voice channel.

Enabling Voice

To enable voice, use:

CheatBreakerAPI.getInstance().getServerRuleHandler().setVoiceEnabled(true)


Creating Voice Channels

Note: Players will only hear people who are in the same channel as they are.

To create voice channels, use:

CheatBreakerAPI.getInstance().getVoiceChatHandler().createVoiceChannels(VoiceChannel channel...)


Adding a player to a channel

Note: Players are not automatically marked as listening to the first channel they are added to.

A player must be in a channel and marked as listening to receive voice data. Players can switch freely between the channels they are added to.

To add a player to a channel, use:

channel.addPlayer(Player player)

To mark them as listening, set their active channel by calling:

CheatBreakerAPI.getInstance().getVoiceChatHandler().setActiveChannel(Player player, VoiceChannel channel)


Removing a player from a channel

To remove a player from a channel, use:

channel.removePlayer(Player player)


Voice Channel Checks

Channel contains player

To see if a voice channel contains a player, use:

channel.hasPlayer(Player player)

Player is listening

To see if a channel is the player's active channel, use:

channel.isListening(Player player)

Example

Below is an example of what is needed to create a global voice channel where anyone can talk.

public class CBVoicePlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        CheatBreakerAPI.getInstance().getServerRuleHandler().setVoiceEnabled(true);

        final VoiceChannel publicVoiceChannel = new VoiceChannel("Public Channel");
        CheatBreakerAPI.getInstance().getVoiceChatHandler().createVoiceChannels(publicVoiceChannel);

        getServer().getPluginManager().registerEvents(
                new Listener() {

                    @EventHandler
                    public void onPlayerJoin(PlayerJoinEvent event) {
                        publicVoiceChannel.addPlayer(event.getPlayer());
                        CheatBreakerAPI.getInstance().getVoiceChatHandler().setActiveChannel(event.getPlayer(), publicVoiceChannel);
                    }
                }, this
        );
    }
}