steel_core/command/builtins/
setidletimeout.rs1use crate::command::brigadier::{ArgumentType, CommandNodeBuilder, CommandSyntaxError};
4use crate::command::execution::{
5 CommandSource, SteelCommandContext, SteelCommandRuntime, argument, literal,
6};
7use crate::command::registration::CommandRegistration;
8use std::sync::atomic::Ordering;
9use steel_utils::Identifier;
10use steel_utils::translations::{
11 COMMANDS_SETIDLETIMEOUT_SUCCESS, COMMANDS_SETIDLETIMEOUT_SUCCESS_DISABLED,
12};
13use text_components::TextComponent;
14
15pub(super) fn registration() -> CommandRegistration<CommandSource> {
16 CommandRegistration::new(Identifier::vanilla_static("setidletimeout"), |_| command())
17}
18
19fn command() -> CommandNodeBuilder<CommandSource, SteelCommandRuntime> {
20 literal("setidletimeout")
21 .then(argument("minutes", ArgumentType::integer(0, i32::MAX)).executes(set_idle_timeout))
22}
23
24fn set_idle_timeout(
25 context: &SteelCommandContext<CommandSource>,
26) -> Result<i32, CommandSyntaxError> {
27 let time = context.integer("minutes")?;
28
29 context
30 .source()
31 .server()
32 .player_idle_timeout
33 .store(time, Ordering::Relaxed);
34
35 if time > 0 {
36 context.source().send_success(
37 &COMMANDS_SETIDLETIMEOUT_SUCCESS
38 .message([TextComponent::plain(time.to_string())])
39 .component(),
40 true,
41 );
42 } else {
43 context.source().send_success(
44 &TextComponent::from(&COMMANDS_SETIDLETIMEOUT_SUCCESS_DISABLED),
45 true,
46 );
47 }
48
49 Ok(time)
50}