Skip to content
Browse files
Fix duping when getting held item meta on block_place.
The item's tags were being modified on read, causing this and probably other lesser issues. This affected shulker boxes, bee nests, beehives, and shields.
  • Loading branch information
PseudoKnight committed Jun 16, 2020
1 parent 675fab0 commit d37f1a701a99c55360dcb99c8d8dbd130a5cd0a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
@@ -6,6 +6,8 @@ public interface MCBlockStateMeta extends MCItemMeta {

MCBlockState getBlockState();

MCBlockState getBlockState(boolean copy);

void setBlockState(MCBlockState state);

@@ -19,9 +19,22 @@ public BukkitMCBlockStateMeta(BlockStateMeta meta) {

public MCBlockState getBlockState() {
return getBlockState(false);

public MCBlockState getBlockState(boolean copy) {
BlockStateMeta meta = bsm;
if(copy) {
// Getting a BlockState currently writes to the block entity tags for some block types.
// Since the tags are no longer equal when compared later, unexpected behavior can occur.
// For example, when getting a shulker box's BlockState on BlockPlaceEvent, it can duplicate the item.
// Copying the meta before getting the block state ensures the original tags are unaffected.
meta = ((BlockStateMeta) meta.clone());
BlockState bs;
try {
bs = bsm.getBlockState();
bs = meta.getBlockState();
} catch (Exception ex) {
// Broken server implementation.
Static.getLogger().log(Level.WARNING, ex.getMessage() + " when"
@@ -463,7 +463,7 @@ public Construct itemMeta(MCItemStack is, Target t) {

// Specific ItemMeta
if(meta instanceof MCBlockStateMeta) {
MCBlockState bs = ((MCBlockStateMeta) meta).getBlockState();
MCBlockState bs = ((MCBlockStateMeta) meta).getBlockState(true);
if(bs instanceof MCContainer || bs instanceof MCDispenser || bs instanceof MCDropper) {
// Handle InventoryHolders with inventory slots that do not have a special meaning.
MCInventory inv = ((MCInventoryHolder) bs).getInventory();

0 comments on commit d37f1a7

Please sign in to comment.