Remove lifetime from TextComponent

This commit is contained in:
Alexander Medvedev 2024-12-30 13:10:02 +01:00
parent 6f7433ee68
commit f772d971f6
66 changed files with 228 additions and 244 deletions

View File

@ -5,19 +5,19 @@ use serde::{Deserialize, Serialize};
/// Action to take on click of the text.
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize, Eq, Hash)]
#[serde(tag = "action", content = "value", rename_all = "snake_case")]
pub enum ClickEvent<'a> {
pub enum ClickEvent {
/// Opens a URL
OpenUrl(Cow<'a, str>),
OpenUrl(Cow<'static, str>),
/// Opens a File
OpenFile(Cow<'a, str>),
OpenFile(Cow<'static, str>),
/// Works in signs, but only on the root text component
RunCommand(Cow<'a, str>),
RunCommand(Cow<'static, str>),
/// Replaces the contents of the chat box with the text, not necessarily a
/// command.
SuggestCommand(Cow<'a, str>),
SuggestCommand(Cow<'static, str>),
/// Only usable within written books. Changes the page of the book. Indexing
/// starts at 1.
ChangePage(i32),
/// Copies the given text to system clipboard
CopyToClipboard(Cow<'a, str>),
CopyToClipboard(Cow<'static, str>),
}

View File

@ -6,17 +6,17 @@ use super::TextComponent;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(tag = "action", content = "contents", rename_all = "snake_case")]
pub enum HoverEvent<'a> {
pub enum HoverEvent {
/// Displays a tooltip with the given text.
ShowText(Cow<'a, str>),
ShowText(Cow<'static, str>),
/// Shows an item.
ShowItem {
/// Resource identifier of the item
id: Cow<'a, str>,
id: Cow<'static, str>,
/// Number of the items in the stack
count: Option<i32>,
/// NBT information about the item (sNBT format)
tag: Cow<'a, str>,
tag: Cow<'static, str>,
},
/// Shows an entity.
ShowEntity {
@ -25,9 +25,9 @@ pub enum HoverEvent<'a> {
/// Resource identifier of the entity
#[serde(rename = "type")]
#[serde(default, skip_serializing_if = "Option::is_none")]
kind: Option<Cow<'a, str>>,
kind: Option<Cow<'static, str>>,
/// Optional custom name for the entity
#[serde(default, skip_serializing_if = "Option::is_none")]
name: Option<Box<TextComponent<'a>>>,
name: Option<Box<TextComponent>>,
},
}

View File

@ -17,37 +17,32 @@ pub mod style;
/// Represents a Text component
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct TextComponent<'a> {
pub struct TextComponent {
/// The actual text
#[serde(flatten)]
pub content: TextContent<'a>,
pub content: TextContent,
/// Style of the text. Bold, Italic, underline, Color...
/// Also has `ClickEvent
#[serde(flatten)]
pub style: Style<'a>,
pub style: Style,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
/// Extra text components
pub extra: Vec<TextComponent<'a>>,
pub extra: Vec<TextComponent>,
}
impl<'a> TextComponent<'a> {
pub fn text(text: &'a str) -> Self {
impl TextComponent {
pub fn text<P>(plain: P) -> Self
where
P: Into<Cow<'static, str>>,
{
Self {
content: TextContent::Text { text: text.into() },
content: TextContent::Text { text: plain.into() },
style: Style::default(),
extra: vec![],
}
}
pub fn text_string(text: String) -> Self {
Self {
content: TextContent::Text { text: text.into() },
style: Style::default(),
extra: vec![],
}
}
pub fn add_child(mut self, child: TextComponent<'a>) -> Self {
pub fn add_child(mut self, child: TextComponent) -> Self {
self.extra.push(child);
self
}
@ -92,7 +87,7 @@ impl<'a> TextComponent<'a> {
}
}
impl serde::Serialize for TextComponent<'_> {
impl serde::Serialize for TextComponent {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
@ -101,7 +96,7 @@ impl serde::Serialize for TextComponent<'_> {
}
}
impl<'a> TextComponent<'a> {
impl TextComponent {
pub fn color(mut self, color: Color) -> Self {
self.style.color = Some(color);
self
@ -154,13 +149,13 @@ impl<'a> TextComponent<'a> {
}
/// Allows for events to occur when the player clicks on text. Only work in chat.
pub fn click_event(mut self, event: ClickEvent<'a>) -> Self {
pub fn click_event(mut self, event: ClickEvent) -> Self {
self.style.click_event = Some(event);
self
}
/// Allows for a tooltip to be displayed when the player hovers their mouse over text.
pub fn hover_event(mut self, event: HoverEvent<'a>) -> Self {
pub fn hover_event(mut self, event: HoverEvent) -> Self {
self.style.hover_event = Some(event);
self
}
@ -184,14 +179,14 @@ impl<'a> TextComponent<'a> {
#[serde(rename_all = "camelCase")]
struct TempStruct<'a> {
#[serde(flatten)]
text: &'a TextContent<'a>,
text: &'a TextContent,
#[serde(flatten)]
style: &'a Style<'a>,
style: &'a Style,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(rename = "extra")]
extra: Vec<TempStruct<'a>>,
}
fn convert_extra<'a>(extra: &'a [TextComponent<'a>]) -> Vec<TempStruct<'a>> {
fn convert_extra(extra: &[TextComponent]) -> Vec<TempStruct<'_>> {
extra
.iter()
.map(|x| TempStruct {
@ -218,22 +213,22 @@ impl<'a> TextComponent<'a> {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(untagged)]
pub enum TextContent<'a> {
pub enum TextContent {
/// Raw Text
Text { text: Cow<'a, str> },
Text { text: Cow<'static, str> },
/// Translated text
Translate {
translate: Cow<'a, str>,
translate: Cow<'static, str>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
with: Vec<TextComponent<'a>>,
with: Vec<TextComponent>,
},
/// Displays the name of one or more entities found by a selector.
EntityNames {
selector: Cow<'a, str>,
selector: Cow<'static, str>,
#[serde(default, skip_serializing_if = "Option::is_none")]
separator: Option<Cow<'a, str>>,
separator: Option<Cow<'static, str>>,
},
/// A keybind identifier
/// https://minecraft.wiki/w/Controls#Configurable_controls
Keybind { keybind: Cow<'a, str> },
Keybind { keybind: Cow<'static, str> },
}

View File

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct Style<'a> {
pub struct Style {
/// Changes the color to render the content
#[serde(default, skip_serializing_if = "Option::is_none")]
pub color: Option<Color>,
@ -31,10 +31,10 @@ pub struct Style<'a> {
pub insertion: Option<String>,
/// Allows for events to occur when the player clicks on text. Only work in chat.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub click_event: Option<ClickEvent<'a>>,
pub click_event: Option<ClickEvent>,
/// Allows for a tooltip to be displayed when the player hovers their mouse over text.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub hover_event: Option<HoverEvent<'a>>,
pub hover_event: Option<HoverEvent>,
/// Allows you to change the font of the text.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub font: Option<String>,
@ -46,7 +46,7 @@ pub struct Style<'a> {
pub shadow_color: Option<ARGBColor>,
}
impl<'a> Style<'a> {
impl Style {
pub fn color(mut self, color: Color) -> Self {
self.color = Some(color);
self
@ -94,13 +94,13 @@ impl<'a> Style<'a> {
}
/// Allows for events to occur when the player clicks on text. Only work in chat.
pub fn click_event(mut self, event: ClickEvent<'a>) -> Self {
pub fn click_event(mut self, event: ClickEvent) -> Self {
self.click_event = Some(event);
self
}
/// Allows for a tooltip to be displayed when the player hovers their mouse over text.
pub fn hover_event(mut self, event: HoverEvent<'a>) -> Self {
pub fn hover_event(mut self, event: HoverEvent) -> Self {
self.hover_event = Some(event);
self
}

View File

@ -300,7 +300,7 @@ pub trait ByteBufMut {
fn put_string_len(&mut self, val: &str, max_size: usize);
fn put_string_array(&mut self, array: &[String]);
fn put_string_array(&mut self, array: &[&str]);
fn put_bit_set(&mut self, set: &BitSet);
@ -346,7 +346,7 @@ impl<T: BufMut> ByteBufMut for T {
self.put(val.as_bytes());
}
fn put_string_array(&mut self, array: &[String]) {
fn put_string_array(&mut self, array: &[&str]) {
for string in array {
self.put_string(string)
}

View File

@ -10,7 +10,7 @@ pub struct CConfigAddResourcePack<'a> {
url: &'a str,
hash: &'a str, // max 40
forced: bool,
prompt_message: Option<TextComponent<'a>>,
prompt_message: Option<TextComponent>,
}
impl<'a> CConfigAddResourcePack<'a> {
@ -19,7 +19,7 @@ impl<'a> CConfigAddResourcePack<'a> {
url: &'a str,
hash: &'a str,
forced: bool,
prompt_message: Option<TextComponent<'a>>,
prompt_message: Option<TextComponent>,
) -> Self {
Self {
uuid,

View File

@ -1,9 +1,9 @@
use crate::VarInt;
use pumpkin_core::text::TextComponent;
pub enum BosseventAction<'a> {
pub enum BosseventAction {
Add {
title: TextComponent<'a>,
title: TextComponent,
health: f32,
color: VarInt,
division: VarInt,
@ -11,7 +11,7 @@ pub enum BosseventAction<'a> {
},
Remove,
UpdateHealth(f32),
UpdateTile(TextComponent<'a>),
UpdateTile(TextComponent),
UpdateStyle {
color: VarInt,
dividers: VarInt,

View File

@ -6,11 +6,11 @@ use serde::Serialize;
#[derive(Serialize)]
#[client_packet("play:set_action_bar_text")]
pub struct CActionBar<'a> {
action_bar: TextComponent<'a>,
action_bar: &'a TextComponent,
}
impl<'a> CActionBar<'a> {
pub fn new(action_bar: TextComponent<'a>) -> Self {
pub fn new(action_bar: &'a TextComponent) -> Self {
Self { action_bar }
}
}

View File

@ -6,19 +6,19 @@ use pumpkin_macros::client_packet;
#[client_packet("play:boss_event")]
pub struct CBossEvent<'a> {
pub uuid: uuid::Uuid,
pub action: BosseventAction<'a>,
pub uuid: &'a uuid::Uuid,
pub action: BosseventAction,
}
impl<'a> CBossEvent<'a> {
pub fn new(uuid: uuid::Uuid, action: BosseventAction<'a>) -> Self {
pub fn new(uuid: &'a uuid::Uuid, action: BosseventAction) -> Self {
Self { uuid, action }
}
}
impl ClientPacket for CBossEvent<'_> {
fn write(&self, bytebuf: &mut impl BufMut) {
bytebuf.put_uuid(&self.uuid);
bytebuf.put_uuid(self.uuid);
let action = &self.action;
match action {
BosseventAction::Add {

View File

@ -8,11 +8,11 @@ use crate::VarInt;
#[client_packet("play:player_combat_kill")]
pub struct CCombatDeath<'a> {
player_id: VarInt,
message: TextComponent<'a>,
message: &'a TextComponent,
}
impl<'a> CCombatDeath<'a> {
pub fn new(player_id: VarInt, message: TextComponent<'a>) -> Self {
pub fn new(player_id: VarInt, message: &'a TextComponent) -> Self {
Self { player_id, message }
}
}

View File

@ -5,20 +5,15 @@ use pumpkin_macros::client_packet;
use crate::{bytebuf::ByteBufMut, ClientPacket, VarInt};
#[client_packet("play:command_suggestions")]
pub struct CCommandSuggestions<'a> {
pub struct CCommandSuggestions {
id: VarInt,
start: VarInt,
length: VarInt,
matches: Vec<CommandSuggestion<'a>>,
matches: Vec<CommandSuggestion>,
}
impl<'a> CCommandSuggestions<'a> {
pub fn new(
id: VarInt,
start: VarInt,
length: VarInt,
matches: Vec<CommandSuggestion<'a>>,
) -> Self {
impl CCommandSuggestions {
pub fn new(id: VarInt, start: VarInt, length: VarInt, matches: Vec<CommandSuggestion>) -> Self {
Self {
id,
start,
@ -28,7 +23,7 @@ impl<'a> CCommandSuggestions<'a> {
}
}
impl ClientPacket for CCommandSuggestions<'_> {
impl ClientPacket for CCommandSuggestions {
fn write(&self, bytebuf: &mut impl BufMut) {
bytebuf.put_var_int(&self.id);
bytebuf.put_var_int(&self.start);
@ -45,13 +40,13 @@ impl ClientPacket for CCommandSuggestions<'_> {
}
#[derive(PartialEq, Eq, Hash, Debug)]
pub struct CommandSuggestion<'a> {
pub struct CommandSuggestion {
pub suggestion: String,
pub tooltip: Option<TextComponent<'a>>,
pub tooltip: Option<TextComponent>,
}
impl<'a> CommandSuggestion<'a> {
pub fn new(suggestion: String, tooltip: Option<TextComponent<'a>>) -> Self {
impl CommandSuggestion {
pub fn new(suggestion: String, tooltip: Option<TextComponent>) -> Self {
Self {
suggestion,
tooltip,

View File

@ -8,18 +8,18 @@ use crate::VarInt;
#[derive(Serialize)]
#[client_packet("play:disguised_chat")]
pub struct CDisguisedChatMessage<'a> {
message: TextComponent<'a>,
message: &'a TextComponent,
chat_type: VarInt,
sender_name: TextComponent<'a>,
target_name: Option<TextComponent<'a>>,
sender_name: &'a TextComponent,
target_name: Option<&'a TextComponent>,
}
impl<'a> CDisguisedChatMessage<'a> {
pub fn new(
message: TextComponent<'a>,
message: &'a TextComponent,
chat_type: VarInt,
sender_name: TextComponent<'a>,
target_name: Option<TextComponent<'a>>,
sender_name: &'a TextComponent,
target_name: Option<&'a TextComponent>,
) -> Self {
Self {
message,

View File

@ -10,11 +10,11 @@ use crate::VarInt;
pub struct COpenScreen<'a> {
window_id: VarInt,
window_type: VarInt,
window_title: TextComponent<'a>,
window_title: &'a TextComponent,
}
impl<'a> COpenScreen<'a> {
pub fn new(window_id: VarInt, window_type: VarInt, window_title: TextComponent<'a>) -> Self {
pub fn new(window_id: VarInt, window_type: VarInt, window_title: &'a TextComponent) -> Self {
Self {
window_id,
window_type,

View File

@ -6,11 +6,11 @@ use serde::Serialize;
#[derive(Serialize)]
#[client_packet("play:disconnect")]
pub struct CPlayDisconnect<'a> {
reason: &'a TextComponent<'a>,
reason: &'a TextComponent,
}
impl<'a> CPlayDisconnect<'a> {
pub fn new(reason: &'a TextComponent<'a>) -> Self {
pub fn new(reason: &'a TextComponent) -> Self {
Self { reason }
}
}

View File

@ -17,11 +17,11 @@ pub struct CPlayerChatMessage<'a> {
salt: i64,
previous_messages_count: VarInt,
previous_messages: &'a [PreviousMessage<'a>], // max 20
unsigned_content: Option<TextComponent<'a>>,
unsigned_content: Option<TextComponent>,
filter_type: FilterType,
chat_type: VarInt,
sender_name: TextComponent<'a>,
target_name: Option<TextComponent<'a>>,
sender_name: TextComponent,
target_name: Option<TextComponent>,
}
impl<'a> CPlayerChatMessage<'a> {
@ -34,11 +34,11 @@ impl<'a> CPlayerChatMessage<'a> {
timestamp: i64,
salt: i64,
previous_messages: &'a [PreviousMessage<'a>],
unsigned_content: Option<TextComponent<'a>>,
unsigned_content: Option<TextComponent>,
filter_type: FilterType,
chat_type: VarInt,
sender_name: TextComponent<'a>,
target_name: Option<TextComponent<'a>>,
sender_name: TextComponent,
target_name: Option<TextComponent>,
) -> Self {
Self {
sender,

View File

@ -6,11 +6,11 @@ use serde::Serialize;
#[derive(Serialize)]
#[client_packet("play:set_title_text")]
pub struct CTitleText<'a> {
title: TextComponent<'a>,
title: &'a TextComponent,
}
impl<'a> CTitleText<'a> {
pub fn new(title: TextComponent<'a>) -> Self {
pub fn new(title: &'a TextComponent) -> Self {
Self { title }
}
}

View File

@ -6,11 +6,11 @@ use serde::Serialize;
#[derive(Serialize)]
#[client_packet("play:set_subtitle_text")]
pub struct CSubtitle<'a> {
subtitle: TextComponent<'a>,
subtitle: &'a TextComponent,
}
impl<'a> CSubtitle<'a> {
pub fn new(subtitle: TextComponent<'a>) -> Self {
pub fn new(subtitle: &'a TextComponent) -> Self {
Self { subtitle }
}
}

View File

@ -6,12 +6,12 @@ use serde::Serialize;
#[derive(Serialize)]
#[client_packet("play:system_chat")]
pub struct CSystemChatMessage<'a> {
content: &'a TextComponent<'a>,
content: &'a TextComponent,
overlay: bool,
}
impl<'a> CSystemChatMessage<'a> {
pub fn new(content: &'a TextComponent<'a>, overlay: bool) -> Self {
pub fn new(content: &'a TextComponent, overlay: bool) -> Self {
Self { content, overlay }
}
}

View File

@ -8,18 +8,18 @@ use crate::{bytebuf::ByteBufMut, ClientPacket, NumberFormat, VarInt};
pub struct CUpdateObjectives<'a> {
objective_name: &'a str,
mode: u8,
display_name: TextComponent<'a>,
display_name: TextComponent,
render_type: VarInt,
number_format: Option<NumberFormat<'a>>,
number_format: Option<NumberFormat>,
}
impl<'a> CUpdateObjectives<'a> {
pub fn new(
objective_name: &'a str,
mode: Mode,
display_name: TextComponent<'a>,
display_name: TextComponent,
render_type: RenderType,
number_format: Option<NumberFormat<'a>>,
number_format: Option<NumberFormat>,
) -> Self {
Self {
objective_name,

View File

@ -11,8 +11,8 @@ pub struct CUpdateScore<'a> {
entity_name: &'a str,
objective_name: &'a str,
value: VarInt,
display_name: Option<TextComponent<'a>>,
number_format: Option<NumberFormat<'a>>,
display_name: Option<TextComponent>,
number_format: Option<NumberFormat>,
}
impl<'a> CUpdateScore<'a> {
@ -20,8 +20,8 @@ impl<'a> CUpdateScore<'a> {
entity_name: &'a str,
objective_name: &'a str,
value: VarInt,
display_name: Option<TextComponent<'a>>,
number_format: Option<NumberFormat<'a>>,
display_name: Option<TextComponent>,
number_format: Option<NumberFormat>,
) -> Self {
Self {
entity_name,

View File

@ -160,13 +160,13 @@ pub struct KnownPack<'a> {
}
#[derive(Serialize)]
pub enum NumberFormat<'a> {
pub enum NumberFormat {
/// Show nothing
Blank,
/// The styling to be used when formatting the score number
Styled(Style<'a>),
Styled(Style),
/// The text to be used as placeholder.
Fixed(TextComponent<'a>),
Fixed(TextComponent),
}
#[derive(Debug, PartialEq, Eq, Hash)]
@ -202,12 +202,12 @@ impl PositionFlag {
}
}
pub enum Label<'a> {
pub enum Label {
BuiltIn(LinkType),
TextComponent(TextComponent<'a>),
TextComponent(TextComponent),
}
impl Serialize for Label<'_> {
impl Serialize for Label {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
@ -222,12 +222,12 @@ impl Serialize for Label<'_> {
#[derive(Serialize)]
pub struct Link<'a> {
pub is_built_in: bool,
pub label: Label<'a>,
pub label: Label,
pub url: &'a String,
}
impl<'a> Link<'a> {
pub fn new(label: Label<'a>, url: &'a String) -> Self {
pub fn new(label: Label, url: &'a String) -> Self {
Self {
is_built_in: match label {
Label::BuiltIn(_) => true,

View File

@ -11,6 +11,6 @@ pub struct ChatType {
pub struct Decoration {
translation_key: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
style: Option<Style<'static>>,
style: Option<Style>,
parameters: Vec<String>,
}

View File

@ -45,7 +45,7 @@ impl ArgumentConsumer for BlockArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -42,7 +42,7 @@ impl ArgumentConsumer for BoolArgConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -53,7 +53,7 @@ impl ArgumentConsumer for BossbarColorArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
let colors = ["blue", "green", "pink", "purple", "red", "white", "yellow"];
let suggestions: Vec<CommandSuggestion> = colors
.iter()

View File

@ -51,7 +51,7 @@ impl ArgumentConsumer for BossbarStyleArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
let styles = [
"notched_10",
"notched_12",

View File

@ -52,7 +52,7 @@ where
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -48,7 +48,7 @@ impl ArgumentConsumer for CommandTreeArgumentConsumer {
_sender: &CommandSender<'a>,
server: &'a Server,
input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
let Some(input) = input.split_single_whitespace_including_empty_parts().last() else {
return Ok(None);
};

View File

@ -51,7 +51,7 @@ impl ArgumentConsumer for EntitiesArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -73,7 +73,7 @@ impl ArgumentConsumer for EntityArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -54,7 +54,7 @@ impl ArgumentConsumer for GamemodeArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -43,7 +43,7 @@ impl ArgumentConsumer for ItemArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -49,7 +49,7 @@ impl ArgumentConsumer for MsgArgConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -67,7 +67,7 @@ impl ArgumentConsumer for PlayersArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -49,7 +49,7 @@ impl ArgumentConsumer for Position2DArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -46,7 +46,7 @@ impl ArgumentConsumer for Position3DArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -47,7 +47,7 @@ impl ArgumentConsumer for BlockPosArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -40,7 +40,7 @@ impl ArgumentConsumer for ResourceLocationArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
if !self.autocomplete {
return Ok(None);
}

View File

@ -55,7 +55,7 @@ impl ArgumentConsumer for RotationArgumentConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -43,7 +43,7 @@ impl ArgumentConsumer for SimpleArgConsumer {
_sender: &CommandSender<'a>,
_server: &'a Server,
_input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
Ok(None)
}
}

View File

@ -577,14 +577,12 @@ pub fn init_command_tree() -> CommandTree {
}
async fn send_success_message(sender: &CommandSender<'_>, message: String) {
sender
.send_message(TextComponent::text(message.as_str()))
.await;
sender.send_message(TextComponent::text(message)).await;
}
async fn send_error_message(sender: &CommandSender<'_>, message: String) {
sender
.send_message(TextComponent::text(message.as_str()).color(Color::Named(NamedColor::Red)))
.send_message(TextComponent::text(message).color(Color::Named(NamedColor::Red)))
.await;
}

View File

@ -36,20 +36,20 @@ async fn clear_player(target: &Player) -> usize {
fn clear_command_text_output(item_count: usize, targets: &[Arc<Player>]) -> TextComponent {
match targets {
[target] if item_count == 0 => TextComponent::text_string(format!(
[target] if item_count == 0 => TextComponent::text(format!(
"No items were found on player {}",
target.gameprofile.name
))
.color_named(NamedColor::Red),
[target] => TextComponent::text_string(format!(
[target] => TextComponent::text(format!(
"Removed {} item(s) on player {}",
item_count, target.gameprofile.name
)),
targets if item_count == 0 => {
TextComponent::text_string(format!("No items were found on {} players", targets.len()))
TextComponent::text(format!("No items were found on {} players", targets.len()))
.color_named(NamedColor::Red)
}
targets => TextComponent::text_string(format!(
targets => TextComponent::text(format!(
"Removed {item_count} item(s) from {} players",
targets.len()
)),

View File

@ -144,7 +144,7 @@ impl CommandExecutor for SetblockExecutor {
};
sender
.send_message(TextComponent::text_string(format!(
.send_message(TextComponent::text(format!(
"Placed {} blocks of {} from {from} to {to}",
placed_blocks, block.name
)))

View File

@ -40,14 +40,14 @@ impl CommandExecutor for GamemodeTargetSelf {
if let Player(target) = sender {
if target.gamemode.load() == gamemode {
target
.send_system_message(&TextComponent::text(&format!(
.send_system_message(&TextComponent::text(format!(
"You already in {gamemode:?} gamemode"
)))
.await;
} else {
target.set_gamemode(gamemode).await;
target
.send_system_message(&TextComponent::text(&format!(
.send_system_message(&TextComponent::text(format!(
"Game mode was set to {gamemode:?}"
)))
.await;
@ -82,7 +82,7 @@ impl CommandExecutor for GamemodeTargetPlayer {
if target.gamemode.load() == gamemode {
if target_count == 1 {
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"{} is already in {:?} gamemode",
target.gameprofile.name, gamemode
)))
@ -92,7 +92,7 @@ impl CommandExecutor for GamemodeTargetPlayer {
target.set_gamemode(gamemode).await;
if target_count == 1 {
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"{}'s Game mode was set to {:?}",
target.gameprofile.name, gamemode
)))

View File

@ -56,7 +56,7 @@ impl CommandExecutor for GiveExecutor {
}
sender
.send_message(TextComponent::text_string(match targets {
.send_message(TextComponent::text(match targets {
[target] => format!(
"Gave {item_count} {} to {}",
item_name, target.gameprofile.name

View File

@ -48,12 +48,12 @@ impl CommandExecutor for CommandHelpExecutor {
let mut message = TextComponent::text("")
.add_child(
TextComponent::text_string("-".repeat((52 - header_text.len()) / 2) + " ")
TextComponent::text("-".repeat((52 - header_text.len()) / 2) + " ")
.color_named(NamedColor::Yellow),
)
.add_child(TextComponent::text(&header_text))
.add_child(TextComponent::text(header_text.clone()))
.add_child(
TextComponent::text_string(
TextComponent::text(
" ".to_owned() + &"-".repeat((52 - header_text.len()) / 2) + "\n",
)
.color_named(NamedColor::Yellow),
@ -62,7 +62,7 @@ impl CommandExecutor for CommandHelpExecutor {
TextComponent::text("Command: ")
.color_named(NamedColor::Aqua)
.add_child(
TextComponent::text_string(format!("/{command_names}"))
TextComponent::text(format!("/{command_names}"))
.color_named(NamedColor::Gold)
.bold(),
)
@ -75,7 +75,7 @@ impl CommandExecutor for CommandHelpExecutor {
TextComponent::text("Description: ")
.color_named(NamedColor::Aqua)
.add_child(
TextComponent::text_string(format!("{description}\n"))
TextComponent::text(format!("{description}\n"))
.color_named(NamedColor::White),
),
)
@ -83,14 +83,13 @@ impl CommandExecutor for CommandHelpExecutor {
TextComponent::text("Usage: ")
.color_named(NamedColor::Aqua)
.add_child(
TextComponent::text_string(format!("{usage}\n"))
.color_named(NamedColor::White),
TextComponent::text(format!("{usage}\n")).color_named(NamedColor::White),
)
.click_event(ClickEvent::SuggestCommand(format!("{tree}").into())),
);
message = message
.add_child(TextComponent::text_string("-".repeat(52)).color_named(NamedColor::Yellow));
message =
message.add_child(TextComponent::text("-".repeat(52)).color_named(NamedColor::Yellow));
sender.send_message(message).await;
@ -165,14 +164,14 @@ impl CommandExecutor for BaseHelpExecutor {
let mut message = TextComponent::text("")
.add_child(
TextComponent::text_string("-".repeat((52 - header_text.len() - 3) / 2) + " ")
TextComponent::text("-".repeat((52 - header_text.len() - 3) / 2) + " ")
.color_named(NamedColor::Yellow),
)
.add_child(arrow_left.clone())
.add_child(TextComponent::text(&header_text))
.add_child(TextComponent::text(header_text.clone()))
.add_child(arrow_right.clone())
.add_child(
TextComponent::text_string(
TextComponent::text(
" ".to_owned() + &"-".repeat((52 - header_text.len() - 3) / 2) + "\n",
)
.color_named(NamedColor::Yellow),
@ -180,17 +179,16 @@ impl CommandExecutor for BaseHelpExecutor {
for tree in page_commands {
message = message.add_child(
TextComponent::text_string("/".to_owned() + &tree.names.join(", /"))
TextComponent::text("/".to_owned() + &tree.names.join(", /"))
.color_named(NamedColor::Gold)
.add_child(TextComponent::text(" - ").color_named(NamedColor::Yellow))
.add_child(
TextComponent::text_string(tree.description.clone() + "\n")
TextComponent::text(tree.description.clone() + "\n")
.color_named(NamedColor::White),
)
.add_child(TextComponent::text(" Usage: ").color_named(NamedColor::Yellow))
.add_child(
TextComponent::text_string(format!("{tree}"))
.color_named(NamedColor::White),
TextComponent::text(format!("{tree}")).color_named(NamedColor::White),
)
.add_child(TextComponent::text("\n").color_named(NamedColor::White))
.click_event(ClickEvent::SuggestCommand(
@ -202,16 +200,14 @@ impl CommandExecutor for BaseHelpExecutor {
let footer_text = format!(" Page {page}/{total_pages} ");
message = message
.add_child(
TextComponent::text_string("-".repeat((52 - footer_text.len() - 3) / 2) + " ")
TextComponent::text("-".repeat((52 - footer_text.len() - 3) / 2) + " ")
.color_named(NamedColor::Yellow),
)
.add_child(arrow_left)
.add_child(TextComponent::text(&footer_text))
.add_child(TextComponent::text(footer_text.clone()))
.add_child(arrow_right)
.add_child(
TextComponent::text_string(
" ".to_owned() + &"-".repeat((52 - footer_text.len() - 3) / 2),
)
TextComponent::text(" ".to_owned() + &"-".repeat((52 - footer_text.len() - 3) / 2))
.color_named(NamedColor::Yellow),
);

View File

@ -40,7 +40,7 @@ impl CommandExecutor for KickExecutor {
let msg = if target_count == 1 {
TextComponent::text("Player has been kicked.")
} else {
TextComponent::text_string(format!("{target_count} players have been kicked."))
TextComponent::text(format!("{target_count} players have been kicked."))
};
sender.send_message(msg.color_named(NamedColor::Blue)).await;

View File

@ -37,7 +37,7 @@ impl CommandExecutor for KillExecutor {
let msg = if target_count == 1 {
TextComponent::text("Entity has been killed.")
} else {
TextComponent::text_string(format!("{target_count} entities have been killed."))
TextComponent::text(format!("{target_count} entities have been killed."))
};
sender.send_message(msg.color_named(NamedColor::Blue)).await;

View File

@ -28,9 +28,9 @@ impl CommandExecutor for ListExecutor {
let players: Vec<Arc<Player>> = server.get_all_players().await;
let message = if players.is_empty() {
"There are no players online."
"There are no players online.".to_owned()
} else {
&format!(
format!(
"There are {} of a max of {} players online: {}",
players.len(),
BASIC_CONFIG.max_players,

View File

@ -63,7 +63,7 @@ impl CommandExecutor for OpExecutor {
let player_name = player.gameprofile.name.clone();
let message = format!("Made {player_name} a server operator.");
let msg = TextComponent::text(&message);
let msg = TextComponent::text(message);
sender.send_message(msg).await;
}

View File

@ -32,14 +32,14 @@ impl CommandExecutor for PumpkinExecutor {
) -> Result<(), CommandError> {
sender
.send_message(
TextComponent::text(&format!("Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION})"))
TextComponent::text(format!("Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION})"))
.hover_event(HoverEvent::ShowText(Cow::from("Click to Copy Version")))
.click_event(ClickEvent::CopyToClipboard(Cow::from(format!(
"Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION})"
))))
.color_named(NamedColor::Green)
.add_child(
TextComponent::text(&format!(", {CARGO_PKG_DESCRIPTION}"))
TextComponent::text(format!(", {CARGO_PKG_DESCRIPTION}"))
.click_event(ClickEvent::CopyToClipboard(Cow::from(
CARGO_PKG_DESCRIPTION,
)))
@ -49,7 +49,7 @@ impl CommandExecutor for PumpkinExecutor {
.color_named(NamedColor::White),
)
.add_child(
TextComponent::text(&format!(
TextComponent::text(format!(
" (Minecraft {CURRENT_MC_VERSION}, Protocol {CURRENT_MC_PROTOCOL})"
))
.click_event(ClickEvent::CopyToClipboard(Cow::from(format!(

View File

@ -32,7 +32,7 @@ impl CommandExecutor for SayExecutor {
server
.broadcast_packet_all(&CSystemChatMessage::new(
&TextComponent::text(&format!("[{sender}] {msg}")),
&TextComponent::text(format!("[{sender}] {msg}")),
false,
))
.await;

View File

@ -38,7 +38,7 @@ impl CommandExecutor for PumpkinExecutor {
.send_message(
TextComponent::text("Seed: [")
.add_child(
TextComponent::text(&seed.clone())
TextComponent::text(seed.clone())
.hover_event(HoverEvent::ShowText(Cow::from(
"Click to Copy to Clipboard",
)))

View File

@ -67,10 +67,9 @@ impl CommandExecutor for SetblockExecutor {
sender
.send_message(if success {
TextComponent::text_string(format!("Placed block {} at {pos}", block.name,))
TextComponent::text(format!("Placed block {} at {pos}", block.name,))
} else {
TextComponent::text_string(format!("Kept block at {pos}"))
.color_named(NamedColor::Red)
TextComponent::text(format!("Kept block at {pos}")).color_named(NamedColor::Red)
})
.await;

View File

@ -66,7 +66,7 @@ impl CommandExecutor for TimeQueryExecutor {
}
};
sender.send_message(TextComponent::text(&msg)).await;
sender.send_message(TextComponent::text(msg)).await;
Ok(())
}
}
@ -117,7 +117,7 @@ impl CommandExecutor for TimeChangeExecutor {
}
};
sender.send_message(TextComponent::text(&msg)).await;
sender.send_message(TextComponent::text(msg)).await;
Ok(())
}
}

View File

@ -65,7 +65,7 @@ impl CommandExecutor for WorldborderGetExecutor {
let diameter = border.new_diameter.round() as i32;
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"The world border is currently {diameter} block(s) wide"
)))
.await;
@ -92,7 +92,7 @@ impl CommandExecutor for WorldborderSetExecutor {
let Ok(distance) = distance_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
distance_consumer().default_name()
))
@ -113,7 +113,7 @@ impl CommandExecutor for WorldborderSetExecutor {
}
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Set the world border to {distance:.1} block(s) wide"
)))
.await;
@ -141,7 +141,7 @@ impl CommandExecutor for WorldborderSetTimeExecutor {
let Ok(distance) = distance_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
distance_consumer().default_name()
))
@ -153,7 +153,7 @@ impl CommandExecutor for WorldborderSetTimeExecutor {
let Ok(time) = time_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
time_consumer().default_name()
))
@ -176,11 +176,11 @@ impl CommandExecutor for WorldborderSetTimeExecutor {
return Ok(());
}
std::cmp::Ordering::Less => {
sender.send_message(TextComponent::text(&format!("Shrinking the world border to {distance:.2} blocks wide over {time} second(s)"))).await;
sender.send_message(TextComponent::text(format!("Shrinking the world border to {distance:.2} blocks wide over {time} second(s)"))).await;
}
std::cmp::Ordering::Greater => {
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Growing the world border to {distance:.2} blocks wide over {time} seconds"
)))
.await;
@ -213,7 +213,7 @@ impl CommandExecutor for WorldborderAddExecutor {
let Ok(distance) = distance_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
distance_consumer().default_name()
))
@ -236,7 +236,7 @@ impl CommandExecutor for WorldborderAddExecutor {
let distance = border.new_diameter + distance;
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Set the world border to {distance:.1} block(s) wide"
)))
.await;
@ -264,7 +264,7 @@ impl CommandExecutor for WorldborderAddTimeExecutor {
let Ok(distance) = distance_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
distance_consumer().default_name()
))
@ -276,7 +276,7 @@ impl CommandExecutor for WorldborderAddTimeExecutor {
let Ok(time) = time_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
time_consumer().default_name()
))
@ -301,11 +301,11 @@ impl CommandExecutor for WorldborderAddTimeExecutor {
return Ok(());
}
std::cmp::Ordering::Less => {
sender.send_message(TextComponent::text(&format!("Shrinking the world border to {distance:.2} blocks wide over {time} second(s)"))).await;
sender.send_message(TextComponent::text(format!("Shrinking the world border to {distance:.2} blocks wide over {time} second(s)"))).await;
}
std::cmp::Ordering::Greater => {
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Growing the world border to {distance:.2} blocks wide over {time} seconds"
)))
.await;
@ -338,7 +338,7 @@ impl CommandExecutor for WorldborderCenterExecutor {
let Vector2 { x, z } = Position2DArgumentConsumer.find_arg_default_name(args)?;
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Set the center of world border to {x:.2}, {z:.2}"
)))
.await;
@ -366,7 +366,7 @@ impl CommandExecutor for WorldborderDamageAmountExecutor {
let Ok(damage_per_block) = damage_per_block_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
damage_per_block_consumer().default_name()
))
@ -389,7 +389,7 @@ impl CommandExecutor for WorldborderDamageAmountExecutor {
}
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Set the world border damage to {damage_per_block:.2} per block each second"
)))
.await;
@ -417,7 +417,7 @@ impl CommandExecutor for WorldborderDamageBufferExecutor {
let Ok(buffer) = damage_buffer_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
damage_buffer_consumer().default_name()
))
@ -440,7 +440,7 @@ impl CommandExecutor for WorldborderDamageBufferExecutor {
}
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Set the world border damage buffer to {buffer:.2} block(s)"
)))
.await;
@ -468,7 +468,7 @@ impl CommandExecutor for WorldborderWarningDistanceExecutor {
let Ok(distance) = warning_distance_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
warning_distance_consumer().default_name()
))
@ -491,7 +491,7 @@ impl CommandExecutor for WorldborderWarningDistanceExecutor {
}
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Set the world border warning distance to {distance} block(s)"
)))
.await;
@ -519,7 +519,7 @@ impl CommandExecutor for WorldborderWarningTimeExecutor {
let Ok(time) = time_consumer().find_arg_default_name(args)? else {
sender
.send_message(
TextComponent::text_string(format!(
TextComponent::text(format!(
"{} is out of bounds.",
time_consumer().default_name()
))
@ -542,7 +542,7 @@ impl CommandExecutor for WorldborderWarningTimeExecutor {
}
sender
.send_message(TextComponent::text(&format!(
.send_message(TextComponent::text(format!(
"Set the world border warning time to {time} second(s)"
)))
.await;

View File

@ -71,7 +71,7 @@ impl CommandDispatcher {
Ok(err) => {
sender
.send_message(
TextComponent::text_string(err)
TextComponent::text(err)
.color_named(pumpkin_core::text::color::NamedColor::Red),
)
.await;
@ -94,7 +94,7 @@ impl CommandDispatcher {
src: &mut CommandSender<'a>,
server: &'a Server,
cmd: &'a str,
) -> Vec<CommandSuggestion<'a>> {
) -> Vec<CommandSuggestion> {
let mut parts = cmd.split_whitespace();
let Some(key) = parts.next() else {
return Vec::new();
@ -254,7 +254,7 @@ impl CommandDispatcher {
tree: &'a CommandTree,
raw_args: &mut RawArgs<'a>,
input: &'a str,
) -> Result<Option<Vec<CommandSuggestion<'a>>>, CommandError> {
) -> Result<Option<Vec<CommandSuggestion>>, CommandError> {
let mut parsed_args: ConsumedArgs = HashMap::new();
for node in path.iter().map(|&i| &tree.nodes[i]) {

View File

@ -48,7 +48,7 @@ impl fmt::Display for CommandSender<'_> {
}
impl<'a> CommandSender<'a> {
pub async fn send_message(&self, text: TextComponent<'a>) {
pub async fn send_message(&self, text: TextComponent) {
match self {
CommandSender::Console => log::info!("{}", text.to_pretty_console()),
CommandSender::Player(c) => c.send_system_message(&text).await,

View File

@ -524,7 +524,7 @@ impl Player {
}
/// Kicks the Client with a reason depending on the connection state
pub async fn kick<'a>(&self, reason: TextComponent<'a>) {
pub async fn kick(&self, reason: TextComponent) {
if self
.client
.closed
@ -565,7 +565,7 @@ impl Player {
self.client
.send_packet(&CCombatDeath::new(
self.entity_id().into(),
TextComponent::text("noob"),
&TextComponent::text("noob"),
))
.await;
}
@ -640,7 +640,7 @@ impl Player {
.await;
}
pub async fn send_system_message<'a>(&self, text: &TextComponent<'a>) {
pub async fn send_system_message(&self, text: &TextComponent) {
self.client
.send_packet(&CSystemChatMessage::new(text, false))
.await;
@ -662,9 +662,9 @@ impl Player {
Err(e) => {
if e.is_kick() {
if let Some(kick_reason) = e.client_kick_reason() {
self.kick(TextComponent::text(&kick_reason)).await;
self.kick(TextComponent::text(kick_reason)).await;
} else {
self.kick(TextComponent::text(&format!(
self.kick(TextComponent::text(format!(
"Error while reading incoming packet {e}"
)))
.await;

View File

@ -39,7 +39,7 @@ impl Player {
.send_packet(&COpenScreen::new(
inventory.total_opened_containers.into(),
VarInt(window_type as i32),
title,
&title,
))
.await;
drop(inventory);

View File

@ -576,7 +576,9 @@ impl Client {
ConnectionState::Config => self.try_send_packet(&CConfigDisconnect::new(reason)).await,
// This way players get kicked when players using client functions (e.g. poll, send_packet)
ConnectionState::Play => {
self.try_send_packet(&CPlayDisconnect::new(&TextComponent::text(reason)))
self.try_send_packet(&CPlayDisconnect::new(&TextComponent::text(
reason.to_owned(),
)))
.await
}
_ => {

View File

@ -523,10 +523,10 @@ impl Player {
chat_message.timestamp,
chat_message.salt,
&[],
Some(TextComponent::text(&message)),
Some(TextComponent::text(message.clone())),
FilterType::PassThrough,
1.into(),
TextComponent::text(&gameprofile.name),
TextComponent::text(gameprofile.name.clone()),
None,
))
.await;

View File

@ -63,32 +63,32 @@ impl Player {
// Maybe this section could be implemented. feel free to change
let bossbar = bossbar.clone();
let boss_action = BosseventAction::Add {
title: TextComponent::text_string(bossbar.title),
title: TextComponent::text(bossbar.title),
health: bossbar.health,
color: (bossbar.color as u8).into(),
division: (bossbar.division as u8).into(),
flags: bossbar.flags as u8,
};
let packet = CBossEvent::new(bossbar.uuid, boss_action);
let packet = CBossEvent::new(&bossbar.uuid, boss_action);
self.client.send_packet(&packet).await;
}
pub async fn remove_bossbar(&self, uuid: Uuid) {
let boss_action = BosseventAction::Remove;
let packet = CBossEvent::new(uuid, boss_action);
let packet = CBossEvent::new(&uuid, boss_action);
self.client.send_packet(&packet).await;
}
pub async fn update_bossbar_health(&self, uuid: Uuid, health: f32) {
pub async fn update_bossbar_health(&self, uuid: &Uuid, health: f32) {
let boss_action = BosseventAction::UpdateHealth(health);
let packet = CBossEvent::new(uuid, boss_action);
self.client.send_packet(&packet).await;
}
pub async fn update_bossbar_title(&self, uuid: Uuid, title: String) {
let boss_action = BosseventAction::UpdateTile(TextComponent::text_string(title));
pub async fn update_bossbar_title(&self, uuid: &Uuid, title: String) {
let boss_action = BosseventAction::UpdateTile(TextComponent::text(title));
let packet = CBossEvent::new(uuid, boss_action);
self.client.send_packet(&packet).await;
@ -96,7 +96,7 @@ impl Player {
pub async fn update_bossbar_style(
&self,
uuid: Uuid,
uuid: &Uuid,
color: BossbarColor,
dividers: BossbarDivisions,
) {
@ -109,7 +109,7 @@ impl Player {
self.client.send_packet(&packet).await;
}
pub async fn update_bossbar_flags(&self, uuid: Uuid, flags: BossbarFlags) {
pub async fn update_bossbar_flags(&self, uuid: &Uuid, flags: BossbarFlags) {
let boss_action = BosseventAction::UpdateFlags(flags as u8);
let packet = CBossEvent::new(uuid, boss_action);

View File

@ -178,7 +178,7 @@ impl CustomBossbars {
.collect();
for player in matching_players {
player
.update_bossbar_health(bossbar.bossbar_data.uuid, bossbar.bossbar_data.health)
.update_bossbar_health(&bossbar.bossbar_data.uuid, bossbar.bossbar_data.health)
.await;
}
@ -260,7 +260,7 @@ impl CustomBossbars {
for player in matching_players {
player
.update_bossbar_title(
bossbar.bossbar_data.uuid,
&bossbar.bossbar_data.uuid,
bossbar.bossbar_data.title.clone(),
)
.await;
@ -301,7 +301,7 @@ impl CustomBossbars {
for player in matching_players {
player
.update_bossbar_style(
bossbar.bossbar_data.uuid,
&bossbar.bossbar_data.uuid,
bossbar.bossbar_data.color.clone(),
bossbar.bossbar_data.division.clone(),
)
@ -343,7 +343,7 @@ impl CustomBossbars {
for player in matching_players {
player
.update_bossbar_style(
bossbar.bossbar_data.uuid,
&bossbar.bossbar_data.uuid,
bossbar.bossbar_data.color.clone(),
bossbar.bossbar_data.division.clone(),
)

View File

@ -722,7 +722,7 @@ impl World {
// Handle join message
// TODO: Config
let msg_txt = format!("{} joined the game.", player.gameprofile.name.as_str());
let msg_comp = TextComponent::text(msg_txt.as_str()).color_named(NamedColor::Yellow);
let msg_comp = TextComponent::text(msg_txt).color_named(NamedColor::Yellow);
for player in current_players.values() {
player.send_system_message(&msg_comp).await;
}
@ -764,8 +764,7 @@ impl World {
// Send disconnect message / quit message to players in the same world
// TODO: Config
let disconn_msg_txt = format!("{} left the game.", player.gameprofile.name.as_str());
let disconn_msg_cmp =
TextComponent::text(disconn_msg_txt.as_str()).color_named(NamedColor::Yellow);
let disconn_msg_cmp = TextComponent::text(disconn_msg_txt).color_named(NamedColor::Yellow);
for player in self.current_players.lock().await.values() {
player.send_system_message(&disconn_msg_cmp).await;
}

View File

@ -78,18 +78,18 @@ impl Scoreboard {
pub struct ScoreboardObjective<'a> {
name: &'a str,
display_name: TextComponent<'a>,
display_name: TextComponent,
render_type: RenderType,
number_format: Option<NumberFormat<'a>>,
number_format: Option<NumberFormat>,
}
impl<'a> ScoreboardObjective<'a> {
#[must_use]
pub const fn new(
name: &'a str,
display_name: TextComponent<'a>,
display_name: TextComponent,
render_type: RenderType,
number_format: Option<NumberFormat<'a>>,
number_format: Option<NumberFormat>,
) -> Self {
Self {
name,
@ -104,8 +104,8 @@ pub struct ScoreboardScore<'a> {
entity_name: &'a str,
objective_name: &'a str,
value: VarInt,
display_name: Option<TextComponent<'a>>,
number_format: Option<NumberFormat<'a>>,
display_name: Option<TextComponent>,
number_format: Option<NumberFormat>,
}
impl<'a> ScoreboardScore<'a> {
@ -114,8 +114,8 @@ impl<'a> ScoreboardScore<'a> {
entity_name: &'a str,
objective_name: &'a str,
value: VarInt,
display_name: Option<TextComponent<'a>>,
number_format: Option<NumberFormat<'a>>,
display_name: Option<TextComponent>,
number_format: Option<NumberFormat>,
) -> Self {
Self {
entity_name,