mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-31 20:32:34 +00:00
New clipps lints
This commit is contained in:
@@ -40,7 +40,7 @@ impl Player {
|
||||
let window_title = container
|
||||
.as_ref()
|
||||
.map(|container| container.window_name())
|
||||
.unwrap_or(inventory.window_name());
|
||||
.unwrap_or_else(|| inventory.window_name());
|
||||
let title = TextComponent::text(window_title);
|
||||
|
||||
self.client.send_packet(&COpenScreen::new(
|
||||
@@ -64,13 +64,12 @@ impl Player {
|
||||
.map(Slot::from)
|
||||
.collect_vec();
|
||||
|
||||
let carried_item = {
|
||||
if let Some(item) = self.carried_item.load().as_ref() {
|
||||
item.into()
|
||||
} else {
|
||||
Slot::empty()
|
||||
}
|
||||
};
|
||||
let carried_item = self
|
||||
.carried_item
|
||||
.load()
|
||||
.as_ref()
|
||||
.map_or_else(Slot::empty, |item| item.into());
|
||||
|
||||
// Gets the previous value
|
||||
let i = inventory
|
||||
.state_id
|
||||
@@ -378,7 +377,7 @@ impl Player {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_current_players_in_container(&self, server: &Server) -> Vec<Arc<Player>> {
|
||||
async fn get_current_players_in_container(&self, server: &Server) -> Vec<Arc<Self>> {
|
||||
let player_ids = {
|
||||
let open_containers = server.open_containers.read();
|
||||
open_containers
|
||||
@@ -453,10 +452,8 @@ impl Player {
|
||||
}
|
||||
|
||||
pub fn get_open_container(&self, server: &Server) -> Option<Arc<Mutex<Box<dyn Container>>>> {
|
||||
if let Some(id) = self.open_container.load() {
|
||||
server.try_get_container(self.entity_id(), id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
self.open_container
|
||||
.load()
|
||||
.map_or_else(|| None, |id| server.try_get_container(self.entity_id(), id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ impl Client {
|
||||
match self.connection_state.load() {
|
||||
ConnectionState::Login => {
|
||||
self.try_send_packet(&CLoginDisconnect::new(
|
||||
&serde_json::to_string_pretty(&reason).unwrap_or("".into()),
|
||||
&serde_json::to_string_pretty(&reason).unwrap_or_else(|_| "".into()),
|
||||
))
|
||||
.unwrap_or_else(|_| self.close());
|
||||
}
|
||||
|
||||
@@ -110,9 +110,9 @@ impl Player {
|
||||
&[self.client.token],
|
||||
&CUpdateEntityPos::new(
|
||||
entity_id.into(),
|
||||
(x * 4096.0 - lastx * 4096.0) as i16,
|
||||
(y * 4096.0 - lasty * 4096.0) as i16,
|
||||
(z * 4096.0 - lastz * 4096.0) as i16,
|
||||
x.mul_add(4096.0, -(lastx * 4096.0)) as i16,
|
||||
y.mul_add(4096.0, -(lasty * 4096.0)) as i16,
|
||||
z.mul_add(4096.0, -(lastz * 4096.0)) as i16,
|
||||
position.ground,
|
||||
),
|
||||
);
|
||||
@@ -180,9 +180,9 @@ impl Player {
|
||||
&[self.client.token],
|
||||
&CUpdateEntityPosRot::new(
|
||||
entity_id.into(),
|
||||
(x * 4096.0 - lastx * 4096.0) as i16,
|
||||
(y * 4096.0 - lasty * 4096.0) as i16,
|
||||
(z * 4096.0 - lastz * 4096.0) as i16,
|
||||
x.mul_add(4096.0, -(lastx * 4096.0)) as i16,
|
||||
y.mul_add(4096.0, -(lasty * 4096.0)) as i16,
|
||||
z.mul_add(4096.0, -(lastz * 4096.0)) as i16,
|
||||
yaw as u8,
|
||||
pitch as u8,
|
||||
position_rotation.ground,
|
||||
|
||||
@@ -7,7 +7,7 @@ const NAMES: [&str; 2] = ["echest", "enderchest"];
|
||||
const DESCRIPTION: &str =
|
||||
"Show your personal enderchest (this command is used for testing container behaviour)";
|
||||
|
||||
pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
pub fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
CommandTree::new(NAMES, DESCRIPTION).execute(&|sender, server, _| {
|
||||
if let Some(player) = sender.as_mut_player() {
|
||||
let entity_id = player.entity_id();
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn parse_arg_gamemode(consumed_args: &ConsumedArgs) -> Result<GameMode, Inva
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
pub fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
CommandTree::new(NAMES, DESCRIPTION).with_child(
|
||||
require(&|sender| sender.permission_lvl() >= 2).with_child(
|
||||
argument(ARG_GAMEMODE, consume_arg_gamemode)
|
||||
|
||||
@@ -32,7 +32,7 @@ fn parse_arg_command<'a>(
|
||||
.map_err(|_| InvalidConsumptionError(Some(command_name.into())))
|
||||
}
|
||||
|
||||
pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
pub fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
CommandTree::new(NAMES, DESCRIPTION)
|
||||
.with_child(
|
||||
argument(ARG_COMMAND, consume_arg_command).execute(&|sender, server, args| {
|
||||
|
||||
@@ -14,7 +14,7 @@ pub fn consume_arg_target(_src: &CommandSender, args: &mut RawArgs) -> Option<St
|
||||
consume_arg_player(_src, args)
|
||||
}
|
||||
|
||||
pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
pub fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
CommandTree::new(NAMES, DESCRIPTION).with_child(
|
||||
argument(ARG_TARGET, consume_arg_target).execute(&|sender, server, args| {
|
||||
let target = parse_arg_player(sender, server, ARG_TARGET, args)?;
|
||||
|
||||
@@ -8,7 +8,7 @@ const NAMES: [&str; 1] = ["pumpkin"];
|
||||
|
||||
const DESCRIPTION: &str = "Display information about Pumpkin.";
|
||||
|
||||
pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
pub fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
CommandTree::new(NAMES, DESCRIPTION).execute(&|sender, _, _| {
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let description = env!("CARGO_PKG_DESCRIPTION");
|
||||
|
||||
@@ -8,7 +8,7 @@ const NAMES: [&str; 1] = ["stop"];
|
||||
|
||||
const DESCRIPTION: &str = "Stop the server.";
|
||||
|
||||
pub(crate) fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
pub fn init_command_tree<'a>() -> CommandTree<'a> {
|
||||
CommandTree::new(NAMES, DESCRIPTION).with_child(
|
||||
require(&|sender| sender.permission_lvl() >= 4).execute(&|sender, _, _args| {
|
||||
sender
|
||||
|
||||
@@ -35,7 +35,7 @@ impl<'a> CommandSender<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_player(&self) -> bool {
|
||||
pub const fn is_player(&self) -> bool {
|
||||
match self {
|
||||
CommandSender::Console => false,
|
||||
CommandSender::Player(_) => true,
|
||||
@@ -43,7 +43,7 @@ impl<'a> CommandSender<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_console(&self) -> bool {
|
||||
pub const fn is_console(&self) -> bool {
|
||||
match self {
|
||||
CommandSender::Console => true,
|
||||
CommandSender::Player(_) => false,
|
||||
@@ -59,7 +59,7 @@ impl<'a> CommandSender<'a> {
|
||||
}
|
||||
|
||||
/// todo: implement
|
||||
pub fn permission_lvl(&self) -> i32 {
|
||||
pub const fn permission_lvl(&self) -> i32 {
|
||||
match self {
|
||||
CommandSender::Rcon(_) => 4,
|
||||
CommandSender::Console => 4,
|
||||
|
||||
@@ -3,20 +3,20 @@ use crate::commands::CommandSender;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
|
||||
/// see [crate::commands::tree_builder::argument]
|
||||
pub(crate) type RawArgs<'a> = Vec<&'a str>;
|
||||
pub type RawArgs<'a> = Vec<&'a str>;
|
||||
|
||||
/// see [crate::commands::tree_builder::argument] and [CommandTree::execute]/[crate::commands::tree_builder::NonLeafNodeBuilder::execute]
|
||||
pub(crate) type ConsumedArgs<'a> = HashMap<&'a str, String>;
|
||||
pub type ConsumedArgs<'a> = HashMap<&'a str, String>;
|
||||
|
||||
/// see [crate::commands::tree_builder::argument]
|
||||
pub(crate) type ArgumentConsumer<'a> = fn(&CommandSender, &mut RawArgs) -> Option<String>;
|
||||
pub type ArgumentConsumer<'a> = fn(&CommandSender, &mut RawArgs) -> Option<String>;
|
||||
|
||||
pub(crate) struct Node<'a> {
|
||||
pub struct Node<'a> {
|
||||
pub(crate) children: Vec<usize>,
|
||||
pub(crate) node_type: NodeType<'a>,
|
||||
}
|
||||
|
||||
pub(crate) enum NodeType<'a> {
|
||||
pub enum NodeType<'a> {
|
||||
ExecuteLeaf {
|
||||
run: &'a RunFunctionType,
|
||||
},
|
||||
@@ -32,12 +32,12 @@ pub(crate) enum NodeType<'a> {
|
||||
},
|
||||
}
|
||||
|
||||
pub(crate) enum Command<'a> {
|
||||
pub enum Command<'a> {
|
||||
Tree(CommandTree<'a>),
|
||||
Alias(&'a str),
|
||||
}
|
||||
|
||||
pub(crate) struct CommandTree<'a> {
|
||||
pub struct CommandTree<'a> {
|
||||
pub(crate) nodes: Vec<Node<'a>>,
|
||||
pub(crate) children: Vec<usize>,
|
||||
pub(crate) names: Vec<&'a str>,
|
||||
|
||||
@@ -101,7 +101,7 @@ impl<'a> NodeBuilder<'a> for NonLeafNodeBuilder<'a> {
|
||||
|
||||
impl<'a> NonLeafNodeBuilder<'a> {
|
||||
/// Add a child [Node] to this one.
|
||||
pub fn with_child(mut self, child: NonLeafNodeBuilder<'a>) -> Self {
|
||||
pub fn with_child(mut self, child: Self) -> Self {
|
||||
self.child_nodes.push(child);
|
||||
self
|
||||
}
|
||||
@@ -124,7 +124,7 @@ impl<'a> NonLeafNodeBuilder<'a> {
|
||||
|
||||
/// Matches a sting literal.
|
||||
#[expect(dead_code)] // todo: remove (so far no commands requiring this are implemented)
|
||||
pub fn literal(string: &str) -> NonLeafNodeBuilder {
|
||||
pub const fn literal(string: &str) -> NonLeafNodeBuilder {
|
||||
NonLeafNodeBuilder {
|
||||
node_type: NodeType::Literal { string },
|
||||
child_nodes: Vec::new(),
|
||||
|
||||
@@ -146,7 +146,7 @@ impl Entity {
|
||||
// This has some vanilla magic
|
||||
let mut x = x;
|
||||
let mut z = z;
|
||||
while x * x + z * z < 1.0E-5 {
|
||||
while x.mul_add(x, z * z) < 1.0E-5 {
|
||||
x = (rand::random::<f64>() - rand::random::<f64>()) * 0.01;
|
||||
z = (rand::random::<f64>() - rand::random::<f64>()) * 0.01;
|
||||
}
|
||||
|
||||
@@ -96,9 +96,8 @@ impl Player {
|
||||
entity_id: EntityId,
|
||||
gamemode: GameMode,
|
||||
) -> Self {
|
||||
let gameprofile = match client.gameprofile.lock().clone() {
|
||||
Some(profile) => profile,
|
||||
None => {
|
||||
let gameprofile = client.gameprofile.lock().clone().map_or_else(
|
||||
|| {
|
||||
log::error!("No gameprofile?. Impossible");
|
||||
GameProfile {
|
||||
id: uuid::Uuid::new_v4(),
|
||||
@@ -106,8 +105,9 @@ impl Player {
|
||||
properties: vec![],
|
||||
profile_actions: None,
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|profile| profile,
|
||||
);
|
||||
let config = client.config.lock().clone().unwrap_or_default();
|
||||
Self {
|
||||
entity: Entity::new(entity_id, world, EntityType::Player, 1.62),
|
||||
@@ -135,7 +135,7 @@ impl Player {
|
||||
self.entity.world.remove_player(self);
|
||||
}
|
||||
|
||||
pub fn entity_id(&self) -> EntityId {
|
||||
pub const fn entity_id(&self) -> EntityId {
|
||||
self.entity.entity_id
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
#![deny(clippy::all)]
|
||||
// #![warn(clippy::pedantic)]
|
||||
// #![warn(clippy::restriction)]
|
||||
#![warn(clippy::nursery)]
|
||||
#![warn(clippy::cargo)]
|
||||
// expect
|
||||
#![expect(clippy::cargo_common_metadata)]
|
||||
#![expect(clippy::multiple_crate_versions)]
|
||||
#![expect(clippy::while_float)]
|
||||
#![expect(clippy::significant_drop_in_scrutinee)]
|
||||
#![expect(clippy::significant_drop_tightening)]
|
||||
#![expect(clippy::future_not_send)]
|
||||
#![expect(clippy::single_call_fn)]
|
||||
#![expect(clippy::await_holding_lock)]
|
||||
|
||||
#[cfg(target_os = "wasi")]
|
||||
|
||||
@@ -28,7 +28,7 @@ pub enum RCONError {
|
||||
|
||||
const SERVER: Token = Token(0);
|
||||
|
||||
pub struct RCONServer {}
|
||||
pub struct RCONServer;
|
||||
|
||||
impl RCONServer {
|
||||
pub async fn new(config: &RCONConfig, server: Arc<Server>) -> Result<Self, io::Error> {
|
||||
@@ -122,7 +122,7 @@ pub struct RCONClient {
|
||||
}
|
||||
|
||||
impl RCONClient {
|
||||
pub fn new(connection: TcpStream) -> Self {
|
||||
pub const fn new(connection: TcpStream) -> Self {
|
||||
Self {
|
||||
connection,
|
||||
logged_in: false,
|
||||
|
||||
@@ -8,7 +8,7 @@ use thiserror::Error;
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
/// Client -> Server
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(i32)]
|
||||
pub enum ServerboundPacket {
|
||||
/// Typically, the first packet sent by the client, which is used to authenticate the connection with the server.
|
||||
@@ -19,7 +19,7 @@ pub enum ServerboundPacket {
|
||||
}
|
||||
|
||||
impl ServerboundPacket {
|
||||
pub fn from_i32(n: i32) -> Self {
|
||||
pub const fn from_i32(n: i32) -> Self {
|
||||
match n {
|
||||
3 => Self::Auth,
|
||||
2 => Self::ExecCommand,
|
||||
@@ -28,7 +28,7 @@ impl ServerboundPacket {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(i32)]
|
||||
/// Server -> Client
|
||||
pub enum ClientboundPacket {
|
||||
@@ -76,7 +76,7 @@ pub struct Packet {
|
||||
}
|
||||
|
||||
impl Packet {
|
||||
pub async fn deserialize(incoming: &mut Vec<u8>) -> Result<Option<Packet>, PacketError> {
|
||||
pub async fn deserialize(incoming: &mut Vec<u8>) -> Result<Option<Self>, PacketError> {
|
||||
if incoming.len() < 4 {
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ impl Packet {
|
||||
}
|
||||
incoming.drain(0..len as usize);
|
||||
|
||||
let packet = Packet {
|
||||
let packet = Self {
|
||||
id,
|
||||
ptype: ServerboundPacket::from_i32(ty),
|
||||
body: String::from_utf8(payload).map_err(PacketError::InvalidBody)?,
|
||||
@@ -110,11 +110,11 @@ impl Packet {
|
||||
&self.body
|
||||
}
|
||||
|
||||
pub fn get_type(&self) -> ServerboundPacket {
|
||||
pub const fn get_type(&self) -> ServerboundPacket {
|
||||
self.ptype
|
||||
}
|
||||
|
||||
pub fn get_id(&self) -> i32 {
|
||||
pub const fn get_id(&self) -> i32 {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ pub struct CachedBranding {
|
||||
}
|
||||
|
||||
impl CachedBranding {
|
||||
pub fn new() -> CachedBranding {
|
||||
pub fn new() -> Self {
|
||||
let cached_server_brand = Self::build_brand();
|
||||
CachedBranding {
|
||||
Self {
|
||||
cached_server_brand,
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ impl CachedStatus {
|
||||
let status_response_json = serde_json::to_string(&status_response)
|
||||
.expect("Failed to parse Status response into JSON");
|
||||
|
||||
CachedStatus {
|
||||
Self {
|
||||
_status_response: status_response,
|
||||
status_response_json,
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl KeyStore {
|
||||
&private_key.e().to_bytes_be(),
|
||||
)
|
||||
.into_boxed_slice();
|
||||
KeyStore {
|
||||
Self {
|
||||
_public_key: public_key,
|
||||
private_key,
|
||||
public_key_der,
|
||||
|
||||
Reference in New Issue
Block a user