Stopping Sounds

Discussion in 'Spigot Plugin Development' started by Necros, Jun 23, 2015.

  1. Hi to all, i'm developing a plugin for my server where the players can do /play stream songname . And it uses custom sounds presents in the server resourcepack. The plugin works well but i don't know how to stop it from playing sounds.
    Does anyone knows how to stop a custom sound or replace with something short (for example wood_Step) with a command? (/stop playstream)
    Please i really need help with this. Thanks in advance.
     
    #1 Necros, Jun 23, 2015
    Last edited: Jun 23, 2015
  2. Most servers I have seen cancel the scheduler that replays the loop and tells the user that it will stop at the next start of the loop.
     
  3. Turn sound on 0
     
  4. Yes but how?!...
    I know but i don't have any loop, it's a 5 minutes song. I need to stop it when the player wants or to replace it with a command. I think i'm clear in the description of the post..
     
  5. I understand that, but the only thing I can think of is looking for packets which I don't have a ton of experience with. Look and see what you can find in protocol lib.
     
  6. I already know that, but i asked for help because i need help from seomeone that already knows how to do that.
     
  7. If you need the code i used to start the sound, there is it:
    Code (Text):
    } else if (args[0].equalsIgnoreCase("stream")) {
                            if(args.length ==1) {
                                Player p = (Player) sender;
                                p.sendMessage("a");
                                ((CraftPlayer) p).getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect("creeptowny.necros.music.skrillex1", p.getLocation().getBlockX(), p.getLocation().getBlockY(), p.getLocation().getBlockZ(), 10.0F, 1.0F));
                            }
     
  8. Hex

    Hex
    IRC Staff

    It's a bit messy, but music will stop on a dimension change or a respawn.
    Code (Text):
    else if (args[0].equalsIgnoreCase("stopmusic")) {
        Player p = (Player) sender;
        Location l = p.getLocation();
        net.minecraft.server.World w = ((CraftWorld)l.getWorld()).getHandle();
        p.sendMessage("Stopping music...");
        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(new PacketPlayOutRespawn(-1, w.getDifficulty(), w.getData().getType(), EnumGamemode.SURVIVAL);
        p.teleport(l);
    }
     
    • Informative Informative x 1
  9. There are some errors in the code (net.minecraft.server.world should be net.minecraft.server.v1_8_R2.World) and it gives me "no methods found on
    w.getData()"
     
  10. I'd really like to know how to do this, too. There must be a packet that is sent when a player deactivates a jukebox, for instance- right? Or is that something very specific to jukeboxes?

    Sending a fake respawn packet seems like it's going to cause all kinds of trouble.. but maybe not?
     
  11. Hex

    Hex
    IRC Staff

    Sorry, I wrote that up without testing.
     
  12. I don't know but i don't think so. Because (For me) there is nothing about jukeboxes.... And i asked a lot of devs how to do that, 2 of them told me that this is not possible, one of them told me to cut in more parts the song and play all them sequentially so that when a player does /song stop it will not keep playing...

    I still can't figure out what's the problem with .getData() .... Can you please test it?
     
  13. Maybe try having a soundtrack that is just complete silence and set that to the song that the player is listening to.
     
  14. Hex

    Hex
    IRC Staff

    It shouldn't cause trouble, but it'll show you that ugly dirt screen for a second. And the world.getData() was only to get the nms WorldType, you can probably find another way to get it.
     
  15. Lol, still no one figured out how to stop sounds? Me not.