Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(player-data): Support saving and loading player NBT Data #600

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use logging::LoggingConfig;
use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
use serde::{Deserialize, Serialize, de::DeserializeOwned};

use std::path::PathBuf;
use std::{
env, fs,
net::{Ipv4Addr, SocketAddr},
Expand All @@ -28,10 +29,12 @@ mod commands;

pub mod chunk;
pub mod op;
mod player_data;
mod pvp;
mod server_links;

use networking::NetworkingConfig;
use player_data::PlayerDataConfig;
use resource_pack::ResourcePackConfig;

const CONFIG_ROOT_FOLDER: &str = "config/";
Expand Down Expand Up @@ -92,6 +95,7 @@ pub struct AdvancedConfiguration {
pub commands: CommandsConfig,
pub pvp: PVPConfig,
pub server_links: ServerLinksConfig,
pub player_data: PlayerDataConfig,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -133,6 +137,8 @@ pub struct BasicConfiguration {
pub use_favicon: bool,
/// Path to server favicon
pub favicon_path: String,
/// The default level name
pub default_level_name: String,
}

impl Default for BasicConfiguration {
Expand All @@ -156,10 +162,17 @@ impl Default for BasicConfiguration {
scrub_ips: true,
use_favicon: true,
favicon_path: "icon.png".to_string(),
default_level_name: "world".to_string(),
}
}
}

impl BasicConfiguration {
pub fn get_world_path(&self) -> PathBuf {
format!("./{}", self.default_level_name).parse().unwrap()
}
}

trait LoadConfiguration {
fn load(exec_dir: &Path) -> Self
where
Expand Down
19 changes: 19 additions & 0 deletions pumpkin-config/src/player_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
#[serde(default)]
pub struct PlayerDataConfig {
/// Is Player Data saving enabled?
pub save_player_data: bool,
/// Time interval in seconds to save player data
pub save_player_cron_interval: u64,
}

impl Default for PlayerDataConfig {
fn default() -> Self {
Self {
save_player_data: true,
save_player_cron_interval: 300,
}
}
}
18 changes: 18 additions & 0 deletions pumpkin-inventory/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ impl PlayerInventory {
slots.into_boxed_slice()
}

pub fn armor_slots(&self) -> Box<[Option<&ItemStack>]> {
self.armor.iter().map(|item| item.as_ref()).collect()
}

pub fn crafting_slots(&self) -> Box<[Option<&ItemStack>]> {
let mut slots = vec![self.crafting_output.as_ref()];
slots.extend(self.crafting.iter().map(|c| c.as_ref()));
slots.into_boxed_slice()
}

pub fn item_slots(&self) -> Box<[Option<&ItemStack>]> {
self.items.iter().map(|item| item.as_ref()).collect()
}

pub fn offhand_slot(&self) -> Option<&ItemStack> {
self.offhand.as_ref()
}

pub fn iter_items_mut(&mut self) -> IterMut<Option<ItemStack>> {
self.items.iter_mut()
}
Expand Down
2 changes: 2 additions & 0 deletions pumpkin-nbt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ thiserror.workspace = true
bytes.workspace = true

cesu8 = "1.1"
flate2 = "1.1"
tempfile = "3.17.1"
1 change: 1 addition & 0 deletions pumpkin-nbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use thiserror::Error;

pub mod compound;
pub mod deserializer;
pub mod nbt_compress;
pub mod serializer;
pub mod tag;

Expand Down
Loading
Loading