From 187da88de97209204d36c6c8fdf9375887cf68a5 Mon Sep 17 00:00:00 2001 From: Treetrain1 Date: Fri, 15 Sep 2023 20:56:35 -0500 Subject: [PATCH 1/2] actually fix --- .../lib/storage/api/StorageInteraction.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java b/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java index 803b66f3a..9dbc22a26 100644 --- a/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java +++ b/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java @@ -31,17 +31,12 @@ public interface StorageInteraction { long moveResources(Storage storage, T resource, long maxAmount, TransactionContext transaction); default long moveResources(Storage storage, T resource, long maxAmount, TransactionContext transaction, boolean simulate) { - TransactionContext transactionContext = transaction; - if (simulate) - transactionContext = transaction.openNested(); - - long ret = moveResources(storage, resource, maxAmount, transactionContext); if (simulate) { - // can safely cast to transaction because openNested returns a Transaction - // parent transaction should never be committed or aborted by any means - var transaction1 = (Transaction) transaction; - transaction1.close(); + try (Transaction simulateTransaction = Transaction.openNested(transaction)) { + return moveResources(storage, resource, maxAmount, simulateTransaction); + } } - return ret; + + return moveResources(storage, resource, maxAmount, transaction); } } From ed942f8410abd115c2e096bb4f8f2a88becf5406 Mon Sep 17 00:00:00 2001 From: Treetrain1 Date: Fri, 15 Sep 2023 20:58:39 -0500 Subject: [PATCH 2/2] put this comment down --- .../net/frozenblock/lib/storage/api/StorageInteraction.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java b/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java index 9dbc22a26..f492dced4 100644 --- a/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java +++ b/src/main/java/net/frozenblock/lib/storage/api/StorageInteraction.java @@ -32,6 +32,8 @@ public interface StorageInteraction { default long moveResources(Storage storage, T resource, long maxAmount, TransactionContext transaction, boolean simulate) { if (simulate) { + // closes this automatically + // check functionality of AutoCloseable class try (Transaction simulateTransaction = Transaction.openNested(transaction)) { return moveResources(storage, resource, maxAmount, simulateTransaction); }