valence_command/parsers/
gamemode.rs
1use valence_server::protocol::packets::play::command_tree_s2c::Parser;
2use valence_server::GameMode;
3
4use crate::parsers::{CommandArg, CommandArgParseError, ParseInput};
5
6impl CommandArg for GameMode {
7 fn parse_arg(input: &mut ParseInput) -> Result<Self, CommandArgParseError> {
8 input.skip_whitespace();
9 if input.match_next("survival") {
10 Ok(GameMode::Survival)
11 } else if input.match_next("creative") {
12 Ok(GameMode::Creative)
13 } else if input.match_next("adventure") {
14 Ok(GameMode::Adventure)
15 } else if input.match_next("spectator") {
16 Ok(GameMode::Spectator)
17 } else {
18 Err(CommandArgParseError::InvalidArgument {
19 expected: "game_mode".to_owned(),
20 got: input.peek_word().to_owned(),
21 })
22 }
23 }
24
25 fn display() -> Parser {
26 Parser::GameMode
27 }
28}