diff --git a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java index dcd42baa4..5575874c4 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java @@ -361,6 +361,12 @@ public boolean isCrafter(InventoryType type) { return false; } + + @Override + public boolean isBundle(Material material) { + return false; + } + @Override public boolean isCopperChest(Material material) { return false; diff --git a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java index 9ccebed8e..33eb225d4 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java @@ -152,6 +152,17 @@ public interface BukkitInterface { */ boolean isBookshelfBook(Material material); + + /** + * Checks if a material is a bundle. + * + * @param material + * The material to check + * @return true if the material is a bundle, false otherwise + */ + boolean isBundle(Material material); + + /** * Gets the seeds material for a plant material. * diff --git a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java index b9e6918ab..16315a8e5 100644 --- a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java +++ b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java @@ -152,9 +152,15 @@ public boolean getItemMeta(ItemMeta itemMeta, List> list, Li return super.getItemMeta(itemMeta, list, metadata, slot); } + @Override + public boolean isBundle(Material material) { + return material == Material.BUNDLE; + } + + @Override public boolean setItemMeta(Material rowType, ItemStack itemstack, List> map) { - if (rowType == Material.BUNDLE) { + if (BukkitAdapter.ADAPTER.isBundle(rowType)) { BundleMeta meta = (BundleMeta) itemstack.getItemMeta(); for (Map itemData : map) { ItemStack itemStack = ItemUtils.unserializeItemStack(itemData); diff --git a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java index 4d0e2521d..63d8d4aa7 100644 --- a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java +++ b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java @@ -27,6 +27,7 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 { public static Set COPPER_CHESTS = new HashSet<>(Arrays.asList()); public static Set SHELVES = new HashSet<>(Arrays.asList()); + public static Set BUNDLES = new HashSet<>(Arrays.asList()); /** * Initializes the Bukkit_v1_21 adapter with 1.21-specific block groups and mappings. @@ -35,6 +36,7 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 { public Bukkit_v1_21() { initializeBlockGroups(); initializeTrapdoorBlocks(); + initializeBundles(); BlockGroup.INTERACT_BLOCKS.addAll(copperChestMaterials()); BlockGroup.CONTAINERS.addAll(copperChestMaterials()); BlockGroup.UPDATE_STATE.addAll(copperChestMaterials()); @@ -68,6 +70,20 @@ private void initializeTrapdoorBlocks() { } } + /** + * Initializes the bundles group to enable the ability to roll back dyed bundles correctly. + * It needs to check whether dyed bundles exist because they were added in 1.21.2. + */ + public void initializeBundles(){ + if (BUNDLES.isEmpty()) { + Material bundle = Material.getMaterial("RED_BUNDLE"); + if (bundle != null) { + BUNDLES.addAll(Tag.ITEMS_BUNDLES.getValues()); + } + BUNDLES.add(Material.BUNDLE); + } + } + /** * Helper method to add a block to a block group if it's not already present. * @@ -185,6 +201,12 @@ public boolean isShelf(Material material) { return SHELVES.contains(material); } + @Override + public boolean isBundle(Material material) { + return Tag.ITEMS_BUNDLES.getValues().contains(material); + } + + @Override public Set copperChestMaterials() { if (COPPER_CHESTS.isEmpty()) {