PreChangeSoundVolumeEvent
Event Details
Property
Type
Description
Example
import ir.taher7.melodymine.api.events.PreChangeSoundVolumeEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public class MyPlugin extends JavaPlugin implements Listener {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onPreChangeSoundVolume(PreChangeSoundVolumeEvent event) {
// Log the sound name and new volume to the console
getLogger().info("Sound " + event.getSoundName() + " is about to have its volume changed to " + event.getVolume());
r
// Log the details of the event
logger.info("Sound Name: " + event.getSoundName());
logger.info("Send To All: " + event.isSendToAll());
logger.info("Socket ID: " + event.getSocketID());
logger.info("New Volume: " + event.getVolume());
// If the volume is above a certain level, cancel the event
if (event.getVolume() > 1.0) {
event.setCancelled(true);
getLogger().info("Cancelled the volume change because the new volume is too high.");
}
}
}Last updated