PrePlaySoundEvent
Event Details
Property
Type
Description
soundName
String
The name of the sound that is about to be played.
sendToAll
Boolean
Indicates whether the sound is sent to all players.
socketID
String
The socket ID of the player who will receive the sound.
volume
Double
The volume of the sound.
Example Usage
Here is an example of how to listen to this event using the Bukkit event API in Java:
import ir.taher7.melodymine.api.events.PrePlaySoundEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class ExampleListener implements Listener {
private JavaPlugin plugin;
public ExampleListener(JavaPlugin plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPrePlaySound(PrePlaySoundEvent event) {
String soundName = event.getSoundName();
boolean sendToAll = event.isSendToAll();
String socketID = event.getSocketID();
Double volume = event.getVolume();
plugin.getLogger().info("A sound is about to be played!");
plugin.getLogger().info("Sound Name: " + soundName);
plugin.getLogger().info("Send to All: " + sendToAll);
plugin.getLogger().info("Socket ID: " + socketID);
plugin.getLogger().info("Volume: " + volume);
}
}
In this example, we create a listener for the PrePlaySoundEvent
. When the event is triggered, we retrieve the details of the sound that is about to be played and log them to the console.
Remember to register your listener in your plugin's onEnable
method to ensure that it listens to the events.
Last updated