From af89cbc2bef5a9f793a31be55058487873fc4454 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 19 Aug 2024 12:14:57 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20possible=20fix=20for=20#97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 11 minutes --- .../auctionhouse/guis/AuctionUpdatingPagedGUI.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/AuctionUpdatingPagedGUI.java b/src/main/java/ca/tweetzy/auctionhouse/guis/AuctionUpdatingPagedGUI.java index 779bd29..ef9031a 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/AuctionUpdatingPagedGUI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/AuctionUpdatingPagedGUI.java @@ -33,6 +33,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitTask; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -94,10 +95,15 @@ public abstract class AuctionUpdatingPagedGUI extends BaseGUI { if (this.items != null) { AuctionHouse.newChain().asyncFirst(() -> { this.fillSlots().forEach(slot -> setItem(slot, getDefaultItem())); + + List itemsCopy; + synchronized (this.items) { + itemsCopy = new ArrayList<>(this.items); + } + prePopulate(); - final List itemsToFill = this.items.stream().skip((page - 1) * (long) this.fillSlots().size()).limit(this.fillSlots().size()).collect(Collectors.toList()); - return itemsToFill; + return itemsCopy.stream().skip((page - 1) * (long) this.fillSlots().size()).limit(this.fillSlots().size()).collect(Collectors.toCollection(ArrayList::new)); }).asyncLast((data) -> { pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) this.fillSlots().size()));