Skip to content

VoiceChat API

Overview

Our VoiceChat has it's own API to enable/disable certain features. Useful for tournaments or role play servers.

Requirements

Disable the entire voice chat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
/**
 * Just send this packet if the player joins the server to disallow the voice chat for the entire server.
 */
public void disableVoiceChat( Player player ) {
    JsonObject object = new JsonObject();

    // Disable the voice chat for this player
    object.addProperty( "allowed", false );

    // Send to LabyMod using the API
    LabyModPlugin.getInstance().sendServerMessage( player, "voicechat", object );
}

Change the settings of the voice chat

voicechat

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
 * Recommend or force player to change the voice chat settings
 */
public void sendSettings( Player player, boolean keepSettings, boolean required ) {
    JsonObject voicechatObject = new JsonObject();

    // "Keep settings" means that the settings are only reset when the player leaves the entire server network.
    // If this setting is set to "false", everything will be reset when the player switches the lobby for example.
    voicechatObject.addProperty( "keep_settings_on_server_switch", keepSettings );

    JsonObject requestSettingsObject = new JsonObject();

    // Required means the player MUST accept the settings to access the server. It's no longer a suggestion.
    requestSettingsObject.addProperty("required", required );

    JsonObject settingsObject = new JsonObject();

    // Only set the settings you want to change, remove everything else!
    settingsObject.addProperty("enabled", true); // Force player to enable the VoiceChat
    settingsObject.addProperty("microphoneVolume", 10); // Own microphone volume. (0 - 10, Default 10)
    settingsObject.addProperty("surroundRange", 10); // Range of the players you can hear (5 - 18, Default: 10)
    settingsObject.addProperty("surroundVolume", 10); // Volume of other players (0 - 10, Default: 10)
    settingsObject.addProperty("continuousTransmission", false); // Speak without push to talk

    requestSettingsObject.add("settings", settingsObject );
    voicechatObject.add("request_settings", requestSettingsObject);

    // Send to LabyMod using the API
    LabyModPlugin.getInstance().sendServerMessage( player, "voicechat", voicechatObject );
}

Response messages

The client will send the following response using thevoicechat key after closing the recommendation GUI:

1
2
3
{
    "accepted_settings": true
}

The client will send the following message with the voicechat key if the player joins a server or changes the voice chat settings:

1
2
3
4
5
6
7
8
9
{
    "enabled": true,
    "surround_range": 10,
    "surround_volume": 10,
    "screamer_protection": true,
    "screamer_protection_level": 75,
    "screamer_max_volume": 15,
    "microphone_volume": 10
}

Mute players

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/**
 * Mute a player for someone
 */
public void sendMutedPlayerTo( Player player, UUID mutedPlayer, boolean muted ) {
     JsonObject voicechatObject = new JsonObject();
     JsonObject mutePlayerObject = new JsonObject();

     mutePlayerObject.addProperty("mute", muted );
     mutePlayerObject.addProperty("target", mutedPlayer );

    voicechatObject.add("mute_player", mutePlayerObject);

    // Send to LabyMod using the API
    LabyModPlugin.getInstance().sendServerMessage( player, "voicechat", voicechatObject );
}