A few questions about packets

Discussion in 'Plugin Development' started by NonameSL, Apr 9, 2014.

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

    NonameSL

    1. What exactly ARE packets? I always see questions about packets, and I know that packets are part of the minecraft code, but I do not know exactly what are they.

    2. How can I use them? I have seen packets like Packet62NamedSoundEffect , and I have tried to import them (net.miencraft.server.Packet62NamedSoundEffect) but the class dosen't exist. Why?

    3. I chose the example of the packet Packet62NamedSoundEffect because I have a question: Can I use this packet or any other packet to play a sound? I saw SoundEffects[Tutorial] but for some reason both Packet62NamedSoundEffect and Packet62LevelSound wont import, it can not be resolved. I have both bukkit and craftbukkit in my build path, what am I doing wrong?
     
  2. Offline

    coasterman10

    1. Packets are bits of information sent between the Minecraft client and server telling each other about any updates to the world. This involves primarily movement, block updates, chat, etc.

    2. You need to build against the net.minecraft.server package, effectively the CraftBukkit jar. Packets are part of the server implementation, so they are not part of the Bukkit API. You can link the CraftBukkit jar the same way you did the Bukkit jar.

    3. Now that you say you have CraftBukkit, the problem is that the packet you are trying to use is from Minecraft 1.6 backwards. In Minecraft 1.7 forwards, the packets have been renamed. The new packet names are PacketPlayOutNamedSoundEffect and I can't find the other one. You should probably try using Player.playSound or World.playSound though.
     
  3. Offline

    NonameSL

    coasterman10 , thanks! But I want to use PacketPlayOutNamedSoundEffect because I want to have my own sound effects. Do you have any idea how to use it?
     
  4. Offline

    Xenira


    I would recomend to use ProtocolLib for packets. They have a library caled PacketWrapper which helps to create packets.
    You should also have a look at their tutorial page ;)

    MfG Xenira
     
  5. Offline

    NonameSL

    Alright, after some snooping I got this:
    PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect("note.pling",x,y,z,1.0F,1.0F);

    Now, I have another problem - to use packet.handle(PacketPlayOutListener); I need a PacketPlayOutListener. But PacketPlayOutListener is an interface (which also extends PacketListener, also an interface) and I have no idea how to create a PacketPlayOutListener which is not null. How can I do that? Which class implements the Listener?
    EDIT:
    Xenira woops, didn't see your comment there... How can I play a sound using ProtocolLib? I saw this:
    Code:
    ProtocolLibrary.getProtocolManager().addPacketListener(
                    new PacketAdapter(main, ConnectionSide.SERVER_SIDE,
                    Packets.Server.NAMED_SOUND_EFFECT) {
                    @Override
                    public void onPacketSending(PacketEvent event) {
                    Packet3ENamedSoundEffect named =
                    new Packet3ENamedSoundEffect(event.getPacket());
                   
                    // Random sound name
                    String[] choices = Packet3ENamedSoundEffect.
                    NamedSoundEffects.values();
                    named.setSoundName(choices[rnd.nextInt(choices.length)]);
                    }
                    });
    But there is no Packet3ENamedSoundEffect... What can I do? What IS the correct class?
     
  6. Offline

    Xenira

  7. Offline

    NonameSL

    Yes, but that uses the class WrapperPlayServerExplosion, and this class and WrapperPlayServerNamedSoundEffect for some reason are not in ProtocolLib v3.0.2. Why?
     
  8. Offline

    Xenira


    If you want to use the PacketWrapper you need to download it here and add AbstractPacket AND WrapperPlayServerNamedSoundEffect to your Project.

    MfG Xenira
     
  9. Offline

    NonameSL

    Okay... I actually found packets easier.
    (EDIT: Why do I find packets easier? Because all I need is this code:
    Code:java
    1. public void playSoundPacket(String name, Location l, float volume, float pitch, Player p){
    2. double x = l.getX();
    3. double y = l.getY();
    4. double z = l.getZ();
    5. PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(name,x,y,z,volume,pitch);
    6. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
    7. }

    )
    Code:
    public void playSoundPacket(String name, Location l, float volume, float pitch, Player p){
            double x = l.getX();
            double y = l.getY();
            double z = l.getZ();
            PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(name,x,y,z,volume,pitch);
            ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
        }
    And now I have another problem, and another one! Hooray!
    The sound at pitch 0, 1 and 2 is the note F# in different scales, and anything above 2 is F#, same scale as pitch 2.
    Plus, he volumes all sound the same to me.
    I tried this code to run 110 plings, from pitch 0 to 10 (11 pitches 10 times, each time in a different volume from 1 to 10) and it works, but I understood that the volumes are the same and that the pitches from 2 and up are all the same.

    I don't really care about the volume, so I have only one question now:
    How can I change the pitch of the note.pling to produce different sounds?
     
  10. Offline

    Xenira


    They might be easyer, but if you have multiple plugins using packages ProtocolLib is saver.

    If I remember it corectly you need a value between 0 and 1 for the pitch ;)

    MfG Xenira
     
  11. Offline

    NonameSL

    I snooped in some other plugins and found out that I am kind of stupid, because I forgot that the pitch doesn't have to be in round numbers. By the way, it is a value between 0 and 2. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page