playSound() with Audio Pack

Discussion in 'Plugin Development' started by The_BloodHound, Jul 2, 2015.

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

    The_BloodHound

    Is it possible to use player.playSound() with an audio pack? In the parameters, I know you put SOUND.soundHere but how would I put an audio pack sound there?
     
  2. Offline

    pie_flavor

    @The_BloodHound I hate to say it, but you may be looking for Server#dispatchCommand(CommandSender, String)
     
  3. Offline

    dlange

  4. Offline

    pie_flavor

    @dlange A resource pack with sounds that do not override minecraft sounds.
    They will not be executed by the bukkit API or in-game actions and must be executed with the /playsound command.
     
  5. Offline

    dlange

  6. I just noticed this is incredibly easy. I'm not sure how long this will stay available since it's deprecated but it's as easy as Player#playSound(Location, String (soundName, not from Sound enum), float volume, float pitch); Same goes with World.
     
    Konato_K likes this.
  7. Offline

    Hawktasard

    @megamichiel
    It should be usable until at least the next Bukkit update (never).
     
  8. @Hawktasard
    Spigot is still maintaining bukkit, so it might get removed.
     
  9. Offline

    The_BloodHound

    I was asking what I would put in the soundName.
    Lets pretend there is an audio code from the audio pack "sounds.coolmusic.wheniseeyouagain"
     
  10. @The_BloodHound
    Then you should be able to play it by putting in "sounds.coolmusic.wheniseeyouagain"
     
  11. Offline

    BurnyDaKath

    If you using CraftBukkit or Spigot (not API, server jar itself as library) you can send player packet through NMS.
    Code:
    ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect("sounds.coolmusic.wheniseeyouagain", /*X*/, /*Y*/, /*Z*/, /*volume*/, /*pitch*/));
    It looks like "/playsound" command.
     
  12. Offline

    Zombie_Striker

    @The_BloodHound
    You can take a look at my Music plugin and the ResourcePack tests which uses custom sounds if you want. This is what I use to send the sound "Sound" to a player

    Plugin
    Code:
    player#playSound(player.getLocation(),"Sound",10,1);
    Resourcepack folder : sounds
    Code:
    Sound.ogg
    Resourcepack sounds.json
    Code:
    {
      "Sound": {
        "sounds": [
          "Sound"
        ]
      },
    }
     
    The_BloodHound likes this.
  13. Offline

    Konato_K

    @megamichiel It deprecated in favour of the version with the Enum, but it's unlikely to be removed since it's really useful.
     
  14. Offline

    The_BloodHound

    Thanks! This helped. And thanks too everyone else that helped. I'll be testing this then I'll change the thread to solved.
     
Thread Status:
Not open for further replies.

Share This Page