valence_command/parsers/
color.rs

1use valence_text::Color;
2
3use super::Parser;
4use crate::parsers::{CommandArg, CommandArgParseError, ParseInput};
5
6impl CommandArg for Color {
7    fn parse_arg(input: &mut ParseInput) -> Result<Self, CommandArgParseError> {
8        input.skip_whitespace();
9        if input.match_next("black") {
10            Ok(Self::BLACK)
11        } else if input.match_next("dark_blue") {
12            Ok(Self::DARK_BLUE)
13        } else if input.match_next("dark_green") {
14            Ok(Self::DARK_GREEN)
15        } else if input.match_next("dark_aqua") {
16            Ok(Self::DARK_AQUA)
17        } else if input.match_next("dark_red") {
18            Ok(Self::DARK_RED)
19        } else if input.match_next("dark_purple") {
20            Ok(Self::DARK_PURPLE)
21        } else if input.match_next("gold") {
22            Ok(Self::GOLD)
23        } else if input.match_next("gray") {
24            Ok(Self::GRAY)
25        } else if input.match_next("dark_gray") {
26            Ok(Self::DARK_GRAY)
27        } else if input.match_next("blue") {
28            Ok(Self::BLUE)
29        } else if input.match_next("green") {
30            Ok(Self::GREEN)
31        } else if input.match_next("aqua") {
32            Ok(Self::AQUA)
33        } else if input.match_next("red") {
34            Ok(Self::RED)
35        } else if input.match_next("light_purple") {
36            Ok(Self::LIGHT_PURPLE)
37        } else if input.match_next("yellow") {
38            Ok(Self::YELLOW)
39        } else if input.match_next("white") {
40            Ok(Self::WHITE)
41        } else if input.match_next("reset") {
42            Ok(Self::Reset)
43        } else {
44            Err(CommandArgParseError::InvalidArgument {
45                expected: "chat_color".to_owned(),
46                got: "not a valid chat color".to_owned(),
47            })
48        }
49    }
50
51    fn display() -> Parser {
52        Parser::Color
53    }
54}