1- package com .eternalcode .core .feature .essentials .item .lore ;
1+ package com .eternalcode .core .feature .essentials .item .itemedit ;
22
33import com .eternalcode .annotations .scan .command .DescriptionDocs ;
44import com .eternalcode .commons .adventure .AdventureUtil ;
55import com .eternalcode .core .injector .annotations .Inject ;
66import com .eternalcode .core .notice .NoticeService ;
7- import com .eternalcode .commons .adventure .AdventureUtil ;
87import dev .rollczi .litecommands .annotations .argument .Arg ;
98import dev .rollczi .litecommands .annotations .context .Context ;
109import dev .rollczi .litecommands .annotations .join .Join ;
1110import dev .rollczi .litecommands .annotations .execute .Execute ;
1211import dev .rollczi .litecommands .annotations .permission .Permission ;
1312import dev .rollczi .litecommands .annotations .command .Command ;
1413import net .kyori .adventure .text .minimessage .MiniMessage ;
14+ import net .kyori .adventure .text .serializer .gson .GsonComponentSerializer ;
1515import org .bukkit .Material ;
1616import org .bukkit .entity .Player ;
1717import org .bukkit .inventory .ItemStack ;
@@ -40,53 +40,79 @@ void execute(@Context Player player, @Arg(ItemLoreArgument.KEY) int line, @Join
4040
4141 if (itemStack == null ) {
4242 this .noticeService .player (player .getUniqueId (), translation -> translation .argument ().noItem ());
43-
4443 return ;
4544 }
4645
4746 ItemMeta itemMeta = itemStack .getItemMeta ();
4847
4948 List <String > lore = itemMeta .getLore ();
50-
5149 lore = lore == null ? new ArrayList <>() : new ArrayList <>(lore );
5250
53- if ( text . equals ( "none" ) ) {
54- lore .remove ( line );
51+ while ( lore . size () <= line ) {
52+ lore .add ( "" );
5553 }
56- else {
57- // fill list
58- while (lore .size () <= line ) {
59- lore .add ("" );
60- }
6154
62- lore .set (line , AdventureUtil .SECTION_SERIALIZER .serialize (AdventureUtil .resetItalic (this .miniMessage .deserialize (text ))));
63- }
55+ // Serialize using GsonComponentSerializer for modern Minecraft versions
56+ String json = GsonComponentSerializer .gson ().serialize (
57+ AdventureUtil .resetItalic (this .miniMessage .deserialize (text ))
58+ );
59+ lore .set (line , json );
6460
6561 itemMeta .setLore (lore );
6662 itemStack .setItemMeta (itemMeta );
6763
6864 this .noticeService .create ()
69- .notice (translation -> translation .item ().itemChangeLoreMessage ())
65+ .notice (translation -> translation .itemEdit ().itemChangeLoreMessage ())
7066 .placeholder ("{ITEM_LORE}" , text )
7167 .player (player .getUniqueId ())
7268 .send ();
7369 }
7470
71+ @ Execute (name = "remove" )
72+ @ DescriptionDocs (description = "Removes a specific line of lore from the item in hand" , arguments = "<line>" )
73+ void remove (@ Context Player player , @ Arg (ItemLoreArgument .KEY ) int line ) {
74+ ItemStack itemStack = this .validateItemFromMainHand (player );
75+
76+ if (itemStack == null ) {
77+ this .noticeService .player (player .getUniqueId (), translation -> translation .argument ().noItem ());
78+ return ;
79+ }
80+
81+ ItemMeta itemMeta = itemStack .getItemMeta ();
82+ List <String > lore = itemMeta .getLore ();
83+
84+ if (lore == null || lore .isEmpty ()) {
85+ this .noticeService .player (player .getUniqueId (), translation -> translation .itemEdit ().noLore ());
86+ return ;
87+ }
88+
89+ if (line < 0 || line >= lore .size ()) {
90+ this .noticeService .player (player .getUniqueId (), translation -> translation .itemEdit ().invalidLoreLine ());
91+ return ;
92+ }
93+
94+ lore .remove (line );
95+ itemMeta .setLore (lore );
96+ itemStack .setItemMeta (itemMeta );
97+
98+ this .noticeService .player (player .getUniqueId (), translation -> translation .itemEdit ().itemLoreLineRemoved ());
99+ }
100+
75101 @ Execute (name = "clear" )
76- @ DescriptionDocs (description = "Clears lore of item in hand" )
102+ @ DescriptionDocs (description = "Clears all lore from the item in hand" )
77103 void clear (@ Context Player player ) {
78104 ItemStack itemStack = this .validateItemFromMainHand (player );
79105
80106 if (itemStack == null ) {
107+ this .noticeService .player (player .getUniqueId (), translation -> translation .argument ().noItem ());
81108 return ;
82109 }
83110
84111 ItemMeta itemMeta = itemStack .getItemMeta ();
85-
86112 itemMeta .setLore (new ArrayList <>());
87113 itemStack .setItemMeta (itemMeta );
88114
89- this .noticeService .player (player .getUniqueId (), translation -> translation .item ().itemClearLoreMessage ());
115+ this .noticeService .player (player .getUniqueId (), translation -> translation .itemEdit ().itemClearLoreMessage ());
90116 }
91117
92118 private ItemStack validateItemFromMainHand (Player player ) {
@@ -98,5 +124,4 @@ private ItemStack validateItemFromMainHand(Player player) {
98124
99125 return itemStack ;
100126 }
101-
102127}
0 commit comments