Making a player sit down

Discussion in 'Plugin Development' started by Alfalik, Oct 18, 2015.

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

    Alfalik

    Here's a video of what I want to do with the player:
    I've coded the following code, it just does not work

    Code:
    public void sendArmorStandPacket(Player player) {
            EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
            PacketPlayOutSpawnEntityLiving field = new PacketPlayOutSpawnEntityLiving();
    
            field.a = 30;
           
            int x = (int) player.getLocation().getX();
            int y = (int) player.getLocation().getY();
            int z = (int) player.getLocation().getZ();
            field.c = (x);
            field.d = (int) (y + 1.0);
            field.c = (z);
    
            sendArmorStandMetadata(field.l);
    
            PacketPlayOutAttachEntity sitPlayer = new PacketPlayOutAttachEntity(0, nmsPlayer, armorStandEntity);
    
            nmsPlayer.playerConnection.sendPacket(field);
            nmsPlayer.playerConnection.sendPacket(sitPlayer);
        }
    
        public DataWatcher sendArmorStandMetadata(DataWatcher dataWatcher) {
            DataWatcher metadata = new DataWatcher(armorStandEntity);
    
            metadata.a(0, (byte) 32); // Invisible = 0x20
            metadata.a(1, (short) 300);
            metadata.a(7, 0);
            metadata.a(8, (byte) 0);
            metadata.a(9, (byte) 0);
            metadata.a(6, 1.0F);
            metadata.a(10, (byte) 8); // NoGravity
            return metadata;
        }
    I want to spawn an armor stand and set the player as passenger. Hope somebody help me
     
  2. Offline

    mcdorli

    Why do you use nms for this? This can be done with player.setVehicle(Entity)
     
    mine-care likes this.
  3. Offline

    mine-care

    @mcdorli Exactly. usually such plugins that make players "sit" drop an item like an arrow or seeds or whatever and attach the player on it.
     
  4. Offline

    567legodude

    @Alfalik
    I can't do it for you, but I can give you these:
    Code:
    // Spawn stand
    World.spawn(Location, Class)
    // example
    player.getWorld().spawn(player.getLocation(), ArmorStand.class);
    
    // Make stand invisible
    // Then put player on stand
     
  5. Offline

    Alfalik

    The deal of NMS/packets is that others players can't see, in this case, the armor stand. I don't want other players to see the armor stand, that's why.

    I'm using packets to spawn the armor stand. I can't get to work the PacketPlayOutAttachEntity packet (the armor stand is spawning), wonder if you know and check my code, thanks in advance.

    Code:
    public void sendArmorStandPacket(Player player) {
            EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
            EntityArmorStand entityArmorStand = new EntityArmorStand(nmsPlayer.getWorld());
            PacketPlayOutSpawnEntityLiving armorStand = new PacketPlayOutSpawnEntityLiving();
    
            try {
                armorStand.b = (byte) 30;
                armorStand.c = (int) (player.getLocation().getBlockX() * 32.0D);
                armorStand.d = (int) (player.getLocation().getBlockY() * 32.0D);
                armorStand.e = (int) (player.getLocation().getBlockZ() * 32.0D);
                armorStand.f = (byte) (int) ((player.getLocation().getYaw() * 256F) / 360F);
                armorStand.g = (byte) (int) ((player.getLocation().getPitch() * 256F) / 360F);
    
                DataWatcher armorStandMetadata = new DataWatcher(entityArmorStand);
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            PacketPlayOutAttachEntity attachEntity = new PacketPlayOutAttachEntity(0, nmsPlayer, entityArmorStand);
    
            nmsPlayer.playerConnection.sendPacket(armorStand);
            nmsPlayer.playerConnection.sendPacket(attachEntity);
        }
     
  6. Offline

    Scimiguy

    @Alfalik
    If the server doesnt know the armour stand exists, how will it show other players that the player sitting on it is doing so?
     
  7. Offline

    Alfalik

    I don't want other players to know that the player is sitting, it'll be client-side
     
  8. Offline

    teej107

    It may be possible to send a packet that makes a player sit without an entity. I don't use packets that much but I think it'll be good to find out.
     
  9. Offline

    Scimiguy

  10. Offline

    teej107

  11. Offline

    xTrollxDudex

    Make the player sit on himself
     
  12. Offline

    Scimiguy

    @teej107
    So?
    Whats wrong with a spawned entity?

    That thread shows that you can make the entity invisible, or use a destroy entity packet

    If doing the latter, the other players dont even see them sitting


    Isnt that exactly what is wanted here?


    @xTrollxDudex
    Did you read any of the posts after the original one?
     
  13. Offline

    teej107

    Because you shouldn't need to spawn an entity so you can sit. That is why I think it is possible to do it without one.
     
  14. Offline

    Scimiguy

    @teej107
    There's plenty of things that you should be able to do.. doesn't mean Bukkit lets you do it.

    But I agree, there should be a way to do it, I just gave you that option given that it's the easiest && most stable
     
  15. Offline

    teej107

    I wouldn't call sending packets "Bukkit". Especially with sending packets, I don't think there is a "doesn't let you" or "lets you". There either "is" or there "isn't". And it is entirely possible that there isn't a packet to make a Player sit.
    EDIT: I can't find the thread that I also seen about this but why wouldn't making a Player sit on himself work? If that doesn't work, I found this: http://bukkit.org/threads/making-a-player-sit-down.111381/#post-1422347 it's outdated but if you find the current packet for it then it's a start and it might work if making a Player sit on himself doesn't work.
     
    Last edited: Oct 21, 2015
    boomboompower likes this.
  16. Offline

    Alfalik

    I just want a player sitting on a armor stand, don't care about others players.
    Sit the player on himself just glitch the camera and movements of the player.
    About the issue, the entity is being spawned (the armor stand), the PacketPlayOutAttachEntity is not working as it should. Nothing happens when I call the method, only the entity being spawned. What's wrong with my code?

    Code:
    public void sendArmorStandPacket(Player player) {
            EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
            EntityArmorStand entityArmorStand = new EntityArmorStand(nmsPlayer.getWorld());
            PacketPlayOutSpawnEntityLiving armorStand = new PacketPlayOutSpawnEntityLiving();
    
            try {
                armorStand.b = (byte) 30;
                armorStand.c = (int) (player.getLocation().getX() * 32.0D);
                armorStand.d = (int) (player.getLocation().getY() * 32.0D);
                armorStand.e = (int) (player.getLocation().getZ() * 32.0D);
                armorStand.f = (byte) (int) ((player.getLocation().getYaw() * 256F) / 360F);
                armorStand.g = (byte) (int) ((player.getLocation().getPitch() * 256F) / 360F);
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            PacketPlayOutAttachEntity attachEntity = new PacketPlayOutAttachEntity(0, nmsPlayer, entityArmorStand);
    
            nmsPlayer.playerConnection.sendPacket(armorStand);
            nmsPlayer.playerConnection.sendPacket(attachEntity);
        }
     
  17. Offline

    Alfalik

    bump. Still can't get the player sitting on the armor stand (the armor stand packet totally works)
     
Thread Status:
Not open for further replies.

Share This Page