Skip to content

Commit d87ecae

Browse files
authored
fix issue so coloured bundles are rolled back properly (#872)
1 parent dc4e9f8 commit d87ecae

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/main/java/net/coreprotect/bukkit/BukkitAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ public boolean isCrafter(InventoryType type) {
374374
return false;
375375
}
376376

377+
378+
@Override
379+
public boolean isBundle(Material material) {
380+
return false;
381+
}
382+
377383
@Override
378384
public boolean isCopperChest(Material material) {
379385
return false;

src/main/java/net/coreprotect/bukkit/BukkitInterface.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ public interface BukkitInterface {
154154
*/
155155
boolean isBookshelfBook(Material material);
156156

157+
158+
/**
159+
* Checks if a material is a bundle.
160+
*
161+
* @param material
162+
* The material to check
163+
* @return true if the material is a bundle, false otherwise
164+
*/
165+
boolean isBundle(Material material);
166+
167+
157168
/**
158169
* Gets the seeds material for a plant material.
159170
*

src/main/java/net/coreprotect/bukkit/Bukkit_v1_17.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,15 @@ public boolean getItemMeta(ItemMeta itemMeta, List<Map<String, Object>> list, Li
152152
return super.getItemMeta(itemMeta, list, metadata, slot);
153153
}
154154

155+
@Override
156+
public boolean isBundle(Material material) {
157+
return material == Material.BUNDLE;
158+
}
159+
160+
155161
@Override
156162
public boolean setItemMeta(Material rowType, ItemStack itemstack, List<Map<String, Object>> map) {
157-
if (rowType == Material.BUNDLE) {
163+
if (BukkitAdapter.ADAPTER.isBundle(rowType)) {
158164
BundleMeta meta = (BundleMeta) itemstack.getItemMeta();
159165
for (Map<String, Object> itemData : map) {
160166
ItemStack itemStack = ItemUtils.unserializeItemStack(itemData);

src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 {
3232

3333
public static Set<Material> COPPER_CHESTS = new HashSet<>(Arrays.asList());
3434
public static Set<Material> SHELVES = new HashSet<>(Arrays.asList());
35+
public static Set<Material> BUNDLES = new HashSet<>(Arrays.asList());
3536

3637
/**
3738
* Initializes the Bukkit_v1_21 adapter with 1.21-specific block groups and mappings.
@@ -40,6 +41,7 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 {
4041
public Bukkit_v1_21() {
4142
initializeBlockGroups();
4243
initializeTrapdoorBlocks();
44+
initializeBundles();
4345
BlockGroup.INTERACT_BLOCKS.addAll(copperChestMaterials());
4446
BlockGroup.CONTAINERS.addAll(copperChestMaterials());
4547
BlockGroup.UPDATE_STATE.addAll(copperChestMaterials());
@@ -73,6 +75,20 @@ private void initializeTrapdoorBlocks() {
7375
}
7476
}
7577

78+
/**
79+
* Initializes the bundles group to enable the ability to roll back dyed bundles correctly.
80+
* It needs to check whether dyed bundles exist because they were added in 1.21.2.
81+
*/
82+
public void initializeBundles(){
83+
if (BUNDLES.isEmpty()) {
84+
Material bundle = Material.getMaterial("RED_BUNDLE");
85+
if (bundle != null) {
86+
BUNDLES.addAll(Tag.ITEMS_BUNDLES.getValues());
87+
}
88+
BUNDLES.add(Material.BUNDLE);
89+
}
90+
}
91+
7692
/**
7793
* Helper method to add a block to a block group if it's not already present.
7894
*
@@ -190,6 +206,12 @@ public boolean isShelf(Material material) {
190206
return SHELVES.contains(material);
191207
}
192208

209+
@Override
210+
public boolean isBundle(Material material) {
211+
return Tag.ITEMS_BUNDLES.getValues().contains(material);
212+
}
213+
214+
193215
@Override
194216
public Set<Material> copperChestMaterials() {
195217
if (COPPER_CHESTS.isEmpty()) {

0 commit comments

Comments
 (0)