2020
2121import org .bukkit .Bukkit ;
2222import org .bukkit .Material ;
23+ import org .bukkit .block .Container ;
2324import org .bukkit .block .ShulkerBox ;
2425import org .bukkit .enchantments .Enchantment ;
2526import org .bukkit .inventory .ItemStack ;
2627import org .bukkit .inventory .meta .BlockStateMeta ;
28+ import org .bukkit .inventory .meta .BundleMeta ;
2729import org .bukkit .inventory .meta .ItemMeta ;
2830import org .bukkit .plugin .Plugin ;
2931
32+ import java .util .ArrayList ;
3033import java .util .Collection ;
3134import java .util .HashSet ;
35+ import java .util .List ;
3236import java .util .Set ;
3337
3438public class ItemFilter {
@@ -71,11 +75,26 @@ public ItemStack[] filterItemStack(ItemStack[] input) {
7175
7276 if (item != null ) {
7377
74- if (item .getType ().toString ().contains ("SHULKER_BOX" )) {
75- if (item .getItemMeta () instanceof BlockStateMeta blockStateMeta ) {
76- if (blockStateMeta .getBlockState () instanceof ShulkerBox shulker ) {
77- shulker .getInventory ().setContents (filterItemStack (shulker .getInventory ().getContents ()));
78+ if (item .getItemMeta () instanceof BlockStateMeta blockStateMeta ) {
79+ if (blockStateMeta .getBlockState () instanceof Container container ) {
80+ container .getInventory ().setContents (filterItemStack (container .getInventory ().getContents ()));
81+ blockStateMeta .setBlockState (container );
82+ item .setItemMeta (blockStateMeta );
83+ }
84+ }
85+
86+ // Handle bundles
87+ if (item .getItemMeta () instanceof BundleMeta bundleMeta ) {
88+ List <ItemStack > bundleItems = bundleMeta .getItems ();
89+ if (!bundleItems .isEmpty ()) {
90+ List <ItemStack > filteredItems = new ArrayList <>();
91+ for (ItemStack bundleItem : bundleItems ) {
92+ if (isSafe (bundleItem )) {
93+ filteredItems .add (bundleItem );
94+ }
7895 }
96+ bundleMeta .setItems (filteredItems );
97+ item .setItemMeta (bundleMeta );
7998 }
8099 }
81100 }
@@ -122,7 +141,7 @@ public void addToWhitelist(Collection<ItemStack[]> items) {
122141 for (ItemStack [] itemStacks : items ) {
123142 for (ItemStack item : itemStacks ) {
124143 if (item != null ) {
125- whitelist .add (item .getType ().toString ());
144+ whitelist .add (item .getType ().toString ());
126145 }
127146 }
128147 }
@@ -133,4 +152,4 @@ public void clearWhitelist() {
133152 }
134153
135154
136- }
155+ }
0 commit comments