mirror of
https://github.com/zyllian/classics.git
synced 2025-01-17 19:22:37 -08:00
add command to save the level without stopping
This commit is contained in:
parent
be81b8d581
commit
c3313626be
3 changed files with 19 additions and 2 deletions
|
@ -19,6 +19,7 @@ const CMD_ALLOWENTRY: &str = "allowentry";
|
|||
const CMD_SETPASS: &str = "setpass";
|
||||
const CMD_SETLEVELSPAWN: &str = "setlevelspawn";
|
||||
const CMD_WEATHER: &str = "weather";
|
||||
const CMD_SAVE: &str = "save";
|
||||
|
||||
/// list of commands available on the server
|
||||
pub const COMMANDS_LIST: &[&str] = &[
|
||||
|
@ -33,6 +34,7 @@ pub const COMMANDS_LIST: &[&str] = &[
|
|||
CMD_SETPASS,
|
||||
CMD_SETLEVELSPAWN,
|
||||
CMD_WEATHER,
|
||||
CMD_SAVE,
|
||||
];
|
||||
|
||||
/// enum for possible commands
|
||||
|
@ -74,6 +76,8 @@ pub enum Command<'m> {
|
|||
SetLevelSpawn,
|
||||
/// changes the levels weather
|
||||
Weather { weather_type: &'m str },
|
||||
/// saves the current level
|
||||
Save,
|
||||
}
|
||||
|
||||
impl<'m> Command<'m> {
|
||||
|
@ -128,6 +132,7 @@ impl<'m> Command<'m> {
|
|||
CMD_WEATHER => Self::Weather {
|
||||
weather_type: arguments,
|
||||
},
|
||||
CMD_SAVE => Self::Save,
|
||||
_ => return Err(format!("Unknown command: {command_name}")),
|
||||
})
|
||||
}
|
||||
|
@ -146,6 +151,7 @@ impl<'m> Command<'m> {
|
|||
Self::SetPass { .. } => CMD_SETPASS,
|
||||
Self::SetLevelSpawn => CMD_SETLEVELSPAWN,
|
||||
Self::Weather { .. } => CMD_WEATHER,
|
||||
Self::Save => CMD_SAVE,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,6 +217,7 @@ impl<'m> Command<'m> {
|
|||
c("<weather type>"),
|
||||
"&fSets the level's weather.".to_string(),
|
||||
],
|
||||
CMD_SAVE => vec![c(""), "&fSaves the current level.".to_string()],
|
||||
_ => vec!["&eUnknown command!".to_string()],
|
||||
}
|
||||
}
|
||||
|
@ -497,6 +504,11 @@ impl<'m> Command<'m> {
|
|||
messages.push(format!("&cUnknown weather type {weather_type}!"));
|
||||
}
|
||||
}
|
||||
|
||||
Command::Save => {
|
||||
data.level.save_now = true;
|
||||
messages.push("Saving level...".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
messages
|
||||
|
|
|
@ -37,6 +37,8 @@ pub struct Level {
|
|||
/// list of updates to apply to the world on the next tick
|
||||
#[serde(skip)]
|
||||
pub updates: Vec<BlockUpdate>,
|
||||
#[serde(skip)]
|
||||
pub save_now: bool,
|
||||
}
|
||||
|
||||
impl Level {
|
||||
|
@ -50,6 +52,7 @@ impl Level {
|
|||
weather: WeatherType::Sunny,
|
||||
awaiting_update: Default::default(),
|
||||
updates: Default::default(),
|
||||
save_now: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,9 +157,11 @@ async fn handle_ticks(data: Arc<RwLock<ServerData>>) {
|
|||
break;
|
||||
}
|
||||
|
||||
if data.config.auto_save_minutes != 0
|
||||
&& last_auto_save.elapsed().as_secs() / 60 >= data.config.auto_save_minutes
|
||||
if data.level.save_now
|
||||
|| (data.config.auto_save_minutes != 0
|
||||
&& last_auto_save.elapsed().as_secs() / 60 >= data.config.auto_save_minutes)
|
||||
{
|
||||
data.level.save_now = false;
|
||||
data.level
|
||||
.save(PathBuf::from(LEVELS_PATH).join(&data.config.level_name))
|
||||
.await
|
||||
|
|
Loading…
Add table
Reference in a new issue