@@ -53,7 +53,7 @@ private RevertHelper() {
53
53
*/
54
54
public static boolean revert (@ Nullable final ItemStack itemStack , @ Nullable final Location location ,
55
55
final boolean checkRecursive , @ NotNull final Predicate <ItemState > predicate ) {
56
- return predicate .test (checkItemStack (itemStack , location , checkRecursive ));
56
+ return predicate .test (checkItemStack (itemStack , location , checkRecursive , true )); // Using cache
57
57
}
58
58
59
59
/**
@@ -195,7 +195,7 @@ public static RevertionResult checkInventory(@NotNull final Inventory inventory,
195
195
boolean wasFixed = false ;
196
196
197
197
for (final ItemStack itemStack : inventory .getContents ()) {
198
- switch (checkItemStack (itemStack , location , checkRecursive )) {
198
+ switch (checkItemStack (itemStack , location , checkRecursive , false )) {
199
199
case ILLEGAL -> removeItemStacks .add (itemStack );
200
200
case WAS_FIXED -> wasFixed = true ;
201
201
case IS_BOOK -> bookItemStacks .add (itemStack );
@@ -287,22 +287,28 @@ public static void checkArmorContents(@NotNull final PlayerInventory playerInven
287
287
* @param itemStack the item to revert
288
288
* @param location the location where books / book shulkers should drop (if any)
289
289
* @param checkRecursive whether containers in item form should be checked for their content recursively
290
+ * @param useCache whether to use the cache for item state checks
290
291
* @return the state of the item that was checked
291
292
*/
292
293
@ NotNull
293
294
public static ItemState checkItemStack (@ Nullable final ItemStack itemStack , @ Nullable final Location location ,
294
- final boolean checkRecursive ) {
295
+ final boolean checkRecursive , final boolean useCache ) {
296
+
295
297
if (itemStack == null || itemStack .getType () == Material .AIR || itemStack .getAmount () == 0 )
296
298
return ItemState .EMPTY ;
297
299
298
300
final int metaHash = CachedState .itemStackHashCode (itemStack );
299
- final CachedState cachedRevertedItem = REVERTED_ITEM_CACHE .getIfPresent (metaHash );
301
+
302
+ CachedState cachedRevertedItem = useCache ? REVERTED_ITEM_CACHE .getIfPresent (metaHash ) : null ;
303
+
300
304
301
305
if (cachedRevertedItem == null ) {
302
306
final ItemState revertedState = checkItemStackUncached (itemStack , location , checkRecursive );
303
- if (revertedState .wasModified ())
304
- REVERTED_ITEM_CACHE .put (metaHash , new CachedState (itemStack .clone (), revertedState ));
305
307
308
+ if (revertedState .wasModified () && useCache ) {
309
+
310
+ REVERTED_ITEM_CACHE .put (metaHash , new CachedState (itemStack .clone (), revertedState ));
311
+ }
306
312
return revertedState ;
307
313
}
308
314
cachedRevertedItem .applyRevertedState (itemStack );
0 commit comments