Use Cow's in TextComponent
We now don't always convert &str to Strings allowing us to use stack allocations
This commit is contained in:
1 parent
dfc0b8afe9
commit
a6d9ed216d
26 files changed
+134
-149
No files matched your search
@@ -18,7 +18,7 @@ impl<'a> Command<'a> for GamemodeCommand {
|
||||
|
||||
if args.len() != 2 {
|
||||
player.send_system_message(
|
||||
TextComponent::from("Usage: /gamemode <mode>")
|
||||
TextComponent::text("Usage: /gamemode <mode>")
|
||||
.color_named(pumpkin_text::color::NamedColor::Red),
|
||||
);
|
||||
return;
|
||||
@@ -28,21 +28,26 @@ impl<'a> Command<'a> for GamemodeCommand {
|
||||
match mode_str.parse() {
|
||||
Ok(mode) => {
|
||||
player.set_gamemode(mode);
|
||||
player.send_system_message(format!("Set own game mode to {:?}", mode).into());
|
||||
player.send_system_message(TextComponent::text(&format!(
|
||||
"Set own game mode to {:?}",
|
||||
mode
|
||||
)));
|
||||
}
|
||||
Err(_) => {
|
||||
// try to parse from number
|
||||
if let Ok(i) = mode_str.parse::<u8>() {
|
||||
if let Some(mode) = GameMode::from_u8(i) {
|
||||
player.set_gamemode(mode);
|
||||
player
|
||||
.send_system_message(format!("Set own game mode to {:?}", mode).into());
|
||||
player.send_system_message(TextComponent::text(&format!(
|
||||
"Set own game mode to {:?}",
|
||||
mode
|
||||
)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
player.send_system_message(
|
||||
TextComponent::from("Invalid gamemode")
|
||||
TextComponent::text("Invalid gamemode")
|
||||
.color_named(pumpkin_text::color::NamedColor::Red),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,5 +79,5 @@ pub fn handle_command(sender: &mut CommandSender, command: &str) {
|
||||
return;
|
||||
}
|
||||
// TODO: red color
|
||||
sender.send_message("Command not Found".into());
|
||||
sender.send_message(TextComponent::text("Command not Found"));
|
||||
}
|
||||
@@ -15,6 +15,6 @@ impl<'a> Command<'a> for PumpkinCommand {
|
||||
fn on_execute(sender: &mut super::CommandSender<'a>, _command: String) {
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let description = env!("CARGO_PKG_DESCRIPTION");
|
||||
sender.send_message(TextComponent::from(format!("Pumpkin {version}, {description} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})")).color_named(NamedColor::Green))
|
||||
sender.send_message(TextComponent::text(&format!("Pumpkin {version}, {description} (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})")).color_named(NamedColor::Green))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user