pub fn save_player_data(
    config: &Config,
    position: Position,
    gamemode: Gamemode,
    inventory: &Inventory,
    uuid: Uuid,
) -> Receiver<()> {
    let data = PlayerData {
        entity: BaseEntityData {
            velocity: vec![0.0; 3], // Player velocity has no effect
            position: vec![position.x, position.y, position.z],
            rotation: vec![position.yaw, position.pitch],
        },
        gamemode: gamemode.get_id() as i32,
        inventory: inventory
            .items()
            .iter()
            .enumerate()
            .filter_map(|(index, item)| match item.clone() {
                Some(item) => Some((index, item)),
                None => None,
            })
            .map(|(index, item)| InventorySlot::from_network_index(index, item))
            .collect(),
    };

    // Channel used to communicate with Tokio task
    let (tx, rx) = crossbeam::bounded(1);

    let world_dir = Path::new(&config.world.name).to_owned();

    tokio_executor::blocking::run(move || {
        if let Err(e) = player_data::save_player_data(world_dir.as_path(), uuid, data) {
            error!("Failed to save player data for UUID {}: {:?}", uuid, e);
        } else {
            debug!("Saved player data for UUID {}", uuid);
        }

        let _ = tx.send(()); // Channel could have been dropped, so ignore result
    });

    rx
}
/// Saves a player's data.
///
/// This operation is performed asynchronously,
/// and a channel is returned which will receive
/// a message upon completion.
Saves a player's data.
This operation is performed asynchronously,
and a channel is returned which will receive
a message upon completion.
Saves a player ' s data . This operation is performed asynchronously and a channel is returned which will receive a message upon completion .
pub fn save_player_data(
    config: &Config,
    position: Position,
    gamemode: Gamemode,
    inventory: &Inventory,
    uuid: Uuid,
) -> Receiver<()> {
    let data = PlayerData {
        entity: BaseEntityData {
            velocity: vec![0.0; 3], // Player velocity has no effect
            position: vec![position.x, position.y, position.z],
            rotation: vec![position.yaw, position.pitch],
        },
        gamemode: gamemode.get_id() as i32,
        inventory: inventory
            .items()
            .iter()
            .enumerate()
            .filter_map(|(index, item)| match item.clone() {
                Some(item) => Some((index, item)),
                None => None,
            })
            .map(|(index, item)| InventorySlot::from_network_index(index, item))
            .collect(),
    };
    // Channel used to communicate with Tokio task
    let (tx, rx) = crossbeam::bounded(1);
    let world_dir = Path::new(&config.world.name).to_owned();
    tokio_executor::blocking::run(move || {
        if let Err(e) = player_data::save_player_data(world_dir.as_path(), uuid, data) {
            error!("Failed to save player data for UUID {}: {:?}", uuid, e);
        } else {
            debug!("Saved player data for UUID {}", uuid);
        }
        let _ = tx.send(()); // Channel could have been dropped, so ignore result
    });
    rx
}
pub fn save_player_data ( config : & Config , position : Position , gamemode : Gamemode , inventory : & Inventory , uuid : Uuid , ) -> Receiver < ( ) > { let data = PlayerData { entity : BaseEntityData { velocity : vec ! [ 0.0 3 ] , // Player velocity has no effect position : vec ! [ position x position y position z ] , rotation : vec ! [ position yaw position pitch ] , } , gamemode : gamemode . get_id ( ) as i32 , inventory : inventory . items ( ) . iter ( ) . enumerate ( ) . filter_map ( | ( index , item ) | match item . clone ( ) { Some ( item ) => Some ( ( index , item ) ) , None => None , } ) . map ( | ( index , item ) | InventorySlot :: from_network_index ( index , item ) ) . collect ( ) , } ; // Channel used to communicate with Tokio task let ( tx , rx ) = crossbeam :: bounded ( 1 ) ; let world_dir = Path :: new ( & config . world . name ) . to_owned ( ) ; tokio_executor :: blocking :: run ( move | | { if let Err ( e ) = player_data :: save_player_data ( world_dir . as_path ( ) , uuid , data ) { error ! ( " " uuid e ) ; } else { debug ! ( " " uuid ) ; } let _ = tx . send ( ( ) ) ; // Channel could have been dropped, so ignore result } ) ; rx }
Saves a player's data.
Saves a player ' s data .
config
&Config
position
Position
gamemode
Gamemode
inventory
&Inventory
uuid
Uuid
config
&Config
position
Position
gamemode
Gamemode
inventory
&Inventory
uuid
Uuid