11package me .xginko .aef .utils ;
22
3- import com .cryptomorin .xseries .XMaterial ;
43import com .destroystokyo .paper .event .player .PlayerArmorChangeEvent ;
54import de .tr7zw .changeme .nbtapi .NBT ;
6- import io .papermc .paper .datacomponent .DataComponentTypes ;
75import me .xginko .aef .utils .reflection .ReflectionUtil ;
86import net .kyori .adventure .text .Component ;
97import net .kyori .adventure .text .minimessage .MiniMessage ;
108import org .bukkit .Bukkit ;
119import org .bukkit .inventory .EquipmentSlot ;
10+ import org .bukkit .inventory .Inventory ;
1211import org .bukkit .inventory .InventoryHolder ;
1312import org .bukkit .inventory .ItemStack ;
1413import org .bukkit .inventory .meta .BlockStateMeta ;
1514import org .bukkit .inventory .meta .BookMeta ;
16- import org .bukkit .inventory .meta .BundleMeta ;
1715import org .bukkit .map .MapView ;
1816import org .jetbrains .annotations .NotNull ;
1917import org .jetbrains .annotations .Nullable ;
2624public final class ItemUtil {
2725
2826 public static final boolean MAP_SET_TRACKING_POS_AVAILABLE ;
29- private static final boolean BUNDLES_SUPPPORTED , USE_MINIMSG_BOOKMETA , COMPONENTS_SUPPORTED ;
27+ private static final boolean USE_MINIMSG_BOOKMETA ;
3028 private static final Map <PlayerArmorChangeEvent .SlotType , EquipmentSlot > EQUIPMENT_SLOT_MAP ;
3129
3230 static {
@@ -38,14 +36,6 @@ public final class ItemUtil {
3836 && ReflectionUtil .hasMethod (MiniMessage .class , "miniMessage" )
3937 && ReflectionUtil .hasMethod (BookMeta .class , "pages" );
4038
41- BUNDLES_SUPPPORTED
42- = XMaterial .BUNDLE .isSupported ()
43- && ReflectionUtil .hasClass ("org.bukkit.inventory.meta.BundleMeta" );
44-
45- COMPONENTS_SUPPORTED
46- = ReflectionUtil .hasClass ("io.papermc.paper.datacomponent.DataComponentTypes" )
47- && ReflectionUtil .hasMethod (ItemStack .class , "getData" );
48-
4939 EQUIPMENT_SLOT_MAP = new EnumMap <>(PlayerArmorChangeEvent .SlotType .class );
5040 EQUIPMENT_SLOT_MAP .put (PlayerArmorChangeEvent .SlotType .HEAD , EquipmentSlot .HEAD );
5141 EQUIPMENT_SLOT_MAP .put (PlayerArmorChangeEvent .SlotType .CHEST , EquipmentSlot .CHEST );
@@ -65,31 +55,32 @@ public static EquipmentSlot getEquipmentSlot(PlayerArmorChangeEvent.SlotType slo
6555 */
6656 @ Nullable
6757 @ UnmodifiableView
68- @ SuppressWarnings ("UnstableApiUsage" )
6958 public static Iterable <ItemStack > getStoredItems (@ NotNull ItemStack itemStack ) {
70- if (itemStack .hasItemMeta ()) {
71- if (MaterialUtil .INVENTORY_HOLDERS .get ().contains (itemStack .getType ())) {
72- BlockStateMeta blockStateMeta = (BlockStateMeta ) itemStack .getItemMeta ();
73- if (blockStateMeta .hasBlockState ()) {
74- return ((InventoryHolder ) blockStateMeta .getBlockState ()).getInventory ();
75- }
76- }
59+ Iterable <ItemStack > content ;
7760
78- if (BUNDLES_SUPPPORTED && itemStack .getType () == XMaterial .BUNDLE .get ()) {
79- return ((BundleMeta ) itemStack .getItemMeta ()).getItems ();
80- }
61+ content = ItemUtil .getShulkerContent (itemStack );
62+ if (content != null ) return content ;
63+
64+ if (BundleUtil .BUNDLES_SUPPPORTED ) {
65+ content = BundleUtil .getBundleContent (itemStack );
66+ if (content != null ) return content ;
8167 }
8268
83- if (COMPONENTS_SUPPORTED ) {
84- if (itemStack .hasData (DataComponentTypes .CONTAINER )) {
85- return itemStack .getData (DataComponentTypes .CONTAINER ).contents ();
86- }
69+ if (DataComponentUtil .COMPONENTS_SUPPORTED ) {
70+ content = DataComponentUtil .getContainerContent (itemStack );
71+ }
72+
73+ return content ;
74+ }
8775
88- if (itemStack .hasData (DataComponentTypes .BUNDLE_CONTENTS )) {
89- return itemStack .getData (DataComponentTypes .BUNDLE_CONTENTS ).contents ();
76+ @ Nullable
77+ public static Inventory getShulkerContent (@ NotNull ItemStack itemStack ) {
78+ if (MaterialUtil .INVENTORY_HOLDERS .get ().contains (itemStack .getType ()) && itemStack .hasItemMeta ()) {
79+ BlockStateMeta blockStateMeta = (BlockStateMeta ) itemStack .getItemMeta ();
80+ if (blockStateMeta .hasBlockState ()) {
81+ return ((InventoryHolder ) blockStateMeta .getBlockState ()).getInventory ();
9082 }
9183 }
92-
9384 return null ;
9485 }
9586
0 commit comments