Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ bitflags = "2.6"
serde = "1"
serde_json = "1.0"
md5 = "0.8"
bus = "2.2"
ctrlc = "3.1"
tracing = "0.1"
rand = "0.10"
Expand Down
1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ bitflags = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
md5 = { workspace = true }
bus = { workspace = true }
ctrlc = { workspace = true, features = ["termination"] }
tracing = { workspace = true }
rand = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions crates/core/src/permissions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ impl PermissionNode {
}

for (i, segment) in str.split('.').enumerate() {
match &self.path[i] {
PathSegment::WildCard => return true,
PathSegment::Named(name) => {
match self.path.get(i) {
None => return false,
Some(PathSegment::WildCard) => return true,
Some(PathSegment::Named(name)) => {
if name != segment {
return false;
}
Expand Down
33 changes: 22 additions & 11 deletions crates/core/src/player.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::config::CONFIG;
use crate::permissions::{self, PlayerPermissionsCache};
use crate::permissions::PlayerPermissionsCache;
use crate::plot::worldedit::WorldEditUndo;
use crate::plot::PLOT_SCALE;
use crate::utils::{self, HyphenatedUUID};
Expand Down Expand Up @@ -196,17 +195,14 @@ impl Player {
uuid: u128,
username: String,
properties: Vec<PlayerProperty>,
permissions_cache: Option<PlayerPermissionsCache>,
client: PlayerConn,
) -> Player {
// Load inventory
let mut inventory: Vec<Option<ItemStack>> = vec![None; 46];
for entry in player_data.inventory {
inventory[entry.slot as usize] = Some(entry.get_item_stack());
}
let permissions_cache = CONFIG
.luckperms
.is_some()
.then(|| permissions::load_player_cache(uuid).unwrap());
Player {
uuid,
username,
Expand Down Expand Up @@ -250,6 +246,7 @@ impl Player {
uuid: u128,
username: String,
properties: Vec<PlayerProperty>,
permissions_cache: Option<PlayerPermissionsCache>,
client: PlayerConn,
) -> Player {
let filename = format!("./world/players/{:032x}", uuid);
Expand All @@ -266,14 +263,29 @@ impl Player {
uuid,
username,
properties,
permissions_cache,
client,
);
}
};

Player::from_data(player_data, uuid, username, properties, client)
Player::from_data(
player_data,
uuid,
username,
properties,
permissions_cache,
client,
)
} else {
Player::from_data(Default::default(), uuid, username, properties, client)
Player::from_data(
Default::default(),
uuid,
username,
properties,
permissions_cache,
client,
)
}
}

Expand Down Expand Up @@ -478,11 +490,10 @@ impl Player {
self.client.send_packet(&cui_plugin_message);
}

/// Sends the player the disconnect packet, it is still up to the player to end the network
/// stream.
pub fn kick(&self, reason: TextComponent) {
pub fn kick(&mut self, reason: TextComponent) {
let disconnect = CDisconnect { reason }.encode();
self.client.send_packet(&disconnect);
self.client.close_connection();
}

pub fn update_player_abilities(&self) {
Expand Down
12 changes: 10 additions & 2 deletions crates/core/src/plot/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ fn parse_relative_coord<F: FromStr + Add + Add<Output = F>>(
}
}

fn parse_relative_plot_coord(coord: &str, ref_coord: i32) -> Option<i32> {
match coord.strip_prefix('~') {
Some("") => Some(ref_coord),
Some(offset) => ref_coord.checked_add(offset.parse().ok()?),
None => coord.parse().ok(),
}
}

impl Plot {
/// Handles a command that starts with `/plot` or `/p`
fn handle_plot_command(&mut self, player: usize, command: &str, args: &[&str]) {
Expand Down Expand Up @@ -129,13 +137,13 @@ impl Plot {

let new_plot_x;
let new_plot_z;
if let Ok(x_arg) = parse_relative_coord(args[0], plot_x) {
if let Some(x_arg) = parse_relative_plot_coord(args[0], plot_x) {
new_plot_x = x_arg;
} else {
self.players[player].send_error_message("Unable to parse x coordinate!");
return;
}
if let Ok(z_arg) = parse_relative_coord(args[1], plot_z) {
if let Some(z_arg) = parse_relative_plot_coord(args[1], plot_z) {
new_plot_z = z_arg;
} else {
self.players[player].send_error_message("Unable to parse z coordinate!");
Expand Down
9 changes: 4 additions & 5 deletions crates/core/src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::player::{EntityId, Gamemode, PacketSender, Player, PlayerPos};
use crate::server::{BroadcastMessage, Message, PrivMessage};
use crate::utils::HyphenatedUUID;
use anyhow::Error;
use bus::BusReader;
use itertools::Itertools;
use mchprs_blocks::block_entities::BlockEntity;
use mchprs_blocks::blocks::Block;
Expand Down Expand Up @@ -66,7 +65,7 @@ pub struct Plot {
pub redpiler: Compiler,

// Thread communication
message_receiver: BusReader<BroadcastMessage>,
message_receiver: Receiver<BroadcastMessage>,
message_sender: Sender<Message>,
priv_message_receiver: Receiver<PrivMessage>,

Expand Down Expand Up @@ -1151,7 +1150,7 @@ impl Plot {
plot_data: PlotData,
x: i32,
z: i32,
rx: BusReader<BroadcastMessage>,
rx: Receiver<BroadcastMessage>,
tx: Sender<Message>,
priv_rx: Receiver<PrivMessage>,
always_running: bool,
Expand Down Expand Up @@ -1214,7 +1213,7 @@ impl Plot {
fn load(
x: i32,
z: i32,
rx: BusReader<BroadcastMessage>,
rx: Receiver<BroadcastMessage>,
tx: Sender<Message>,
priv_rx: Receiver<PrivMessage>,
always_running: bool,
Expand Down Expand Up @@ -1298,7 +1297,7 @@ impl Plot {
pub fn load_and_run(
x: i32,
z: i32,
rx: BusReader<BroadcastMessage>,
rx: Receiver<BroadcastMessage>,
tx: Sender<Message>,
priv_rx: Receiver<PrivMessage>,
always_running: bool,
Expand Down
Loading
Loading