From f772d971f635cfd96fca0492cc7f2959f3190d3b Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Mon, 30 Dec 2024 13:10:02 +0100 Subject: [PATCH] Remove lifetime from TextComponent --- pumpkin-core/src/text/click.rs | 12 ++-- pumpkin-core/src/text/hover.rs | 12 ++-- pumpkin-core/src/text/mod.rs | 55 +++++++++---------- pumpkin-core/src/text/style.rs | 12 ++-- pumpkin-protocol/src/bytebuf/mod.rs | 4 +- .../src/client/config/c_add_resource_pack.rs | 4 +- .../src/client/play/bossevent_action.rs | 6 +- .../src/client/play/c_actionbar.rs | 4 +- .../src/client/play/c_boss_event.rs | 8 +-- .../src/client/play/c_combat_death.rs | 4 +- .../src/client/play/c_command_suggestions.rs | 23 +++----- .../client/play/c_disguised_chat_message.rs | 12 ++-- .../src/client/play/c_open_screen.rs | 4 +- .../src/client/play/c_play_disconnect.rs | 4 +- .../src/client/play/c_player_chat_message.rs | 12 ++-- .../src/client/play/c_set_title.rs | 4 +- .../src/client/play/c_subtitle.rs | 4 +- .../src/client/play/c_system_chat_message.rs | 4 +- .../src/client/play/c_update_objectives.rs | 8 +-- .../src/client/play/c_update_score.rs | 8 +-- pumpkin-protocol/src/lib.rs | 16 +++--- pumpkin-registry/src/chat_type.rs | 2 +- pumpkin/src/command/args/arg_block.rs | 2 +- pumpkin/src/command/args/arg_bool.rs | 2 +- pumpkin/src/command/args/arg_bossbar_color.rs | 2 +- pumpkin/src/command/args/arg_bossbar_style.rs | 2 +- pumpkin/src/command/args/arg_bounded_num.rs | 2 +- pumpkin/src/command/args/arg_command.rs | 2 +- pumpkin/src/command/args/arg_entities.rs | 2 +- pumpkin/src/command/args/arg_entity.rs | 2 +- pumpkin/src/command/args/arg_gamemode.rs | 2 +- pumpkin/src/command/args/arg_item.rs | 2 +- pumpkin/src/command/args/arg_message.rs | 2 +- pumpkin/src/command/args/arg_players.rs | 2 +- pumpkin/src/command/args/arg_position_2d.rs | 2 +- pumpkin/src/command/args/arg_position_3d.rs | 2 +- .../src/command/args/arg_position_block.rs | 2 +- .../src/command/args/arg_resource_location.rs | 2 +- pumpkin/src/command/args/arg_rotation.rs | 2 +- pumpkin/src/command/args/arg_simple.rs | 2 +- pumpkin/src/command/commands/cmd_bossbar.rs | 6 +- pumpkin/src/command/commands/cmd_clear.rs | 8 +-- pumpkin/src/command/commands/cmd_fill.rs | 2 +- pumpkin/src/command/commands/cmd_gamemode.rs | 8 +-- pumpkin/src/command/commands/cmd_give.rs | 2 +- pumpkin/src/command/commands/cmd_help.rs | 40 ++++++-------- pumpkin/src/command/commands/cmd_kick.rs | 2 +- pumpkin/src/command/commands/cmd_kill.rs | 2 +- pumpkin/src/command/commands/cmd_list.rs | 4 +- pumpkin/src/command/commands/cmd_op.rs | 2 +- pumpkin/src/command/commands/cmd_pumpkin.rs | 6 +- pumpkin/src/command/commands/cmd_say.rs | 2 +- pumpkin/src/command/commands/cmd_seed.rs | 2 +- pumpkin/src/command/commands/cmd_setblock.rs | 5 +- pumpkin/src/command/commands/cmd_time.rs | 4 +- .../src/command/commands/cmd_worldborder.rs | 44 +++++++-------- pumpkin/src/command/dispatcher.rs | 6 +- pumpkin/src/command/mod.rs | 2 +- pumpkin/src/entity/player.rs | 10 ++-- pumpkin/src/net/container.rs | 2 +- pumpkin/src/net/mod.rs | 6 +- pumpkin/src/net/packet/play.rs | 4 +- pumpkin/src/world/bossbar.rs | 16 +++--- pumpkin/src/world/custom_bossbar.rs | 8 +-- pumpkin/src/world/mod.rs | 5 +- pumpkin/src/world/scoreboard.rs | 16 +++--- 66 files changed, 228 insertions(+), 244 deletions(-) diff --git a/pumpkin-core/src/text/click.rs b/pumpkin-core/src/text/click.rs index caa78f61d..a9b2f4c1f 100644 --- a/pumpkin-core/src/text/click.rs +++ b/pumpkin-core/src/text/click.rs @@ -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>), } diff --git a/pumpkin-core/src/text/hover.rs b/pumpkin-core/src/text/hover.rs index 35182e8e3..796ec912e 100644 --- a/pumpkin-core/src/text/hover.rs +++ b/pumpkin-core/src/text/hover.rs @@ -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, /// 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>, + kind: Option>, /// Optional custom name for the entity #[serde(default, skip_serializing_if = "Option::is_none")] - name: Option>>, + name: Option>, }, } diff --git a/pumpkin-core/src/text/mod.rs b/pumpkin-core/src/text/mod.rs index f94e39563..73a0183ac 100644 --- a/pumpkin-core/src/text/mod.rs +++ b/pumpkin-core/src/text/mod.rs @@ -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>, + pub extra: Vec, } -impl<'a> TextComponent<'a> { - pub fn text(text: &'a str) -> Self { - Self { - content: TextContent::Text { text: text.into() }, - style: Style::default(), - extra: vec![], - } - } - - pub fn text_string(text: String) -> Self { +impl TextComponent { + pub fn text

(plain: P) -> Self + where + P: Into>, + { Self { - content: TextContent::Text { text: text.into() }, + content: TextContent::Text { text: plain.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(&self, serializer: S) -> Result 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>, } - fn convert_extra<'a>(extra: &'a [TextComponent<'a>]) -> Vec> { + fn convert_extra(extra: &[TextComponent]) -> Vec> { 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>, + with: Vec, }, /// 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>, + separator: Option>, }, /// A keybind identifier /// https://minecraft.wiki/w/Controls#Configurable_controls - Keybind { keybind: Cow<'a, str> }, + Keybind { keybind: Cow<'static, str> }, } diff --git a/pumpkin-core/src/text/style.rs b/pumpkin-core/src/text/style.rs index 1049e14c6..86bc38d7f 100644 --- a/pumpkin-core/src/text/style.rs +++ b/pumpkin-core/src/text/style.rs @@ -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, @@ -31,10 +31,10 @@ pub struct Style<'a> { pub insertion: Option, /// 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>, + pub click_event: Option, /// 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>, + pub hover_event: Option, /// Allows you to change the font of the text. #[serde(default, skip_serializing_if = "Option::is_none")] pub font: Option, @@ -46,7 +46,7 @@ pub struct Style<'a> { pub shadow_color: Option, } -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 } diff --git a/pumpkin-protocol/src/bytebuf/mod.rs b/pumpkin-protocol/src/bytebuf/mod.rs index edfa15c79..d089c221b 100644 --- a/pumpkin-protocol/src/bytebuf/mod.rs +++ b/pumpkin-protocol/src/bytebuf/mod.rs @@ -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 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) } diff --git a/pumpkin-protocol/src/client/config/c_add_resource_pack.rs b/pumpkin-protocol/src/client/config/c_add_resource_pack.rs index e73946835..bcda7fcc7 100644 --- a/pumpkin-protocol/src/client/config/c_add_resource_pack.rs +++ b/pumpkin-protocol/src/client/config/c_add_resource_pack.rs @@ -10,7 +10,7 @@ pub struct CConfigAddResourcePack<'a> { url: &'a str, hash: &'a str, // max 40 forced: bool, - prompt_message: Option>, + prompt_message: Option, } impl<'a> CConfigAddResourcePack<'a> { @@ -19,7 +19,7 @@ impl<'a> CConfigAddResourcePack<'a> { url: &'a str, hash: &'a str, forced: bool, - prompt_message: Option>, + prompt_message: Option, ) -> Self { Self { uuid, diff --git a/pumpkin-protocol/src/client/play/bossevent_action.rs b/pumpkin-protocol/src/client/play/bossevent_action.rs index e0841d538..fbf8d2b66 100644 --- a/pumpkin-protocol/src/client/play/bossevent_action.rs +++ b/pumpkin-protocol/src/client/play/bossevent_action.rs @@ -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, diff --git a/pumpkin-protocol/src/client/play/c_actionbar.rs b/pumpkin-protocol/src/client/play/c_actionbar.rs index c74f0778e..1da6dcade 100644 --- a/pumpkin-protocol/src/client/play/c_actionbar.rs +++ b/pumpkin-protocol/src/client/play/c_actionbar.rs @@ -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 } } } diff --git a/pumpkin-protocol/src/client/play/c_boss_event.rs b/pumpkin-protocol/src/client/play/c_boss_event.rs index e5b2292d5..00109f61c 100644 --- a/pumpkin-protocol/src/client/play/c_boss_event.rs +++ b/pumpkin-protocol/src/client/play/c_boss_event.rs @@ -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 { diff --git a/pumpkin-protocol/src/client/play/c_combat_death.rs b/pumpkin-protocol/src/client/play/c_combat_death.rs index 0de9b64bb..2186b7960 100644 --- a/pumpkin-protocol/src/client/play/c_combat_death.rs +++ b/pumpkin-protocol/src/client/play/c_combat_death.rs @@ -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 } } } diff --git a/pumpkin-protocol/src/client/play/c_command_suggestions.rs b/pumpkin-protocol/src/client/play/c_command_suggestions.rs index c137b9ad7..bfda9b2b4 100644 --- a/pumpkin-protocol/src/client/play/c_command_suggestions.rs +++ b/pumpkin-protocol/src/client/play/c_command_suggestions.rs @@ -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>, + matches: Vec, } -impl<'a> CCommandSuggestions<'a> { - pub fn new( - id: VarInt, - start: VarInt, - length: VarInt, - matches: Vec>, - ) -> Self { +impl CCommandSuggestions { + pub fn new(id: VarInt, start: VarInt, length: VarInt, matches: Vec) -> 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>, + pub tooltip: Option, } -impl<'a> CommandSuggestion<'a> { - pub fn new(suggestion: String, tooltip: Option>) -> Self { +impl CommandSuggestion { + pub fn new(suggestion: String, tooltip: Option) -> Self { Self { suggestion, tooltip, diff --git a/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs b/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs index 5f79292b5..9f1fc879f 100644 --- a/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_disguised_chat_message.rs @@ -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>, + 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>, + sender_name: &'a TextComponent, + target_name: Option<&'a TextComponent>, ) -> Self { Self { message, diff --git a/pumpkin-protocol/src/client/play/c_open_screen.rs b/pumpkin-protocol/src/client/play/c_open_screen.rs index 90a9d959b..518f03076 100644 --- a/pumpkin-protocol/src/client/play/c_open_screen.rs +++ b/pumpkin-protocol/src/client/play/c_open_screen.rs @@ -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, diff --git a/pumpkin-protocol/src/client/play/c_play_disconnect.rs b/pumpkin-protocol/src/client/play/c_play_disconnect.rs index ae8dd3f56..6ac87017e 100644 --- a/pumpkin-protocol/src/client/play/c_play_disconnect.rs +++ b/pumpkin-protocol/src/client/play/c_play_disconnect.rs @@ -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 } } } diff --git a/pumpkin-protocol/src/client/play/c_player_chat_message.rs b/pumpkin-protocol/src/client/play/c_player_chat_message.rs index 0db6c3df0..f84f03ab4 100644 --- a/pumpkin-protocol/src/client/play/c_player_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_player_chat_message.rs @@ -17,11 +17,11 @@ pub struct CPlayerChatMessage<'a> { salt: i64, previous_messages_count: VarInt, previous_messages: &'a [PreviousMessage<'a>], // max 20 - unsigned_content: Option>, + unsigned_content: Option, filter_type: FilterType, chat_type: VarInt, - sender_name: TextComponent<'a>, - target_name: Option>, + sender_name: TextComponent, + target_name: Option, } impl<'a> CPlayerChatMessage<'a> { @@ -34,11 +34,11 @@ impl<'a> CPlayerChatMessage<'a> { timestamp: i64, salt: i64, previous_messages: &'a [PreviousMessage<'a>], - unsigned_content: Option>, + unsigned_content: Option, filter_type: FilterType, chat_type: VarInt, - sender_name: TextComponent<'a>, - target_name: Option>, + sender_name: TextComponent, + target_name: Option, ) -> Self { Self { sender, diff --git a/pumpkin-protocol/src/client/play/c_set_title.rs b/pumpkin-protocol/src/client/play/c_set_title.rs index 2253f4202..7692a5fb9 100644 --- a/pumpkin-protocol/src/client/play/c_set_title.rs +++ b/pumpkin-protocol/src/client/play/c_set_title.rs @@ -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 } } } diff --git a/pumpkin-protocol/src/client/play/c_subtitle.rs b/pumpkin-protocol/src/client/play/c_subtitle.rs index 52c0db090..45a89d421 100644 --- a/pumpkin-protocol/src/client/play/c_subtitle.rs +++ b/pumpkin-protocol/src/client/play/c_subtitle.rs @@ -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 } } } diff --git a/pumpkin-protocol/src/client/play/c_system_chat_message.rs b/pumpkin-protocol/src/client/play/c_system_chat_message.rs index 98d7b275e..0112a18d2 100644 --- a/pumpkin-protocol/src/client/play/c_system_chat_message.rs +++ b/pumpkin-protocol/src/client/play/c_system_chat_message.rs @@ -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 } } } diff --git a/pumpkin-protocol/src/client/play/c_update_objectives.rs b/pumpkin-protocol/src/client/play/c_update_objectives.rs index 41c45ff58..31d9dadb1 100644 --- a/pumpkin-protocol/src/client/play/c_update_objectives.rs +++ b/pumpkin-protocol/src/client/play/c_update_objectives.rs @@ -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>, + number_format: Option, } 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>, + number_format: Option, ) -> Self { Self { objective_name, diff --git a/pumpkin-protocol/src/client/play/c_update_score.rs b/pumpkin-protocol/src/client/play/c_update_score.rs index 33abebe69..b82aa5d75 100644 --- a/pumpkin-protocol/src/client/play/c_update_score.rs +++ b/pumpkin-protocol/src/client/play/c_update_score.rs @@ -11,8 +11,8 @@ pub struct CUpdateScore<'a> { entity_name: &'a str, objective_name: &'a str, value: VarInt, - display_name: Option>, - number_format: Option>, + display_name: Option, + number_format: Option, } 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>, - number_format: Option>, + display_name: Option, + number_format: Option, ) -> Self { Self { entity_name, diff --git a/pumpkin-protocol/src/lib.rs b/pumpkin-protocol/src/lib.rs index fec62014a..afb136092 100644 --- a/pumpkin-protocol/src/lib.rs +++ b/pumpkin-protocol/src/lib.rs @@ -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(&self, serializer: S) -> Result 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, diff --git a/pumpkin-registry/src/chat_type.rs b/pumpkin-registry/src/chat_type.rs index f72d8ef79..93b46e89e 100644 --- a/pumpkin-registry/src/chat_type.rs +++ b/pumpkin-registry/src/chat_type.rs @@ -11,6 +11,6 @@ pub struct ChatType { pub struct Decoration { translation_key: String, #[serde(default, skip_serializing_if = "Option::is_none")] - style: Option>, + style: Option