added some fun

😉
This commit is contained in:
Alexander Medvedev 2025-04-01 15:45:23 +02:00
parent d36102dc69
commit bfdd57b88f
5 changed files with 51 additions and 1 deletions

14
pumpkin-config/src/fun.rs Normal file
View File

@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};
// Lets face it, the only reason we play this game is because of fun 🙃
#[derive(Deserialize, Serialize)]
#[serde(default)]
pub struct FunConfig {
pub april_fools: bool,
}
impl Default for FunConfig {
fn default() -> Self {
Self { april_fools: true }
}
}

View File

@ -1,4 +1,5 @@
use chunk::ChunkConfig; use chunk::ChunkConfig;
use fun::FunConfig;
use log::warn; use log::warn;
use logging::LoggingConfig; use logging::LoggingConfig;
use pumpkin_util::{Difficulty, GameMode, PermissionLvl}; use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
@ -12,6 +13,7 @@ use std::{
path::Path, path::Path,
sync::LazyLock, sync::LazyLock,
}; };
pub mod fun;
pub mod logging; pub mod logging;
pub mod networking; pub mod networking;
@ -99,6 +101,7 @@ pub struct AdvancedConfiguration {
pub pvp: PVPConfig, pub pvp: PVPConfig,
pub server_links: ServerLinksConfig, pub server_links: ServerLinksConfig,
pub player_data: PlayerDataConfig, pub player_data: PlayerDataConfig,
pub fun: FunConfig,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]

View File

@ -9,6 +9,7 @@ use crate::net::PlayerConfig;
use crate::plugin::player::player_chat::PlayerChatEvent; use crate::plugin::player::player_chat::PlayerChatEvent;
use crate::plugin::player::player_command_send::PlayerCommandSendEvent; use crate::plugin::player::player_command_send::PlayerCommandSendEvent;
use crate::plugin::player::player_move::PlayerMoveEvent; use crate::plugin::player::player_move::PlayerMoveEvent;
use crate::server::seasonal_events;
use crate::world::BlockFlags; use crate::world::BlockFlags;
use crate::{ use crate::{
command::CommandSender, command::CommandSender,
@ -688,10 +689,15 @@ impl Player {
let config = advanced_config(); let config = advanced_config();
let message = match seasonal_events::modify_chat_message(&event.message) {
Some(m) => m,
None => event.message.clone(),
};
let decorated_message = &TextComponent::chat_decorated( let decorated_message = &TextComponent::chat_decorated(
config.chat.format.clone(), config.chat.format.clone(),
gameprofile.name.clone(), gameprofile.name.clone(),
event.message.clone(), message,
); );
let entity = &self.living_entity.entity; let entity = &self.living_entity.entity;

View File

@ -40,6 +40,7 @@ use tokio_util::task::TaskTracker;
mod connection_cache; mod connection_cache;
mod key_store; mod key_store;
pub mod seasonal_events;
pub mod ticker; pub mod ticker;
pub const CURRENT_MC_VERSION: &str = "1.21.5"; pub const CURRENT_MC_VERSION: &str = "1.21.5";

View File

@ -0,0 +1,26 @@
use chrono::{Datelike, Local};
use pumpkin_config::advanced_config;
use rand::{seq::SliceRandom, thread_rng};
// Infact Mojang also has some Seasonal Events, so we can use that later to match Vanilla :D
#[must_use]
pub fn is_april() -> bool {
let data = Local::now();
data.day() == 1 && data.month() == 4
}
#[must_use]
pub fn modify_chat_message(message: &str) -> Option<String> {
if !advanced_config().fun.april_fools && is_april() {
return None;
}
let mut words: Vec<&str> = message.split_whitespace().collect();
if words.is_empty() {
return None;
}
let mut rng = thread_rng();
words.shuffle(&mut rng);
let result = words.join(" ");
Some(result)
}