minecraft_command_types/command/
datapack.rs

1use crate::command::enums::datapack_list_type::DatapackListType;
2use crate::snbt::SNBT;
3use minecraft_command_types_derive::HasMacro;
4use std::fmt::{Display, Formatter};
5
6#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
7pub enum DatapackLoadPriority {
8    First,
9    Last,
10    Before(String),
11    After(String),
12}
13
14impl Display for DatapackLoadPriority {
15    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
16        match self {
17            DatapackLoadPriority::First => f.write_str("first"),
18            DatapackLoadPriority::Last => f.write_str("last"),
19            DatapackLoadPriority::Before(existing) => write!(f, "before {}", existing),
20            DatapackLoadPriority::After(existing) => write!(f, "after {}", existing),
21        }
22    }
23}
24
25#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
26pub enum DatapackCommand {
27    Disable(String),
28    Enable(String, Option<DatapackLoadPriority>),
29    List(Option<DatapackListType>),
30    Create(String, SNBT),
31}
32
33impl Display for DatapackCommand {
34    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
35        match self {
36            DatapackCommand::Disable(name) => {
37                write!(f, "disable {}", name)
38            }
39            DatapackCommand::Enable(name, load_priority) => {
40                write!(f, "enable {}", name)?;
41
42                if let Some(load_priority) = load_priority {
43                    write!(f, " {}", load_priority)?;
44                }
45
46                Ok(())
47            }
48            DatapackCommand::List(list_type) => {
49                f.write_str("list")?;
50
51                if let Some(list_type) = list_type {
52                    write!(f, " {}", list_type)?;
53                }
54
55                Ok(())
56            }
57            DatapackCommand::Create(id, description) => {
58                write!(f, "create {} {}", id, description)
59            }
60        }
61    }
62}