The API
Please PM me if you wrote a Plugin using this API, I'm curious what people will do :)
How to use the API
This example code might be fired when a player respawns.
Important for this to work is that there is a sound linked to a label in the config section (apisounds)
Ok, now to java:
First you have to import it the same way as you import bukkit to your reference libraries.
Now we have to create a reference:
eventsounds es = (eventsounds)Bukkit.getPluginManager().getPlugin("EventSounds"); if (es == null) return;
you may add a depend or softdepend part to your plugin.yml later but keep in mind that es might become null if you're using softdepend.
Now i'm gonna check, if the sound exist:
if (es.knowSound("respawn")) {
As argument use the label as setup in the config. This will only return true if the config entry exists - it can't check if the client has a resource called like that or if the client has a resourcepack installed at all.
now i don't want to play the sound along with an other, so i'll check if it's spaming:
if (!es.isSpam()) {
I guess i don't need to explain that any more ;)
Now each client owns a soundcount, telling if he can play a sound or not (== 0)
if (es.soundCount(player) > 0)
ok, so if he got some sounds left, we may play the sound to all players on the server:
es.playSound("respawn");
or we can play it to only the player using:
es.playSound(player, "respawn");
note, that you need to use the label again as mentioned befrore,
As complete example it may look like this:
eventsounds es = (eventsounds)Bukkit.getPluginManager().getPlugin("EventSounds"); if (es == null) return; if (es.knowSound("respawn")) { if (!es.isSpam()) { if (es.soundCount(player) > 0) es.playSound("respawn"); else player.sendMessage("You got no sounds left to use!"); } else player.sendMessage("This sound might overlap an other sound right now"); } else player.sendMessage("Sound was not registered!");
Command Overview
/** * Checks if the sound is linked between config and sound.json by a label * @param label The sound labe to search for as setup in the config * @return true if sound was found - otherwise false */ public boolean knowSound(String label) /** * Play a sound by label to a player at his current possition with a range huge range * @param target The player that is supposed to hear the sound * @param label The sound to be played as setup in the config */ public void playSound(Player target, String label) /** * Play a sound by label to all player on the server * @param label The sound to be played as setup in the config */ public void playSound(String label) /** * Checks if this sound would spam by cooldown * @return true if this would be spam - false if cooldown reached 0 */ public boolean isSpam() /** * The number of sounds the player has left before beeing blocked * @return The number of sounds for the player - Admins always return 0! */ public int soundCount(Player target)
The Event-Listener (0.2+)
Data you may get by the Event:
/**The sound-name as it's sent to the client to play the sound * For teleports this will be null as two sounds are played at a time * @return the name as string (null on teleport) */ String getSound() /** Specifies what caused the sound to be triggered * @return the sound type */ SoundType getType() /** The player trying to trigger the sound * @return a player (may be null) */ Player getPlayer() boolean isCancelled() void setCancelled(boolean cancel)
The SoundType contains the following values:
SAYSOUND, ADMINSAYSOUND, JOINSOUND, GLOBALJOINSOUND, HOTBARSCROLL, KILLSTREAK, MULTIKILL, SUICIDE, TELEPORT, PLUGIN
Comments