HomeJavaModsSoundCancelerAPI | cancel any sound you want | custom config | simple API
SoundCancelerAPI | cancel any sound you want | custom config | simple API
ModsJava

SoundCancelerAPI | cancel any sound you want | custom config | simple API

This api and plugin allows you to cancel any sound you want. Free Minecraft Java mod for 1.9.

⬇ Download on Spigot
Note: This should work on all versions but it has only been tested on 1.9. If you find it works on other version please tell me.

Note2: If you do not see the SoundCancelerAPI folder, do /soundc reload
What does this do?
This is a simple plugin and api to stop users from hearing sounds. (stop all villager sounds, or even stop all sounds that end in ".step". This allows you to control what sounds your users hear and by using the api, you can customize it even more.

Awesome, now how do I install it?
Download SoundCancelerAPI and put it in your plugins folder then download PacketListenerAPI found here and drop it in your plugins folder.

So.. how do I cancel sounds?
The config is pretty self explanatory. It looks like this:
Code (YAML):

settings
:
  loop-through-config
: false
  enable
: # we will check here to see if you want the plugin to loop through the different sections. Turning the ones off that you don't use may help your server run faster
    name
: true
    contains
: false
    startswith
: false
    endswith
: false

cancel
: #remeber, don't use capitals in the names (unless you have a custom sounds that uses them)
  name
:
   - sound.to.cancel
  contains
: # if you have a slow server with little ram, you should probably turn this off
    - sound.to.cancel.that.contains.this
  startswith
:
   - sounds.to.cancel.that.starts.with.this
  endswith
:
   - sound.to.cancel.that.ends.with.this
    - someentity.step
By default you have to enable everything that you need at the top. Remember to set loop-through-config to true if you are using any of the methods to cancel sounds

What about commands?
Yep there are a few of those too. To have access to all the commands you need to permission "soundcancel.full" (or need to be op)
To see all the commands do /soundcancel or /soundc
commands:
/soundc reload - reloads the config (you will have to do this whenever you edit the config or you can restart the server)
/soundc add <name> - add a sound that you want to stop
/soundc addc <name> - add a sound you want to stop when it contains that name.
/soundc addstart <name> - add a sound you want to cancel when it starts with that name.
/soundc adde <name> - add a sound you want to cancel when it ends with that name

You said there was an API!!!
Yep there sure is. You can listen for SoundSendEvent.
It has everything you could possibly want in it.
you can get the location with getLocation();
you can get the player the sound is playing to with getPlayer();
you can get the sound name with getSoundName(); (you can also set it with setSound(String name)
You can also get the volume and pitch. And of course, you can cancel it with setCancelled(boolean b);
Also, you can check if the sound can be changed by doing canChangeSound()

Here's an example of what I use it for:
Code (Java):

    @EventHandler
    public void onSound ( SoundSendEvent e ) {
        if ( e. getPlayer ( ) . getWorld ( ) . getName ( ) . equalsIgnoreCase ( "worldwithsheep" ) ) {
            if ( e. getSoundName ( ) . contains ( "sheep" ) ) {
                e. setCancelled ( true ) ;
            }
        }
    }
How does this plugin work?
This plugins works by listening for the packets PacketPlayOutCustomSoundEffect and PacketPlayOutNamedSoundEffect then uses reflection so it doesn't import anything allowing it to work on multiple versions. Plus, there's a feature where it detects if the version is 1.8 or below and then treats PacketPlayOutNamedSoundEffect like PacketPlayOutCustomSoundEffect. This feature has not yet been tested, by looking at net.minecraft source, it should work.
This plugin also uses a class called ReflectedObject that I made. You just put an object into the contructor then call whatever method you need to get private fields or methods.

If you find any bugs or if I missed anything, please use the discussion page.

Commands

Plugin details

Read from the plugin's own plugin.yml.

SoundCancelerAPI | cancel any sound you want | custom config | simple API is a free Minecraft Java mod. Compatible with Minecraft 1.9. Downloaded 463 times (via Spigot). Download it and open it directly in the game.

Explore more