PostPlaySoundEvent
PostPlaySoundEvent
Class Attributes
soundName
String
The name of the sound that was played.
sendToAll
Boolean
Indicates whether the sound was sent to all players.
socketID
String
The socket ID of the player who triggered the sound.
volume
Double
The volume at which the sound was played.
Listening to the Event
To listen to this event, you need to create a class that implements the Listener
interface from the Bukkit API. Inside this class, you can then define a method annotated with @EventHandler
to handle the PostPlaySoundEvent
.
Here is an example:
import ir.taher7.melodymine.api.events.PostPlaySoundEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class SoundEventListener implements Listener {
@EventHandler
public void onPostPlaySound(PostPlaySoundEvent event) {
// Get the sound name
String soundName = event.getSoundName();
// Get the socket ID
String socketID = event.getSocketID();
// Log the information
Bukkit.getLogger().info("Sound " + soundName + " was played by player with socket ID " + socketID);
}
}
In this example, the onPostPlaySound
method is called whenever a PostPlaySoundEvent
is triggered. The method retrieves the name of the sound and the socket ID of the player who triggered the sound, and then logs this information to the console.
Remember to register your event listener with the Bukkit plugin manager to ensure that your @EventHandler
methods are called when the events are triggered.
Last updated