@@ -69,14 +69,8 @@ public Item handleItemToClient(UserConnection connection, Item item) {
6969 final ComponentRewriter componentRewriter = protocol .getComponentRewriter ();
7070 if (componentRewriter != null ) {
7171 // Handle name and lore components
72- final StructuredData <Tag > customNameData = dataContainer .getNonEmpty (StructuredDataKey .CUSTOM_NAME );
73- if (customNameData != null ) {
74- final Tag originalName = customNameData .value ().copy ();
75- componentRewriter .processTag (connection , customNameData .value ());
76- if (!customNameData .value ().equals (originalName )) {
77- saveTag (createCustomTag (item ), originalName , "Name" );
78- }
79- }
72+ updateComponent (connection , item , StructuredDataKey .ITEM_NAME , "item_name" );
73+ updateComponent (connection , item , StructuredDataKey .CUSTOM_NAME , "custom_name" );
8074
8175 final StructuredData <Tag []> loreData = dataContainer .getNonEmpty (StructuredDataKey .LORE );
8276 if (loreData != null ) {
@@ -164,6 +158,19 @@ protected void updateItemComponents(UserConnection connection, StructuredDataCon
164158 }
165159 }
166160
161+ private void updateComponent (final UserConnection connection , final Item item , final StructuredDataKey <Tag > key , final String backupKey ) {
162+ final StructuredData <Tag > name = item .dataContainer ().getNonEmpty (key );
163+ if (name == null ) {
164+ return ;
165+ }
166+
167+ final Tag originalName = name .value ().copy ();
168+ protocol .getComponentRewriter ().processTag (connection , name .value ());
169+ if (!name .value ().equals (originalName )) {
170+ saveTag (createCustomTag (item ), originalName , backupKey );
171+ }
172+ }
173+
167174 protected void restoreTextComponents (final Item item ) {
168175 final StructuredDataContainer data = item .dataContainer ();
169176 final StructuredData <CompoundTag > customData = data .getNonEmpty (StructuredDataKey .CUSTOM_DATA );
@@ -172,12 +179,17 @@ protected void restoreTextComponents(final Item item) {
172179 }
173180
174181 // Remove custom name
175- if (customData .value ().remove (nbtTagName ("customName " )) != null ) {
182+ if (customData .value ().remove (nbtTagName ("added_custom_name " )) != null ) {
176183 data .remove (StructuredDataKey .CUSTOM_NAME );
177184 } else {
178- final Tag name = removeBackupTag (customData .value (), "Name" );
179- if (name != null ) {
180- data .set (StructuredDataKey .CUSTOM_NAME , name );
185+ final Tag customName = removeBackupTag (customData .value (), "custom_name" );
186+ if (customName != null ) {
187+ data .set (StructuredDataKey .CUSTOM_NAME , customName );
188+ }
189+
190+ final Tag itemName = removeBackupTag (customData .value (), "item_name" );
191+ if (itemName != null ) {
192+ data .set (StructuredDataKey .ITEM_NAME , itemName );
181193 }
182194 }
183195 }
0 commit comments