How do I play a sound for a player on disconnect?

Discussion in 'Plugin Development' started by pop4959, May 20, 2014.

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

    pop4959

    I've seen it done in other plugins (such as AntiSwear for chat events), but I was wondering how to do this. I tried using playSound, playEffect, and createExplosion to generate some sort of sound for a player when they disconnect, but I cannot get it to work.

    Any help?
     
  2. Offline

    Gater12

    pop4959
    You want to play a sound to a player that will be disconnected?
     
  3. Offline

    JasonDL13

    You can try and look at net.minecraft.server code. You have to use CraftBukkit as a external jar though. Then construct a PacketPlayOutNamedSound (if think that's what the packet is called) and send it to all/nearby players by doing:

    ((CraftPlayer)p).getHandle().playerConnection.sendPacket(Packet);
     
  4. Offline

    Gater12

    JasonDL13
    Or loop through nearest players from that player and play the sound to them using Bukkit API if I understand correctly.
     
  5. Offline

    pop4959

    Yes, as my example (AntiSwear) does. Except that plays a sound only if a player swears, and kicks them the split second after playing the sound. I tried replicating this but I haven't gotten it working.
     
  6. Offline

    Gater12

    pop4959
    I guess you can try a delayed task to kick the player after a full second or so.
     
Thread Status:
Not open for further replies.

Share This Page