@@ -39,42 +39,53 @@ public static String getPlayerJson(OfflinePlayer player) {
39
39
40
40
public static String getItemJsonStripped (ItemStack item ) {
41
41
ItemStack cloned = item .clone ();
42
- if (cloned .hasItemMeta () && cloned .getItemMeta () instanceof BookMeta ) {
43
- return ItemStackUtils .itemToJson (removeBookContent (cloned ));
42
+ if (cloned .hasItemMeta ()) {
43
+ var meta = cloned .getItemMeta ();
44
+ if (meta instanceof BookMeta ) {
45
+ return ItemStackUtils .itemToJson (removeBookContent (cloned ));
46
+ }
47
+ if (meta != null ) {
48
+ cloned .setItemMeta (filterItemMeta (meta ));
49
+ }
44
50
}
45
- if (cloned .hasItemMeta () && cloned .getItemMeta () instanceof BlockStateMeta blockStateMeta ) {
46
- if (blockStateMeta .hasBlockState () && blockStateMeta .getBlockState () instanceof InventoryHolder inventoryHolder ) {
47
- ArrayList <ItemStack > items = new ArrayList <>();
48
- for (int i = 0 ; i < inventoryHolder .getInventory ().getSize (); i ++) {
49
- ItemStack itemStack = inventoryHolder .getInventory ().getItem (i );
50
- if (itemStack != null && itemStack .getType () != Material .AIR ) {
51
- if (items .size () < 5 ) {
52
- if (itemStack .hasItemMeta ()) {
53
- if (itemStack .getItemMeta ().hasLore ()) {
54
- ItemMeta meta = itemStack .getItemMeta ();
55
- meta .setLore (new ArrayList <>());
56
- itemStack .setItemMeta (meta );
57
- }
58
- if (itemStack .getItemMeta () instanceof BookMeta ) {
59
- itemStack = removeBookContent (itemStack );
60
- }
61
- }
62
- items .add (itemStack );
63
- } else {
64
- items .add (new ItemStack (Material .STONE ));
51
+ return ItemStackUtils .itemToJson (cloned );
52
+ }
53
+
54
+
55
+ public static ItemMeta filterItemMeta (ItemMeta itemMeta ) {
56
+ var cloned = itemMeta .clone ();
57
+ if (!(cloned instanceof BlockStateMeta blockStateMeta ))return cloned ;
58
+ if (!(blockStateMeta .getBlockState () instanceof InventoryHolder inventoryHolder ))return cloned ;
59
+ ArrayList <ItemStack > items = new ArrayList <>();
60
+
61
+ for (int i = 0 ; i < inventoryHolder .getInventory ().getSize (); i ++) {
62
+ ItemStack itemStack = inventoryHolder .getInventory ().getItem (i );
63
+ if (itemStack != null && itemStack .getType () != Material .AIR ) {
64
+ if (items .size () < 5 ) {
65
+ if (itemStack .hasItemMeta ()) {
66
+ if (itemStack .getItemMeta ().hasLore ()) {
67
+ ItemMeta meta = itemStack .getItemMeta ();
68
+ meta .setLore (new ArrayList <>());
69
+ itemStack .setItemMeta (meta );
70
+ }
71
+ if (itemStack .getItemMeta () instanceof BookMeta ) {
72
+ itemStack = removeBookContent (itemStack );
65
73
}
66
74
}
75
+ items .add (itemStack );
76
+ } else {
77
+ items .add (new ItemStack (Material .STONE ));
67
78
}
68
- inventoryHolder .getInventory ().clear ();
69
- for (int i = 0 ; i < items .size (); i ++) {
70
- inventoryHolder .getInventory ().setItem (i , items .get (i ));
71
- }
72
- blockStateMeta .setBlockState ((BlockState ) inventoryHolder );
73
- cloned .setItemMeta (blockStateMeta );
74
- return ItemStackUtils .itemToJson (cloned );
75
79
}
76
80
}
77
- return ItemStackUtils .itemToJson (cloned );
81
+
82
+ inventoryHolder .getInventory ().clear ();
83
+ for (int i = 0 ; i < items .size (); i ++) {
84
+ inventoryHolder .getInventory ().setItem (i , items .get (i ));
85
+ }
86
+ blockStateMeta .setBlockState ((BlockState ) inventoryHolder );
87
+ return blockStateMeta ;
88
+
78
89
}
79
90
80
91
/**
0 commit comments