Sitting on blocks packet

Discussion in 'Plugin Development' started by MCCoding, Aug 30, 2013.

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

    MCCoding

    I have made it so players can sit on blocks like a chair i'm using the Packet18ArmAnimation but its not making the player sit all its doing is a fade effect i'm not sure if its the wrong packet or i'm not using it right.
     
  2. Offline

    phips99

    MCCoding What should a blade effect be?! Just post your code and we can help. I won't post a code straight ahead...
     
  3. Offline

    MCCoding

    phips99
    Sorry typo is was the sleep effect when you wake up, fade here is my code.


    Code:java
    1. @EventHandler
    2. public void BlockSet(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4.  
    5. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. if(event.getClickedBlock().getType() == Material.WOOD_STAIRS ||
    7. event.getClickedBlock().getType() == Material.COBBLESTONE_STAIRS) {
    8.  
    9. EntityPlayer ep = ((CraftPlayer)event.getPlayer()).getHandle();
    10. Packet18ArmAnimation arm = new Packet18ArmAnimation(ep, 3);
    11.  
    12. for (Player p : plugin.getServer().getOnlinePlayers()) {
    13. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(arm);
    14. }
    15. }
    16. }
    17. }
     
  4. Offline

    phips99

    MCCoding First of all dom't use params in a packet! Remove them. Instead you can use this method to set the entity:
    Code:java
    1. packet.a = player.getEntityId()
    Then you have to set the animation id. You can lookup all the id's at this website: Protocol . You can set the animation id with this method:
    Code:java
    1. packet.b = id;

    Then you can send the packet!
     
  5. Offline

    MCCoding

    phips99
    Okay i'm new with using packets this is my first time doing it all, i don't understand on what i need to change i know how to change the animation id i don't understand on what u ment by
     
  6. Offline

    phips99

    MCCoding OK: To create a packet you'll have to set a few parameters! I don't like to set them in this format (I think this way is confusing...):
    Code:java
    1. Packet18ArmAnimation packet = new Packet18ArmAnimation(Entity, animationid))
    I like to set every single paramteter! To set them I have to acces them over the
    Code:java
    1. packet.a
    2. //or
    3. packet.b

    methods. The packet.a method defines the entity id (it grabs the entity by its id). The packet.b method defines the animation id. Every single animation has an id which you can find at the website which I gave you the link. To send the crouch animation you have to use the animation id 104 (see on the website). Then you have to send the packet, which you have done right.
     
  7. Offline

    MCCoding

    phips99
    Okay i have sent them packet 104 but its not making them sit down.
     
  8. Offline

    phips99

    MCCoding Oops I'm sorry! We are using the wrong packet... I'll send you the new code as soon as possible!
     
  9. Offline

    MCCoding

    phips99
    Haha okay that's fine its good practice, Thanks for the help.
     
  10. Offline

    phips99

    MCCoding Found it! You can make the player like he is sitting! The concept is: spawn an invisible horse attach the player! I'm using ProtocoLib to send packets, and I also use PacketWrapper to modify packets, so you will need the librarys to make this happen!
    Code:java
    1. Packet27AttachEntity packet = new Packet27AttachEntity();
    2. Packet18SpawnMob packets = new Packet18SpawnMob();
    3. WrappedDataWatcher watcher = new WrappedDataWatcher();
    4. int idofhorse = 12345; //Just a random number! Has to be unique
    5. watcher.setObject(0, (byte) 0x20); //Makes the horse invisible
    6. packet.setEntityId(p.getEntityId());
    7. packets.setEntityID(idofhorse);
    8. packets.setType(EntityType.HORSE);
    9. //The Location! You can modify them as you want! Just the -1 on the y axis has to stay...
    10. packets.setX(p.getLocation().getX());
    11. packets.setY(p.getLocation().getY() - 1);
    12. packets.setZ(p.getLocation().getZ());
    13. packet.setVehicleId(idofhorse);
    14. packets.setMetadata(watcher);
    15. try {
    16. manager.sendServerPacket(p, packets.getHandle());
    17. manager.sendServerPacket(p, packet.getHandle());
    18. e.printStackTrace();
    19. }
     
  11. Offline

    metalhedd

    I'm gonna have to ask why. I dont see any problem with passing in the args via constructor as opposed to directly setting the properties as you've done.
     
  12. Offline

    MCCoding

    phips99
    i'm getting some errors on Packet18SpawnMob, WrappedDataWatcher, setEntityId, setVehicleId, manager.
    With the Packet18SpawnMob and WrappedDataWatcher they are wanting me to create new class files.
     
  13. Offline

    phips99

    It's just my thing to do this... There is no sense ;)

    As I said you need to implement the ProtocolLib.jar and the PacketaWrapper.jar... Search for them

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  14. Offline

    MCCoding

    phips99
    Oh I thought I had them installed, also is it possible to do with out libraries? Don't really want to use them.
     
  15. Offline

    foodyling

    Then don't tell people to not use parameters in a constructor if it's just a specific style in which you code..
     
    metalhedd likes this.
  16. Offline

    metalhedd


    yes, and at the very least, it should be prefixed with: "I don't have an answer to your question, or any relevant information, BUT, with regards to your code here, I have a totally unrelated suggestion..."

    Otherwise you lead people to believe that the totally unrelated stuff you're talking about might actually solve their problem, and they waste a bunch of time and cause a bunch of confusion in the thread, making it difficult for anyone else to step in and help...

    so please, for the love of all that's holy... don't reply to a thread unless you have an actual answer that you're relatively confident in, or can help lead the person to something relevant. (ie. link to docs, other relevant discussion, etc). it ONLY causes problems to do otherwise, no matter how good your intentions are.
     
  17. Offline

    MCCoding

  18. Offline

    phips99

    metalhedd foodyling I found a sense! I didn't know that before because I was a bit inactive but I remebered that I shouldn't use the parameters! Explanation: As example I take the Packet24MobSpawn! You would have to set an EntityLiving as parameter! You would have to create one. I tried creating it with a constructor, but you would have to create a whole class thats extending a EntityLiving... Soo much work. You'll have to set all these new parameters to the EntityLiving. Instead of creating a new EntityLiving I can easily set the packets fields to that what I want...
     
  19. Offline

    MCCoding

    phips99
    Okay, but how would i make a player sit with out using libs?
     
  20. Offline

    foodyling

    You don't extend it, you spawn one and use that as a parameter, you'd run into the same problem with just setting the variables yourself.
     
  21. Offline

    mattrick

    MCCoding
    Before this turns into a flame war, I don't believe there is a way. The best way I have been taught is through ProtocolLib. Hopefully Bukkit will implement it in a later release though.
     
  22. Offline

    MCCoding

    mattrick16

    this is what phips99 gave me using Packwarpper and ProtocolLib but i'm getting this error

    code:

    Code:java
    1. public void sitPlayer(Player p){
    2. Packet27AttachEntity packet = new Packet27AttachEntity();
    3. Packet18SpawnMob packets = new Packet18SpawnMob();
    4. WrappedDataWatcher watcher = new WrappedDataWatcher();
    5. watcher.setObject(0, (byte) 0x20);
    6. packet.setEntityId(p.getEntityId());
    7. packets.setEntityID(12345);
    8. packets.setType(EntityType.HORSE);
    9. packets.setX(p.getLocation().getX());
    10. packets.setY(p.getLocation().getY() - 1);
    11. packets.setZ(p.getLocation().getZ());
    12. packet.setVehicleId(12345);
    13. packets.setMetadata(watcher);
    14. try {
    15. ProtocolLibrary.getProtocolManager().sendServerPacket(p, packets.getHandle());
    16. ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet.getHandle());
    17. e.printStackTrace();
    18. }


    Error:

    Code:
      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:192)
        at net.minecraft.server.v1_6_R2.PlayerInteractManager.interact(PlayerInteractManager.java:373)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:628)
        at net.minecraft.server.v1_6_R2.Packet15Place.handle(SourceFile:58)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.NoClassDefFoundError: com/comphenix/packetwrapper/Packet27AttachEntity
        at Special.Sitting.sitPlayer(Sitting.java:22)
        at Special.Sitting.onSit(Sitting.java:51)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 16 more
    Caused by: java.lang.ClassNotFoundException: com.comphenix.packetwrapper.Packet27AttachEntity
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 23 more
     
  23. Offline

    phips99

    Because you will have to download the three classes and put them into your project setup. I sent you the 3 files to download...
     
Thread Status:
Not open for further replies.

Share This Page