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

Warning

Not available in LabyMod 4!

/**
 * 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
    LabyModProtocol.sendLabyModMessage( player, "voicechat", object );
}

Change the settings of the voice chat

Warning

Not available in LabyMod 4!

voicechat

/**
 * 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
    LabyModProtocol.sendLabyModMessage( player, "voicechat", voicechatObject );
}

Response messages

The client will send the following response using thevoicechat key after closing the recommendation GUI, joining a server or changing the voice chat settings:

{
    "enabled": true,
    "surround_range": 10,
    "surround_volume": 10,
    "screamer_protection": true,
    "screamer_protection_level": 75,
    "screamer_max_volume": 15,
    "microphone_volume": 10,
    "accepted_settings": true
}
accepted_settings is true if the player accepted the custom settings of the server.

Mute players

Warning

This is for LabyMod 3. See LabyMod 4 variant below.

/**
 * 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
    LabyModProtocol.sendLabyModMessage( player, "voicechat", voicechatObject );
}

Mute players in LabyMod 4

/**
 * Mute a player for someone.
 * 
 * This should to be sent to every LabyMod player as custom 
 * addons could otherwise bypass this if only sent to the
 * muted player(s) themselves.
 */
public void sendMutedPlayerTo(Player player, UUID mutedPlayer, boolean muted) {
    JsonObject voiceChatObject = new JsonObject();
    JsonArray mutePlayersArray = new JsonArray();

    // You can also add multiple players to this at once
    JsonObject mutePlayerObject = new JsonObject();
    mutePlayerObject.addProperty("mute", muted);
    mutePlayerObject.addProperty("target", mutedPlayer.toString());
    mutePlayersArray.add(mutePlayerObject);

    voiceChatObject.add("mute_players", mutePlayersArray);

    // Send to LabyMod using the API
    LabyModProtocol.sendLabyModMessage(player, "voicechat", voiceChatObject);
}