From 78eb6a1c7db010711e361909c2019ce5ca9d79b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ossi=20Erkkil=C3=A4?= Date: Thu, 3 Sep 2026 20:57:31 +0300 Subject: [PATCH] Fix multiple transaction related issues - SpongeMutableDataHolder#undo returned DataTransactionResult.failNoData() instead of the actual result. - InventoryTransactionResultImpl#and discarded the polled items of the other transaction - InventoryTransactionResultImpl#and returned a SUCCESS transaction when `type == NO_SLOT` - InventoryTransactionResultImpl.Builder from & reset ignored polled items --- .../common/data/holder/SpongeMutableDataHolder.java | 2 +- .../inventory/InventoryTransactionResultImpl.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/spongepowered/common/data/holder/SpongeMutableDataHolder.java b/src/main/java/org/spongepowered/common/data/holder/SpongeMutableDataHolder.java index 0d11a8f2e65..4824be46b76 100644 --- a/src/main/java/org/spongepowered/common/data/holder/SpongeMutableDataHolder.java +++ b/src/main/java/org/spongepowered/common/data/holder/SpongeMutableDataHolder.java @@ -293,7 +293,7 @@ default DataTransactionResult undo(DataTransactionResult result) { for (final Value value : result.successfulData()) { builder.absorbResult(this.remove(value)); } - return DataTransactionResult.failNoData(); + return builder.build(); } // Delegated diff --git a/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java b/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java index 38317b9c96f..7f863b72d1b 100644 --- a/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java +++ b/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java @@ -58,17 +58,21 @@ public class InventoryTransactionResultImpl implements InventoryTransactionResul @Override public InventoryTransactionResult and(InventoryTransactionResult other) { - Type resultType = Type.SUCCESS; + final Type resultType; if (this.type == Type.ERROR || other.type() == Type.ERROR) { resultType = Type.ERROR; - } - if (this.type == Type.FAILURE || other.type() == Type.FAILURE) { + } else if (this.type == Type.FAILURE || other.type() == Type.FAILURE) { resultType = Type.FAILURE; + } else if (this.type == Type.NO_SLOT || other.type() == Type.NO_SLOT) { + resultType = Type.NO_SLOT; + } else { + resultType = Type.SUCCESS; } InventoryTransactionResult.Builder builder = InventoryTransactionResult.builder().type(resultType).reject(this.rejected).reject(other.rejectedItems()) .transaction(this.slotTransactions).transaction(other.slotTransactions()); this.polled.forEach(builder::poll); + other.polledItems().forEach(builder::poll); return builder.build(); } @@ -189,6 +193,7 @@ public InventoryTransactionResult.Builder from(InventoryTransactionResult value) this.resultType = Objects.requireNonNull(value.type(), "ResultType cannot be null!"); this.slotTransactions = new ArrayList<>(value.slotTransactions()); this.rejected = new ArrayList<>(value.rejectedItems()); + this.polled = new ArrayList<>(value.polledItems()); return this; } @@ -197,6 +202,7 @@ public InventoryTransactionResult.Builder reset() { this.resultType = null; this.rejected = null; this.slotTransactions = null; + this.polled = null; return this; }