changeSoundVolume()

changeSoundVolume Method in MelodyManager Class

The changeSoundVolume method is used to change the volume of a sound in the MelodyMine plugin. This method can change the volume of a sound for a specific player or for all players, depending on the parameters passed.

Method Signature

public void changeSoundVolume(String soundName, boolean sendToAll, String socketID, double volume)

Parameters

ParameterTypeDescription

soundName

String

The name of the sound for which the volume is to be changed.

sendToAll

boolean

Determines whether the volume should be changed for all players or not.

socketID

String

The socket ID of the player for whom the volume should be changed. This is ignored if sendToAll is true.

volume

double

The new volume level for the sound.

Example

Here is an example of how to use the changeSoundVolume method in another plugin:

import ir.taher7.melodymine.core.MelodyManager;
import ir.taher7.melodymine.models.MelodyPlayer;

public class ExamplePlugin {

    public void changeVolumeForPlayer(String playerUUID, String soundName, double newVolume) {
        MelodyPlayer player = MelodyManager.INSTANCE.getMelodyPlayer(playerUUID);

        if (player != null) {
            MelodyManager.INSTANCE.changeSoundVolume(soundName, false, player.getSocketID(), newVolume);
            Bukkit.getLogger().info("Changed volume of sound " + soundName + " for player " + player.getName() + " to " + newVolume);
        } else {
            Bukkit.getLogger().warning("Player not found.");
        }
    }
}

In this example, the changeVolumeForPlayer method in the ExamplePlugin class retrieves the MelodyPlayer instance for the player using their UUID. It then uses the changeSoundVolume method of the MelodyManager class to change the volume of a sound for the player. If the volume is successfully changed, a message is logged to the console. If the player is not found, a warning is logged instead.

Last updated