Cleanup Server struct

This cleanup's goal is to make all `Server` functions only require &self. This means that `Server` can now be a `Arc<Server>` instead of `Arc<Mutex<Server>>`, which solves a lot of deadlock problems.
This commit is contained in:
lukas0008 committed 2024-09-08 17:44:09 +02:00
1 parent f23592de8c
commit fa114e7e23
15 files changed
+136 -131

No files matched your search

+4 -3
View File
@@ -7,6 +7,7 @@ use crate::commands::tree::{Command, CommandTree, ConsumedArgs, NodeType, RawArg
use crate::commands::CommandSender;
use crate::server::Server;
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Debug)]
pub(crate) enum InvalidTreeError {
@@ -26,7 +27,7 @@ pub struct CommandDispatcher<'a> {
/// Stores registered [CommandTree]s and dispatches commands to them.
impl<'a> CommandDispatcher<'a> {
pub fn handle_command(&self, sender: &mut CommandSender, server: &mut Server, cmd: &str) {
pub fn handle_command(&self, sender: &mut CommandSender, server: &Arc<Server>, cmd: &str) {
if let Err(err) = self.dispatch(sender, server, cmd) {
sender.send_message(
TextComponent::text(&err).color_named(pumpkin_core::text::color::NamedColor::Red),
@@ -38,7 +39,7 @@ impl<'a> CommandDispatcher<'a> {
pub(crate) fn dispatch(
&'a self,
src: &mut CommandSender,
server: &mut Server,
server: &Arc<Server>,
cmd: &str,
) -> Result<(), String> {
let mut parts = cmd.split_ascii_whitespace();
@@ -86,7 +87,7 @@ impl<'a> CommandDispatcher<'a> {
fn try_is_fitting_path(
src: &mut CommandSender,
server: &mut Server,
server: &Arc<Server>,
path: Vec<usize>,
tree: &CommandTree,
mut raw_args: RawArgs,