Sound Volume and Pitch

Discussion in 'Plugin Development' started by the_merciless, Jun 7, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    Is there a way to play the default volume and pitch of a sound,


    player.playSound(player.getLocation(), args[0], vol, pitch);

    where args[0] is what sound the player typed,
    vol would be replaced with the correct volume for the sound and same for pitch.
  2. Offline

    ZeusAllMighty11 Retired Staff

    Hey, the_merciless !

    It seems that you almost have it, but you need to parse the sound enum value into an actual. For example:

    2. // as in your example
    3. player.playSound(player.getLocation(), Sound.valueOf(args[0]), Float.parseFloat(/* Some float*/), Float.parseFloat(/*Some float*/);

    However, I can not recall off the top of my head if Sound has a valueOf() method. If it does not, it may have a fromName() method or something similar, in which you can compare.

    But keep note that enumeration values often use _ (underscores), and you will need to recognize this when parsing. You can also create your own method to parse your own sound, try reading around.

  3. Offline


    I think its easier to do 1F instead of Float.parseFloat(1)
  4. Offline

    ZeusAllMighty11 Retired Staff


    Not everyone uses 1 as their float value!
  5. Offline


    Thats not exactly what i meant. The sound name is fine, i just wanted to ensure the pitch was the correct pitch for the sound, but it seems 1 is the correct pitch for all sounds. So i have it working perfectly now with this code:

    for (Sound sound : Sound.values()){
                    if ( + ".Sound"))){
                        p.playSound(p.getLocation(), sound, 5, 1);
  6. Offline


    you can use #F for your float. USE ALL DA NUMBERS :p

    Yeah 1 is the correct pitch. Or at least it is close enough.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 1, 2016
  7. Offline


    1 is default volume, and 0 is default pitch.
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page