Removing Sounds with Protocollib

Discussion in 'Plugin Development' started by DefaultSyntax, May 3, 2014.

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

    DefaultSyntax

    Hi I'm a new developer and right now I'm trying to make a plugin that changes what happens when a player gets hit by another player.


    Code:java
    1. // Disable all sound effects
    2. protocolManager.addPacketListener(
    3. new PacketAdapter(this, ListenerPriority.NORMAL,
    4. PacketType.Play.Server.NAMED_SOUND_EFFECT) {
    5. @Override
    6. public void onPacketSending(PacketEvent event) {
    7. // Item packets (id: 0x29)
    8. if (event.getPacketType() ==
    9. PacketType.Play.Server.NAMED_SOUND_EFFECT) {
    10. event.setCancelled(true);
    11. }
    12. }
    13. });


    How would I set this so the packets only block a specific sound?
     
  2. Offline

    hintss

    Check what sound it is, and if it's the one you want to cancel, cancel it?
     
  3. Offline

    DefaultSyntax

    hintss
    I tried changing the second
    "PacketType.Play.Server.NAMED_SOUND_EFFECT"
    to "PacketType.Play.Server.NAMED_SOUND_EFFECT.equals(Sound.HURT_FLESH)) "
    but it's always giving me the error saying
    "Operator '==' cannot be applied to 'com.comphenix.protocol.PacketType', 'boolean' "
     
  4. Offline

    mbcx2

    Hello!
    I need to do the same thing too!
    @aadnk
     
  5. Offline

    fireblast709

    DefaultSyntax mbcx2 when working with ProtocolLib, you will be able to get and modify the actual packet fields. In this case, the sound packet, has a String field which holds the name of the sound, as specified in the link below. You get this field by getting all the Strings from the packet, and then read the first String.
    Code:java
    1. // gets the PacketContainer, wrapping the raw packet
    2. event.getPacket()
    3. // gets the StructureModifier<String>, which is able to read/write all Strings from the packet
    4. .getStrings()
    5. // gets the first String field from the packet. As you can see in the link, this is the sound name
    6. .read(0);

    http://wiki.vg/Protocol#Sound_Effect
     
  6. Offline

    mbcx2

    But I can't see it getting portal.portal
    it only gets dig.stone when I place stone example but breaking stone wont give me any output
     
  7. Offline

    fireblast709

  8. Offline

    mbcx2

  9. Offline

    fireblast709

    mbcx2 not sure which particle that is.
     
  10. Offline

    NathanWolf

    You could always make and host a custom RP for your plugin/server.

    Just remove or change the sounds in the RP, might be much easier and more flexible for your users/players.
     
Thread Status:
Not open for further replies.

Share This Page