1.15.2 Yet another set player to sleep without bed

Discussion in 'Spigot Plugin Development' started by Stellrow, Mar 25, 2020.

  1. Anyone got a clue about it,i just started digging through packets trying to make a player sleep without a bad

    So far i tried this(that actually do something)
    Code (Text):
    public void setToBed(Player p) {
         
            EntityPlayer entityPlayer = ((CraftPlayer)p).getHandle();
            entityPlayer.setPosition(p.getLocation().getX(), p.getLocation().getY()-0.5, p.getLocation().getZ());
         
         
            PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawn(entityPlayer);

            entityPlayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer));
            entityPlayer.playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);

            Vec3D pos = new Vec3D(p.getLocation().getX(),p.getLocation().getY(),p.getLocation().getZ());
            entityPlayer.e(pos);

            entityPlayer.playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityPlayer.getId(), entityPlayer.getDataWatcher(), false));
            DataWatcher watcher = entityPlayer.getDataWatcher();
         
         
            entityPlayer.playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityPlayer.getId(), watcher, false));
        }
    The only problem it seems to only teleport me to that position,and nothing more

    Also noticed that the method .e everybody talked about it's now requiring a Vec3D instead of BlockPosition
     
  2. dunno about later versions, but in older versions, for a client to recognize a player as sleeping, there has to be a bed there when the "go to sleep" packet is sent. how it was done is spawn a client side bed at the bottom of the world. sleep the player there, then teleport the player to the correct location. think u need to keep the bed there or the client forces the player to wake up on their perspective