sending packets to player

Discussion in 'Spigot Plugin Development' started by Ean244, Jun 1, 2017.

  1. hey guys i was wondering is it possible to make a plugin that sends an anvil sound packet to a player without worrying the version of minecraft?

    Im quite new to packets
     
  2. There are methods out there to check which version the servers running based on Classes.
     
  3. Just wrap the playSound using new sound in a try/catch. In the catch send the old one. It's pretty simple ;)
     
    • Like Like x 1
  4. Ummmmm no error is produced from playSound, it would just fail silently?
     
  5. There's literally something in the API for playing sounds...

    Player#playSound

    Also, Hi Cammy
     
    • Funny Funny x 1
  6. Code (Text):
    try{
        // play sound using 1.9+ method
    }catch(Exception ex){
        // play sound using 1.8- method
    }
     
  7.  
  8. Its the same method, the only thing thats different is the name of the sound, which he should be choosing at startup based on the server version.

    Have multiple classes that hold the information for each version, and choose the one at startup
     
  9. tbh I feel like that's overcomplicated when you can just try one, and if it fails, use the other. Simple, easy, and (theoretically) works.
     
  10. Are you avoiding my replies on purpose? xD
     
    • Funny Funny x 1
  11. Sorry, I didn't even see them lol
    If they fail silently, we could just use an NMS Class detector. People use them all the time for PlayerList and Scoreboard stuff with multi-version support.
     
  12. *sigh*
     
    • Agree Agree x 2
  13. Alright give me a break, you guys know this stuff a lot better than I do, and I'm exhausted! :'D
     
  14. so... which is the best choice??
    im a bit confused
     
  15.  
  16. Whatever @Mr.Midnight and @Sxtanna say
     
    • Like Like x 1
  17. Will other players hear it too
     
  18. If you iterate through a list of players, yes. If you just send it to one player, no.
     
  19. Code (Text):

    try {
        player.playSound(Sound.valueOf("ANVIL_NEW"));
    } catch(IllegalArgumentException e) {
        player.playSound(Sound.valueOf("ANVIL_OLD"));
    }
     
    Writing from my phone, so this is pseudo code. Idr the exact namings :p

    Sound is an enum, meaning it comes with a fancy valueOf(String) method. If given a bad value it throws an IllegalArgumentException.
     
    • Informative Informative x 1
  20. whats the float,float params for @ playsound