possible fix for #97

Took 11 minutes
This commit is contained in:
Kiran Hart 2024-08-19 12:14:57 -04:00
parent 38c36729db
commit af89cbc2be
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3

View File

@ -33,6 +33,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -94,10 +95,15 @@ public abstract class AuctionUpdatingPagedGUI<T> extends BaseGUI {
if (this.items != null) { if (this.items != null) {
AuctionHouse.newChain().asyncFirst(() -> { AuctionHouse.newChain().asyncFirst(() -> {
this.fillSlots().forEach(slot -> setItem(slot, getDefaultItem())); this.fillSlots().forEach(slot -> setItem(slot, getDefaultItem()));
List<T> itemsCopy;
synchronized (this.items) {
itemsCopy = new ArrayList<>(this.items);
}
prePopulate(); prePopulate();
final List<T> itemsToFill = this.items.stream().skip((page - 1) * (long) this.fillSlots().size()).limit(this.fillSlots().size()).collect(Collectors.toList()); return itemsCopy.stream().skip((page - 1) * (long) this.fillSlots().size()).limit(this.fillSlots().size()).collect(Collectors.toCollection(ArrayList::new));
return itemsToFill;
}).asyncLast((data) -> { }).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) this.fillSlots().size())); pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) this.fillSlots().size()));