1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use valence_server::protocol::packets::play::command_tree_s2c::Parser;
use valence_server::GameMode;

use crate::parsers::{CommandArg, CommandArgParseError, ParseInput};

impl CommandArg for GameMode {
    fn parse_arg(input: &mut ParseInput) -> Result<Self, CommandArgParseError> {
        input.skip_whitespace();
        if input.match_next("survival") {
            Ok(GameMode::Survival)
        } else if input.match_next("creative") {
            Ok(GameMode::Creative)
        } else if input.match_next("adventure") {
            Ok(GameMode::Adventure)
        } else if input.match_next("spectator") {
            Ok(GameMode::Spectator)
        } else {
            Err(CommandArgParseError::InvalidArgument {
                expected: "game_mode".to_owned(),
                got: input.peek_word().to_owned(),
            })
        }
    }

    fn display() -> Parser {
        Parser::GameMode
    }
}