diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-08-06 07:22:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-06 02:22:19 -0500 |
| commit | 5a9fca0ca9cdb46f4b866781f219756c89e2293a (patch) | |
| tree | b006e28b91a181734fb9702bb6ec510f5b2af3df /azalea-client/src/movement.rs | |
| parent | 1d48c3fe34edd4e2295f54bd3d79f81f58c38a8e (diff) | |
| download | azalea-drasl-5a9fca0ca9cdb46f4b866781f219756c89e2293a.tar.xz | |
Better errors (#14)
* make reading use thiserror
* finish implementing all the error things
* clippy warnings related to ok_or
* fix some errors in other places
* thiserror in more places
* don't use closures in a couple places
* errors in writing packet
* rip backtraces
* change some BufReadError::Custom to UnexpectedEnumVariant
* Errors say what packet is bad
* error on leftover data and fix
it wasn't reading the properties for gameprofile
Diffstat (limited to 'azalea-client/src/movement.rs')
| -rw-r--r-- | azalea-client/src/movement.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs index 4f99984f..bc48e1b2 100644 --- a/azalea-client/src/movement.rs +++ b/azalea-client/src/movement.rs @@ -1,10 +1,20 @@ use crate::Client; use azalea_core::EntityPos; use azalea_protocol::packets::game::serverbound_move_player_packet_pos_rot::ServerboundMovePlayerPacketPosRot; +use azalea_world::MoveEntityError; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum MovePlayerError { + #[error("Player is not in world")] + PlayerNotInWorld, + #[error("{0}")] + Io(#[from] std::io::Error), +} impl Client { /// Set the client's position to the given coordinates. - pub async fn move_to(&mut self, new_pos: EntityPos) -> Result<(), String> { + pub async fn move_to(&mut self, new_pos: EntityPos) -> Result<(), MovePlayerError> { { let mut dimension_lock = self.dimension.lock().unwrap(); let dimension = dimension_lock.as_mut().unwrap(); @@ -14,10 +24,15 @@ impl Client { let player_id = if let Some(player_lock) = player_lock.entity(dimension) { player_lock.id } else { - return Err("Player entity not found".to_string()); + return Err(MovePlayerError::PlayerNotInWorld); }; - dimension.move_entity(player_id, new_pos)?; + match dimension.move_entity(player_id, new_pos) { + Ok(_) => Ok(()), + Err(e) => match e { + MoveEntityError::EntityDoesNotExist => Err(MovePlayerError::PlayerNotInWorld), + }, + }?; } self.conn @@ -34,7 +49,7 @@ impl Client { } .get(), ) - .await; + .await?; Ok(()) } |
