convert debug command to use macro string

This commit is contained in:
Moritz Hölting 2024-11-07 14:40:25 +01:00
parent 2c9fa613ed
commit 72f98849ea
1 changed files with 8 additions and 8 deletions

View File

@ -29,7 +29,7 @@ pub enum Command {
/// A command that contains macro usages
UsesMacro(MacroString),
/// Message to be printed only in debug mode
Debug(String),
Debug(MacroString),
/// Execute command
Execute(Execute),
/// Group of commands to be called instantly after each other
@ -91,8 +91,8 @@ impl Command {
#[must_use]
pub fn contains_macro(&self, options: &CompileOptions) -> bool {
match self {
Self::Raw(_) | Self::Comment(_) | Self::Debug(_) | Self::Execute(_) => false,
Self::UsesMacro(cmd) => cmd.contains_macro(),
Self::Raw(_) | Self::Comment(_) | Self::Execute(_) => false,
Self::UsesMacro(s) | Self::Debug(s) => s.contains_macro(),
Self::Group(commands) => group_contains_macro(commands, options),
}
}
@ -101,8 +101,8 @@ impl Command {
#[must_use]
pub fn get_macros(&self) -> HashSet<&str> {
match self {
Self::Raw(_) | Self::Comment(_) | Self::Debug(_) | Self::Execute(_) => HashSet::new(),
Self::UsesMacro(cmd) => cmd.get_macros(),
Self::Raw(_) | Self::Comment(_) | Self::Execute(_) => HashSet::new(),
Self::UsesMacro(s) | Self::Debug(s) => s.get_macros(),
Self::Group(commands) => group_get_macros(commands),
}
}
@ -124,11 +124,11 @@ impl From<&mut Function> for Command {
}
}
fn compile_debug(message: &str, option: &CompileOptions) -> Vec<String> {
fn compile_debug(message: &MacroString, option: &CompileOptions) -> Vec<String> {
if option.debug {
vec![format!(
r#"tellraw @a [{{"text":"[","color":"dark_blue"}},{{"text":"DEBUG","color":"dark_green","hoverEvent":{{"action":"show_text","value":[{{"text":"Debug message generated by Shulkerbox"}},{{"text":"\nSet debug message to 'false' to disable"}}]}}}},{{"text":"]","color":"dark_blue"}},{{"text":" {}","color":"black"}}]"#,
message
r#"tellraw @a [{{"text":"[","color":"dark_blue"}},{{"text":"DEBUG","color":"dark_green","hoverEvent":{{"action":"show_text","value":[{{"text":"Debug message generated by Shulkerbox"}},{{"text":"\nSet debug to 'false' to disable"}}]}}}},{{"text":"] ","color":"dark_blue"}},{{"text":"{}","color":"black"}}]"#,
message.compile()
)]
} else {
Vec::new()