11package me .hsgamer .bettergui .modifier ;
22
33import com .google .gson .Gson ;
4+ import me .hsgamer .hscore .bukkit .utils .VersionUtils ;
45import me .hsgamer .hscore .common .StringReplacer ;
56import me .hsgamer .hscore .common .Validate ;
67import me .hsgamer .hscore .minecraft .item .ItemModifier ;
78import org .bukkit .Bukkit ;
9+ import org .bukkit .Material ;
10+ import org .bukkit .NamespacedKey ;
811import org .bukkit .inventory .ItemStack ;
912import org .jetbrains .annotations .NotNull ;
1013
1518
1619public class NBTModifier implements ItemModifier <ItemStack > {
1720 private static final Gson GSON = new Gson ();
21+ private static final boolean USE_ITEM_COMPONENT = VersionUtils .isAtLeast (20 , 5 );
1822 private String nbtData = "" ;
1923
2024 @ SuppressWarnings ("deprecation" )
@@ -23,10 +27,24 @@ public class NBTModifier implements ItemModifier<ItemStack> {
2327 if (Validate .isNullOrEmpty (nbtData )) {
2428 return original ;
2529 }
26- try {
27- return Bukkit .getUnsafe ().modifyItemStack (original , StringReplacer .replace (nbtData , uuid , stringReplacers ));
28- } catch (Throwable throwable ) {
29- return original ;
30+
31+ String replacedNbtData = StringReplacer .replace (nbtData , uuid , stringReplacers );
32+
33+ if (USE_ITEM_COMPONENT ) {
34+ Material material = original .getType ();
35+ NamespacedKey materialKey = material .getKey ();
36+ String materialName = materialKey .toString ();
37+ try {
38+ return Bukkit .getItemFactory ().createItemStack (materialName + replacedNbtData );
39+ } catch (Throwable throwable ) {
40+ return original ;
41+ }
42+ } else {
43+ try {
44+ return Bukkit .getUnsafe ().modifyItemStack (original , replacedNbtData );
45+ } catch (Throwable throwable ) {
46+ return original ;
47+ }
3048 }
3149 }
3250
0 commit comments