minecraft_command_types/command/
bossbar.rs

1use crate::command::enums::bossbar_color::BossbarColor;
2use crate::command::enums::bossbar_get_type::BossbarGetType;
3use crate::command::enums::bossbar_style::BossbarStyle;
4use crate::entity_selector::EntitySelector;
5use crate::resource_location::ResourceLocation;
6use crate::snbt::SNBT;
7use minecraft_command_types_derive::HasMacro;
8use std::fmt::{Display, Formatter};
9
10#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
11pub enum BossbarSetType {
12    /// Set the text color (if no color was specified as part of a text component) and bar color. Defaults to `white` upon creation.
13    Color(BossbarColor),
14    /// Set the bossbar's maximum value. Defaults to `100` upon creation.
15    Max(i32),
16    /// Set the bossbar's name.
17    Name(SNBT),
18    /// Change the set of players to whom the bar is visible. Defaults to none upon creation.
19    Players(Option<EntitySelector>),
20    /// Set the bossbar's visual amount of segments: continuous, 6 segments, 10 segments, 12 segments, or 20 segments. Defaults to `progress` upon creation.
21    Style(BossbarStyle),
22    /// Set the bossbar's current value. Defaults to `0` upon creation.
23    Value(i32),
24    /// Set the bossbar's visibility. Defaults to `true` upon creation.
25    Visible(bool),
26}
27
28impl Display for BossbarSetType {
29    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
30        match self {
31            BossbarSetType::Color(color) => write!(f, "color {}", color),
32            BossbarSetType::Max(max) => write!(f, "max {}", max),
33            BossbarSetType::Name(name) => write!(f, "name {}", name),
34            BossbarSetType::Players(players) => {
35                f.write_str("players")?;
36
37                if let Some(players) = players {
38                    write!(f, " {}", players)?;
39                }
40
41                Ok(())
42            }
43            BossbarSetType::Style(style) => write!(f, "style {}", style),
44            BossbarSetType::Value(value) => write!(f, "value {}", value),
45            BossbarSetType::Visible(visible) => write!(f, "visible {}", visible),
46        }
47    }
48}
49
50#[derive(Debug, Clone, Eq, PartialEq, Hash, HasMacro)]
51pub enum BossbarCommand {
52    Add(ResourceLocation, SNBT),
53    Get(ResourceLocation, BossbarGetType),
54    List,
55    Remove(ResourceLocation),
56    Set(ResourceLocation, BossbarSetType),
57}
58
59impl Display for BossbarCommand {
60    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
61        match self {
62            BossbarCommand::Add(id, name) => write!(f, "add {} {}", id, name),
63            BossbarCommand::Get(id, type_) => write!(f, "get {} {}", id, type_),
64            BossbarCommand::List => f.write_str("list"),
65            BossbarCommand::Remove(id) => write!(f, "remove {}", id),
66            BossbarCommand::Set(id, set_type) => write!(f, "set {} {}", id, set_type),
67        }
68    }
69}