From 3d789f745018869ac60f6804ecbf69ce1dabc977 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Wed, 5 Feb 2025 23:12:16 +0100 Subject: [PATCH] Some Renames --- CONTRIBUTING.md | 2 +- Cargo.toml | 4 +-- pumpkin-config/src/networking/compression.rs | 4 +-- pumpkin-config/src/networking/rcon.rs | 16 +++++----- pumpkin-config/src/resource_pack.rs | 12 +++---- pumpkin-protocol/src/bytebuf/mod.rs | 10 +++--- pumpkin-protocol/src/client/play/take_item.rs | 2 +- .../src/client/status/ping_response.rs | 2 +- pumpkin-protocol/src/codec/identifier.rs | 10 +++--- pumpkin-protocol/src/packet_decoder.rs | 6 ++-- .../src/server/config/cookie_response.rs | 2 +- .../src/server/config/plugin_message.rs | 2 +- .../src/server/login/cookie_response.rs | 2 +- .../src/server/play/cookie_response.rs | 2 +- pumpkin/src/{net => entity}/combat.rs | 0 pumpkin/src/entity/mod.rs | 2 ++ pumpkin/src/entity/player.rs | 11 ++++--- pumpkin/src/net/mod.rs | 1 - pumpkin/src/net/packet/login.rs | 19 ++++------- pumpkin/src/net/packet/play.rs | 16 +++++----- pumpkin/src/net/rcon/mod.rs | 6 ++-- .../src/world/{worldborder.rs => border.rs} | 0 .../world/{player_chunker.rs => chunker.rs} | 0 pumpkin/src/world/mod.rs | 32 ++++++++++++------- pumpkin/src/world/{level_time.rs => time.rs} | 0 pumpkin/world/session.lock | 1 + 26 files changed, 85 insertions(+), 79 deletions(-) rename pumpkin/src/{net => entity}/combat.rs (100%) rename pumpkin/src/world/{worldborder.rs => border.rs} (100%) rename pumpkin/src/world/{player_chunker.rs => chunker.rs} (100%) rename pumpkin/src/world/{level_time.rs => time.rs} (100%) create mode 100644 pumpkin/world/session.lock diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e172bb077..a8c3078f5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ The Documentation of Pumpkin can be found at ### Coding Guidelines Things need to be done before this Pull Request can be merged. Your CI also checks most of them automatically and fill fail if something is not fulfilled -Note: Pumpkin's clippy settings are relatively strict, this can be may frustrating but is necessary so the code says clean and conssistent +Note: Pumpkin's clippy settings are relatively strict, this can be may frustrating but is necessary so the code says clean and consistent **Basic** - **Title:** Use a concise and informative title that clearly communicates the purpose of the PR. Anyone reviewing the PR should quickly understand the changes being proposed. diff --git a/Cargo.toml b/Cargo.toml index f0fc8408e..5ab1ad907 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,8 +50,8 @@ rayon = "1.10" parking_lot = { version = "0.12", features = ["send_guard"] } crossbeam = "0.8" -uuid = { version = "1.12", features = ["serde", "v3", "v4"] } -derive_more = { version = "1.0", features = ["full"] } +uuid = { version = "1.13", features = ["serde", "v3", "v4"] } +derive_more = { version = "2.0", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/pumpkin-config/src/networking/compression.rs b/pumpkin-config/src/networking/compression.rs index a07c4959b..703261f35 100644 --- a/pumpkin-config/src/networking/compression.rs +++ b/pumpkin-config/src/networking/compression.rs @@ -7,14 +7,14 @@ pub struct CompressionConfig { /// Whether compression is enabled pub enabled: bool, #[serde(flatten)] - pub compression_info: CompressionInfo, + pub info: CompressionInfo, } impl Default for CompressionConfig { fn default() -> Self { Self { enabled: true, - compression_info: Default::default(), + info: Default::default(), } } } diff --git a/pumpkin-config/src/networking/rcon.rs b/pumpkin-config/src/networking/rcon.rs index 89f57fbb6..ffe97bea9 100644 --- a/pumpkin-config/src/networking/rcon.rs +++ b/pumpkin-config/src/networking/rcon.rs @@ -33,22 +33,22 @@ impl Default for RCONConfig { #[serde(default)] pub struct RCONLogging { /// Whether successful RCON logins should be logged. - pub log_logged_successfully: bool, + pub logged_successfully: bool, /// Whether failed RCON login attempts with incorrect passwords should be logged. - pub log_wrong_password: bool, + pub wrong_password: bool, /// Whether all RCON commands, regardless of success or failure, should be logged. - pub log_commands: bool, + pub commands: bool, /// Whether RCON quit commands should be logged. - pub log_quit: bool, + pub quit: bool, } impl Default for RCONLogging { fn default() -> Self { Self { - log_logged_successfully: true, - log_wrong_password: true, - log_commands: true, - log_quit: true, + logged_successfully: true, + wrong_password: true, + commands: true, + quit: true, } } } diff --git a/pumpkin-config/src/resource_pack.rs b/pumpkin-config/src/resource_pack.rs index 3936f8320..1f011de70 100644 --- a/pumpkin-config/src/resource_pack.rs +++ b/pumpkin-config/src/resource_pack.rs @@ -5,11 +5,11 @@ use serde::{Deserialize, Serialize}; pub struct ResourcePackConfig { pub enabled: bool, /// The path to the resource pack. - pub resource_pack_url: String, + pub url: String, /// The SHA1 hash (40) of the resource pack. - pub resource_pack_sha1: String, + pub sha1: String, /// Custom prompt Text component, Leave blank for none - pub prompt_message: String, + pub message: String, /// Will force the Player to accept the resource pack pub force: bool, } @@ -17,12 +17,12 @@ pub struct ResourcePackConfig { impl ResourcePackConfig { pub fn validate(&self) { assert_eq!( - !self.resource_pack_url.is_empty(), - !self.resource_pack_sha1.is_empty(), + !self.url.is_empty(), + !self.sha1.is_empty(), "Resource Pack path or Sha1 hash is missing" ); assert!( - self.resource_pack_sha1.len() <= 40, + self.sha1.len() <= 40, "Resource pack sha1 hash is too long (max. 40)" ) } diff --git a/pumpkin-protocol/src/bytebuf/mod.rs b/pumpkin-protocol/src/bytebuf/mod.rs index 259c8db5f..7305ed389 100644 --- a/pumpkin-protocol/src/bytebuf/mod.rs +++ b/pumpkin-protocol/src/bytebuf/mod.rs @@ -48,7 +48,7 @@ pub trait ByteBuf: Buf { fn try_get_var_long(&mut self) -> Result; - fn try_get_identifer(&mut self) -> Result; + fn try_get_identifier(&mut self) -> Result; fn try_get_string(&mut self) -> Result; @@ -170,12 +170,12 @@ impl ByteBuf for T { self.try_copy_to_bytes(bits.div_ceil(8)) } - fn try_get_identifer(&mut self) -> Result { + fn try_get_identifier(&mut self) -> Result { match Identifier::decode(self) { - Ok(identifer) => Ok(identifer), + Ok(identifier) => Ok(identifier), Err(error) => match error { - DecodeError::Incomplete => Err(ReadingError::Incomplete("identifer".to_string())), - DecodeError::TooLarge => Err(ReadingError::TooLarge("identifer".to_string())), + DecodeError::Incomplete => Err(ReadingError::Incomplete("identifier".to_string())), + DecodeError::TooLarge => Err(ReadingError::TooLarge("identifier".to_string())), }, } } diff --git a/pumpkin-protocol/src/client/play/take_item.rs b/pumpkin-protocol/src/client/play/take_item.rs index b21497df4..4366a7684 100644 --- a/pumpkin-protocol/src/client/play/take_item.rs +++ b/pumpkin-protocol/src/client/play/take_item.rs @@ -8,7 +8,7 @@ use serde::Serialize; pub struct CTakeItemEntity { /// The Entity ID of the Item Entity entity_id: VarInt, - /// The Entity ID of the Entitiy who is collecting the Item + /// The Entity ID of the Entity who is collecting the Item collector_entity_id: VarInt, /// The Number of items in the Stack stack_amount: VarInt, diff --git a/pumpkin-protocol/src/client/status/ping_response.rs b/pumpkin-protocol/src/client/status/ping_response.rs index c2fc67f14..1929a168d 100644 --- a/pumpkin-protocol/src/client/status/ping_response.rs +++ b/pumpkin-protocol/src/client/status/ping_response.rs @@ -5,7 +5,7 @@ use serde::Serialize; #[derive(Serialize)] #[client_packet(STATUS_PONG_RESPONSE)] pub struct CPingResponse { - payload: i64, // must responde with the same as in `SPingRequest` + payload: i64, // must respond with the same as in `SPingRequest` } impl CPingResponse { diff --git a/pumpkin-protocol/src/codec/identifier.rs b/pumpkin-protocol/src/codec/identifier.rs index 6be5675c7..0c8fb4b58 100644 --- a/pumpkin-protocol/src/codec/identifier.rs +++ b/pumpkin-protocol/src/codec/identifier.rs @@ -22,7 +22,7 @@ impl Identifier { } } impl Codec for Identifier { - /// The maximum number of bytes a `Identifer` is the same as for a normal String. + /// The maximum number of bytes a `Identifier` is the same as for a normal String. const MAX_SIZE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(i16::MAX as usize) }; fn written_size(&self) -> usize { @@ -34,10 +34,10 @@ impl Codec for Identifier { } fn decode(read: &mut impl Buf) -> Result { - let identifer = read + let identifier = read .try_get_string_len(Self::MAX_SIZE.get()) .map_err(|_| DecodeError::Incomplete)?; - match identifer.split_once(":") { + match identifier.split_once(":") { Some((namespace, path)) => Ok(Identifier { namespace: namespace.to_string(), path: path.to_string(), @@ -77,11 +77,11 @@ impl<'de> Deserialize<'de> for Identifier { self.visit_str(&v) } - fn visit_str(self, identifer: &str) -> Result + fn visit_str(self, identifier: &str) -> Result where E: serde::de::Error, { - match identifer.split_once(":") { + match identifier.split_once(":") { Some((namespace, path)) => Ok(Identifier { namespace: namespace.to_string(), path: path.to_string(), diff --git a/pumpkin-protocol/src/packet_decoder.rs b/pumpkin-protocol/src/packet_decoder.rs index 43beb6ada..0f98e3c14 100644 --- a/pumpkin-protocol/src/packet_decoder.rs +++ b/pumpkin-protocol/src/packet_decoder.rs @@ -10,9 +10,9 @@ use crate::{ type Cipher = cfb8::Decryptor; -// Decoder: Client -> Server -// Supports ZLib decoding/decompression -// Supports Aes128 Encryption +/// Decoder: Client -> Server +/// Supports ZLib decoding/decompression +/// Supports Aes128 Encryption #[derive(Default)] pub struct PacketDecoder { buf: BytesMut, diff --git a/pumpkin-protocol/src/server/config/cookie_response.rs b/pumpkin-protocol/src/server/config/cookie_response.rs index dfad993f0..3e1f874ea 100644 --- a/pumpkin-protocol/src/server/config/cookie_response.rs +++ b/pumpkin-protocol/src/server/config/cookie_response.rs @@ -22,7 +22,7 @@ const MAX_COOKIE_LENGTH: usize = 5120; impl ServerPacket for SConfigCookieResponse { fn read(bytebuf: &mut impl Buf) -> Result { - let key = bytebuf.try_get_identifer()?; + let key = bytebuf.try_get_identifier()?; let has_payload = bytebuf.try_get_bool()?; if !has_payload { diff --git a/pumpkin-protocol/src/server/config/plugin_message.rs b/pumpkin-protocol/src/server/config/plugin_message.rs index 018a3b7c9..9aa53ccf9 100644 --- a/pumpkin-protocol/src/server/config/plugin_message.rs +++ b/pumpkin-protocol/src/server/config/plugin_message.rs @@ -18,7 +18,7 @@ pub struct SPluginMessage { impl ServerPacket for SPluginMessage { fn read(bytebuf: &mut impl Buf) -> Result { Ok(Self { - channel: bytebuf.try_get_identifer()?, + channel: bytebuf.try_get_identifier()?, data: bytebuf.try_copy_to_bytes_len(bytebuf.remaining(), MAX_PAYLOAD_SIZE)?, }) } diff --git a/pumpkin-protocol/src/server/login/cookie_response.rs b/pumpkin-protocol/src/server/login/cookie_response.rs index a111300b6..1d248b10b 100644 --- a/pumpkin-protocol/src/server/login/cookie_response.rs +++ b/pumpkin-protocol/src/server/login/cookie_response.rs @@ -21,7 +21,7 @@ const MAX_COOKIE_LENGTH: usize = 5120; impl ServerPacket for SLoginCookieResponse { fn read(bytebuf: &mut impl Buf) -> Result { - let key = bytebuf.try_get_identifer()?; + let key = bytebuf.try_get_identifier()?; let has_payload = bytebuf.try_get_bool()?; if !has_payload { diff --git a/pumpkin-protocol/src/server/play/cookie_response.rs b/pumpkin-protocol/src/server/play/cookie_response.rs index 0aa23eba7..fa26163a2 100644 --- a/pumpkin-protocol/src/server/play/cookie_response.rs +++ b/pumpkin-protocol/src/server/play/cookie_response.rs @@ -21,7 +21,7 @@ const MAX_COOKIE_LENGTH: usize = 5120; impl ServerPacket for SCookieResponse { fn read(bytebuf: &mut impl Buf) -> Result { - let key = bytebuf.try_get_identifer()?; + let key = bytebuf.try_get_identifier()?; let has_payload = bytebuf.try_get_bool()?; if !has_payload { diff --git a/pumpkin/src/net/combat.rs b/pumpkin/src/entity/combat.rs similarity index 100% rename from pumpkin/src/net/combat.rs rename to pumpkin/src/entity/combat.rs diff --git a/pumpkin/src/entity/mod.rs b/pumpkin/src/entity/mod.rs index 768f29d0d..2069ae6ce 100644 --- a/pumpkin/src/entity/mod.rs +++ b/pumpkin/src/entity/mod.rs @@ -40,6 +40,8 @@ pub mod mob; pub mod player; pub mod projectile; +mod combat; + pub type EntityId = i32; #[async_trait] diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 98703de40..2df1da321 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -66,14 +66,15 @@ use pumpkin_world::{ }; use tokio::sync::{Mutex, Notify, RwLock}; -use super::{item::ItemEntity, Entity, EntityId, NBTStorage}; +use super::{ + combat::{self, player_attack_sound, AttackType}, + item::ItemEntity, + Entity, EntityId, NBTStorage, +}; use crate::{ command::{client_suggestions, dispatcher::CommandDispatcher}, data::op_data::OPERATOR_CONFIG, - net::{ - combat::{self, player_attack_sound, AttackType}, - Client, PlayerConfig, - }, + net::{Client, PlayerConfig}, server::Server, world::World, }; diff --git a/pumpkin/src/net/mod.rs b/pumpkin/src/net/mod.rs index e8ff86f82..3bb254ac2 100644 --- a/pumpkin/src/net/mod.rs +++ b/pumpkin/src/net/mod.rs @@ -46,7 +46,6 @@ use tokio::sync::Mutex; use thiserror::Error; use uuid::Uuid; mod authentication; -pub mod combat; mod container; pub mod lan_broadcast; mod packet; diff --git a/pumpkin/src/net/packet/login.rs b/pumpkin/src/net/packet/login.rs index b33d10045..8fb222323 100644 --- a/pumpkin/src/net/packet/login.rs +++ b/pumpkin/src/net/packet/login.rs @@ -233,11 +233,7 @@ impl Client { } async fn enable_compression(&self) { - let compression = ADVANCED_CONFIG - .networking - .packet_compression - .compression_info - .clone(); + let compression = ADVANCED_CONFIG.networking.packet_compression.info.clone(); self.send_packet(&CSetCompression::new(compression.threshold.into())) .await; self.set_compression(Some(compression)).await; @@ -334,17 +330,14 @@ impl Client { let resource_config = &ADVANCED_CONFIG.resource_pack; if resource_config.enabled { let resource_pack = CConfigAddResourcePack::new( - Uuid::new_v3( - &uuid::Uuid::NAMESPACE_DNS, - resource_config.resource_pack_url.as_bytes(), - ), - &resource_config.resource_pack_url, - &resource_config.resource_pack_sha1, + Uuid::new_v3(&uuid::Uuid::NAMESPACE_DNS, resource_config.url.as_bytes()), + &resource_config.url, + &resource_config.sha1, resource_config.force, - if resource_config.prompt_message.is_empty() { + if resource_config.message.is_empty() { None } else { - Some(TextComponent::text(&resource_config.prompt_message)) + Some(TextComponent::text(&resource_config.message)) }, ); diff --git a/pumpkin/src/net/packet/play.rs b/pumpkin/src/net/packet/play.rs index 8206f9a66..1e174d5bb 100644 --- a/pumpkin/src/net/packet/play.rs +++ b/pumpkin/src/net/packet/play.rs @@ -10,7 +10,7 @@ use crate::{ entity::player::{ChatMode, Hand, Player}, error::PumpkinError, server::Server, - world::player_chunker, + world::chunker, }; use pumpkin_config::ADVANCED_CONFIG; use pumpkin_data::entity::{EntityPose, EntityType}; @@ -204,7 +204,7 @@ impl Player { ) .await; } - player_chunker::update_position(self).await; + chunker::update_position(self).await; } pub async fn handle_position_rotation(self: &Arc, packet: SPlayerPositionRotation) { @@ -296,7 +296,7 @@ impl Player { ) .await; } - player_chunker::update_position(self).await; + chunker::update_position(self).await; } pub async fn handle_rotation(&self, rotation: SPlayerRotation) { @@ -614,9 +614,9 @@ impl Player { return; } - let (update_skin, update_watched) = { + let (update_settings, update_watched) = { let mut config = self.config.lock().await; - let update_skin = config.main_hand != main_hand + let update_settings = config.main_hand != main_hand || config.skin_parts != client_information.skin_parts; let old_view_distance = config.view_distance; @@ -649,14 +649,14 @@ impl Player { text_filtering: client_information.text_filtering, server_listing: client_information.server_listing, }; - (update_skin, update_watched) + (update_settings, update_watched) }; if update_watched { - player_chunker::update_position(self).await; + chunker::update_position(self).await; } - if update_skin { + if update_settings { log::debug!( "Player {} ({}) updated their skin.", self.gameprofile.name, diff --git a/pumpkin/src/net/rcon/mod.rs b/pumpkin/src/net/rcon/mod.rs index 0380899de..a4f806216 100644 --- a/pumpkin/src/net/rcon/mod.rs +++ b/pumpkin/src/net/rcon/mod.rs @@ -89,12 +89,12 @@ impl RCONClient { if packet.get_body() == password { self.send(ClientboundPacket::AuthResponse, packet.get_id(), "") .await?; - if config.logging.log_logged_successfully { + if config.logging.logged_successfully { log::info!("RCON ({}): Client logged in successfully", self.address); } self.logged_in = true; } else { - if config.logging.log_wrong_password { + if config.logging.wrong_password { log::info!("RCON ({}): Client has tried wrong password", self.address); } self.send(ClientboundPacket::AuthResponse, -1, "").await?; @@ -121,7 +121,7 @@ impl RCONClient { let output = output.lock().await; for line in output.iter() { - if config.logging.log_commands { + if config.logging.commands { log::info!("RCON ({}): {}", self.address, line); } self.send(ClientboundPacket::Output, packet.get_id(), line) diff --git a/pumpkin/src/world/worldborder.rs b/pumpkin/src/world/border.rs similarity index 100% rename from pumpkin/src/world/worldborder.rs rename to pumpkin/src/world/border.rs diff --git a/pumpkin/src/world/player_chunker.rs b/pumpkin/src/world/chunker.rs similarity index 100% rename from pumpkin/src/world/player_chunker.rs rename to pumpkin/src/world/chunker.rs diff --git a/pumpkin/src/world/mod.rs b/pumpkin/src/world/mod.rs index d0c63e2c8..815e3beb9 100644 --- a/pumpkin/src/world/mod.rs +++ b/pumpkin/src/world/mod.rs @@ -3,8 +3,8 @@ use std::{ sync::{atomic::Ordering, Arc}, }; -pub mod level_time; -pub mod player_chunker; +pub mod chunker; +pub mod time; use crate::{ command::client_suggestions, @@ -18,7 +18,7 @@ use crate::{ server::Server, PLUGIN_MANAGER, }; -use level_time::LevelTime; +use border::Worldborder; use pumpkin_config::BasicConfiguration; use pumpkin_data::{ entity::EntityType, @@ -50,18 +50,18 @@ use pumpkin_world::{ use rand::{thread_rng, Rng}; use scoreboard::Scoreboard; use thiserror::Error; +use time::LevelTime; use tokio::sync::{mpsc::Receiver, Mutex}; use tokio::{ runtime::Handle, sync::{mpsc, RwLock}, }; -use worldborder::Worldborder; +pub mod border; pub mod bossbar; pub mod custom_bossbar; pub mod scoreboard; pub mod weather; -pub mod worldborder; use weather::Weather; @@ -223,13 +223,23 @@ impl World { } pub async fn play_record(&self, record_id: i32, position: BlockPos) { - self.broadcast_packet_all(&CLevelEvent::new(1010, position, record_id, false)) - .await; + self.broadcast_packet_all(&CLevelEvent::new( + WorldEvent::JukeboxStartsPlaying as i32, + position, + record_id, + false, + )) + .await; } pub async fn stop_record(&self, position: BlockPos) { - self.broadcast_packet_all(&CLevelEvent::new(1011, position, 0, false)) - .await; + self.broadcast_packet_all(&CLevelEvent::new( + WorldEvent::JukeboxStopsPlaying as i32, + position, + 0, + false, + )) + .await; } pub async fn tick(&self) { @@ -499,7 +509,7 @@ impl World { } // Spawn in initial chunks - player_chunker::player_join(&player).await; + chunker::player_join(&player).await; // if let Some(bossbars) = self..lock().await.get_player_bars(&player.gameprofile.id) { // for bossbar in bossbars { @@ -600,7 +610,7 @@ impl World { .await; player.send_client_information().await; - player_chunker::player_join(player).await; + chunker::player_join(player).await; // update commands player.set_health(20.0, 20, 20.0).await; diff --git a/pumpkin/src/world/level_time.rs b/pumpkin/src/world/time.rs similarity index 100% rename from pumpkin/src/world/level_time.rs rename to pumpkin/src/world/time.rs diff --git a/pumpkin/world/session.lock b/pumpkin/world/session.lock new file mode 100644 index 000000000..0d7e5f854 --- /dev/null +++ b/pumpkin/world/session.lock @@ -0,0 +1 @@ +☃ \ No newline at end of file