playSound()

playSound Method in MelodyManager Class

The playSound method is used to play a sound in the MelodyMine plugin. This method can play a sound for a specific player or for all players, and the volume of the sound can be adjusted.

Method Signature

public void playSound(String soundName, boolean sendToAll, String socketID, Double volume)

Parameters

ParameterTypeDescription

soundName

String

The name of the sound to be played.

sendToAll

boolean

Determines whether the sound should be played for all players or not.

socketID

String

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

volume

Double

The volume at which the sound should be played.

Example

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

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

public class ExamplePlugin {

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

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

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

Last updated