Optimized custom item cache

This commit is contained in:
Auxilor
2022-03-05 12:34:39 +00:00
parent 44924cdf83
commit a22ad1b22d
3 changed files with 16 additions and 0 deletions

View File

@@ -116,6 +116,13 @@ public interface FastItemStack {
*/
boolean hasItemFlag(@NotNull ItemFlag flag);
/**
* Get if the item has any nbt data.
*
* @return If any nbt data is present on the item.
*/
boolean hasAnyNBT();
/**
* Get the Bukkit ItemStack again.
*

View File

@@ -2,6 +2,7 @@ package com.willfp.eco.core.items;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.willfp.eco.core.fast.FastItemStack;
import com.willfp.eco.core.items.args.LookupArgParser;
import com.willfp.eco.core.items.provider.ItemProvider;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
@@ -45,6 +46,10 @@ public final class Items {
.expireAfterAccess(5, TimeUnit.MINUTES)
.build(
key -> {
if (!FastItemStack.wrap(key.getItem()).hasAnyNBT()) {
return Optional.empty();
}
TestableItem match = null;
for (TestableItem item : REGISTRY.values()) {
if (item.matches(key.getItem())) {