added some fun
😉
This commit is contained in:
parent
d36102dc69
commit
bfdd57b88f
14
pumpkin-config/src/fun.rs
Normal file
14
pumpkin-config/src/fun.rs
Normal 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 }
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
use chunk::ChunkConfig;
|
||||
use fun::FunConfig;
|
||||
use log::warn;
|
||||
use logging::LoggingConfig;
|
||||
use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
|
||||
@ -12,6 +13,7 @@ use std::{
|
||||
path::Path,
|
||||
sync::LazyLock,
|
||||
};
|
||||
pub mod fun;
|
||||
pub mod logging;
|
||||
pub mod networking;
|
||||
|
||||
@ -99,6 +101,7 @@ pub struct AdvancedConfiguration {
|
||||
pub pvp: PVPConfig,
|
||||
pub server_links: ServerLinksConfig,
|
||||
pub player_data: PlayerDataConfig,
|
||||
pub fun: FunConfig,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
||||
@ -9,6 +9,7 @@ use crate::net::PlayerConfig;
|
||||
use crate::plugin::player::player_chat::PlayerChatEvent;
|
||||
use crate::plugin::player::player_command_send::PlayerCommandSendEvent;
|
||||
use crate::plugin::player::player_move::PlayerMoveEvent;
|
||||
use crate::server::seasonal_events;
|
||||
use crate::world::BlockFlags;
|
||||
use crate::{
|
||||
command::CommandSender,
|
||||
@ -688,10 +689,15 @@ impl Player {
|
||||
|
||||
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(
|
||||
config.chat.format.clone(),
|
||||
gameprofile.name.clone(),
|
||||
event.message.clone(),
|
||||
message,
|
||||
);
|
||||
|
||||
let entity = &self.living_entity.entity;
|
||||
|
||||
@ -40,6 +40,7 @@ use tokio_util::task::TaskTracker;
|
||||
|
||||
mod connection_cache;
|
||||
mod key_store;
|
||||
pub mod seasonal_events;
|
||||
pub mod ticker;
|
||||
|
||||
pub const CURRENT_MC_VERSION: &str = "1.21.5";
|
||||
|
||||
26
pumpkin/src/server/seasonal_events.rs
Normal file
26
pumpkin/src/server/seasonal_events.rs
Normal 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)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user