add the ability to periodically update items in open auction menus

This commit is contained in:
Ryder Belserion 2024-10-24 17:53:48 -04:00
parent 0394518e75
commit 3d9c011185
No known key found for this signature in database
3 changed files with 26 additions and 12 deletions

View File

@ -59,16 +59,26 @@ public class CrazyAuctions extends Vital {
this.userManager.updateAuctionsCache();
// we want to update this cache, after the cache above... because we will also calculate if items are expired!
this.userManager.updateExpiredCache();
/*new FoliaRunnable(getServer().getGlobalRegionScheduler()) {
new FoliaRunnable(getServer().getGlobalRegionScheduler()) {
@Override
public void run() {
userManager.updateAuctionsCache();
//todo() update existing inventories.
for (final Player player : getServer().getOnlinePlayers()) {
final Inventory inventory = player.getInventory();
if (inventory instanceof AuctionsMenu menu) {
menu.calculateItems();
continue;
}
if (inventory instanceof CurrentMenu menu) {
menu.calculateItems();
}
}
}
}.runAtFixedRate(this, 20, 300 * 5);*/
}.runAtFixedRate(this, 20, 300 * 5);
this.crazyManager = new CrazyManager();
this.crazyManager.load();

View File

@ -82,9 +82,7 @@ public class AuctionsMenu extends Holder {
));
}
getItems(); // populate the inventory
this.maxPages = getMaxPage(this.items);
calculateItems();
HolderManager.addShopType(this.player, this.shopType);
@ -363,7 +361,7 @@ public class AuctionsMenu extends Holder {
GuiManager.openBuying(player, auction_id);
}
private void getItems() {
public void calculateItems() {
this.userManager.getAuctions().forEach(((uuid, auctions) -> auctions.forEach(auction -> {
final ItemBuilder itemBuilder = auction.getActiveItem(this.shopType);
@ -373,5 +371,7 @@ public class AuctionsMenu extends Holder {
this.items.add(auction);
})));
this.maxPages = getMaxPage(this.items);
}
}

View File

@ -45,9 +45,7 @@ public class CurrentMenu extends Holder {
"WhatIsThis.CurrentItems"
));
this.items = this.userManager.getAuctions().get(this.player.getUniqueId());
this.maxPages = getMaxPage(this.items);
calculateItems();
for (final String key : this.options) {
if (!this.config.contains("Settings.GUISettings.OtherSettings." + key)) {
@ -164,4 +162,10 @@ public class CurrentMenu extends Holder {
GuiManager.openPlayersCurrentList(player, menu.getPage());
}
public void calculateItems() {
this.items = this.userManager.getAuctions().get(this.player.getUniqueId());
this.maxPages = getMaxPage(this.items);
}
}