Skip to content

Commit

Permalink
Merge pull request #16 from GTNewHorizons/fix/memory
Browse files Browse the repository at this point in the history
Convert to foreach over stream
  • Loading branch information
Dream-Master authored Feb 17, 2024
2 parents 7619497 + d130070 commit eeac7dd
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,20 @@ protected final void addHandler(@NotNull String className,
}

protected @NotNull DurabilityLikeInfo getDurabilityLikeInfo(@NotNull ItemStack itemStack) {
return handlers.stream()
.filter(
p -> p.getLeft()
.isInstance(itemStack.getItem()))
.findFirst()
.map(
classFunctionPair -> classFunctionPair.getRight()
.apply(itemStack))
.orElse(new DurabilityLikeInfo(0, 0));
int handlerSize = handlers.size();
for (int i = 0; i < handlerSize; i++) {
Pair<@NotNull Class<?>, @NotNull Function<@NotNull ItemStack, @Nullable DurabilityLikeInfo>> handler = handlers
.get(i);
if (handler.getLeft()
.isInstance(itemStack.getItem())) {
DurabilityLikeInfo info = handler.getRight()
.apply(itemStack);
if (info != null) {
return info;
}
}
}
return new DurabilityLikeInfo(0, 0);
}

protected int getColor(DurabilityLikeInfo info) {
Expand Down

0 comments on commit eeac7dd

Please sign in to comment.