Skip to content

Commit a9c9fa0

Browse files
Use async stock fetching in UIs to improve accuracy and ensure up-to-date display. Add axolotyl and tropical fish variants to fish_bucket custom matcher component. (#2426)
* Add tropical fish and axolotyl variants to ModernCustomMatcher under fish_bucket. * Use async stock fetching in UIs to improve accuracy and ensure up-to-date display. Add axolotyl and tropical fish variants to fish_bucket custom matcher component.
1 parent 48edb07 commit a9c9fa0

6 files changed

Lines changed: 102 additions & 30 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 6.3.0.0 (Orion: Rigel) SNAPSHOT 11
2+
3+
## Minor Changes
4+
- Modified fish_bucket custom matcher component to include the following components:
5+
- "AXOLOTL/VARIANT",
6+
- "SALMON/SIZE",
7+
- "TROPICAL_FISH/PATTERN",
8+
- "TROPICAL_FISH/BASE_COLOR",
9+
- "TROPICAL_FISH/BASE_COLOR"
10+
11+
## Internal Changes
12+
- Adjusted trade ui to use a stock variable instead of the cache, this should fix issues where stock information was sometimes inaccurate while not sacrificing performance.

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/menu/ShopKeeperMenu.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class ShopKeeperMenu extends QuickShopMenu {
3333
public static final int KEEPER_MAIN = 1;
3434

3535
public static final String SHOP_DATA_ID = "SHOP_ID";
36+
public static final String SHOP_STOCK_ID = "SHOP_STOCK_REMAINING";
3637

3738
public ShopKeeperMenu() {
3839

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/menu/trade/MainPage.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import java.util.Optional;
5252
import java.util.UUID;
5353

54+
import static com.ghostchu.quickshop.menu.ShopKeeperMenu.SHOP_STOCK_ID;
55+
5456
/**
5557
* MainPage
5658
*
@@ -104,9 +106,22 @@ public void handle(final PageOpenCallback open) {
104106

105107
final ItemStack shopItem = shop.get().getItem();
106108
final int amount = shopItem.getAmount();
107-
// Use cache to avoid Folia cross-region block access issues
108-
final int stock = (shop.get().isBuying())? -1 : MarketUtils.getStockFromCache(shop.get());
109-
final String stockString = (shop.get().isUnlimited())? "Unlimited" : stock + "";
109+
110+
final int remainingStock = (int)viewer.get().dataOrDefault(SHOP_STOCK_ID, MarketUtils.getStockFromCache(shop.get()));
111+
final QuickShop plugin = QuickShop.getInstance();
112+
final String baseKey = (shop.get().isStackingShop())? shop.get().shopType().stackTradingTranslationKey()
113+
: shop.get().shopType().tradingTranslationKey();
114+
final String finalKey = (shop.get().shopState().overrideShopTypeText())? shop.get().shopState().translationKey() : baseKey;
115+
116+
final Component stockComponent = switch (remainingStock) {
117+
118+
case -1 -> plugin.text().of(player, finalKey, plugin.text().of(player, "signs.unlimited").forLocale()).forLocale();
119+
120+
case 0 -> (shop.get().shopState().overrideShopTypeText())? plugin.text().of(player, shop.get().shopState().translationKey()).forLocale()
121+
: plugin.text().of(player, shop.get().shopType().outOfStockTranslationKey()).forLocale();
122+
123+
default -> Component.text(remainingStock);
124+
};
110125
final String priceFormatted = shop.get().format(shop.get().bukkitLocation().getWorld().getName(), shop.get().getCurrency());
111126

112127
// Shop item display slot from config (centered in row 2)
@@ -130,7 +145,7 @@ public void handle(final PageOpenCallback open) {
130145
final int infoStockSlot = (infoStockConfig != null)? infoStockConfig.getSlot() : 21;
131146
open.getPage().addIcon(new IconBuilder(QuickShop.getInstance().stack().of(infoStockMaterial, 1)
132147
.customName(getConfigDisplay(id, infoStockConfig, "<yellow>Stock Information</yellow>"))
133-
.lore(getConfigLore(id, infoStockConfig, stockString)))
148+
.lore(getConfigLore(id, infoStockConfig, stockComponent)))
134149
.withSlot(infoStockSlot).build());
135150

136151
// Info icons row - Price info
@@ -163,7 +178,7 @@ public void handle(final PageOpenCallback open) {
163178
final String enterPath = (shop.get().isSelling())? "trade.enter-buy" : "trade.enter-sell";
164179
open.getPage().addIcon(new IconBuilder(QuickShop.getInstance().stack().of(customAmountMaterial, 1)
165180
.customName(getConfigDisplay(id, customAmountConfig, "<bold><blue>Custom Order</blue></bold>"))
166-
.lore(getConfigLore(id, customAmountConfig, amount, stockString)))
181+
.lore(getConfigLore(id, customAmountConfig, amount, stockComponent)))
167182
.withActions(new GuiChatAction((message)->{
168183
if(!message.isEmpty()) {
169184
try {
@@ -173,7 +188,7 @@ public void handle(final PageOpenCallback open) {
173188
return true;
174189
}
175190

176-
if(!shop.get().isUnlimited() && quantity > stock && stock > -1) {
191+
if(!shop.get().isUnlimited() && quantity > remainingStock && remainingStock > -1) {
177192
player.sendMessage(guiMessage("trade.invalid-stock"));
178193
return true;
179194
}

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/shop/interaction/behaviors/ControlPanelUI.java

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.jetbrains.annotations.NotNull;
3939
import org.jetbrains.annotations.Nullable;
4040

41+
import java.util.concurrent.CompletableFuture;
42+
4143
/**
4244
* ControlPanelUI
4345
*
@@ -78,10 +80,15 @@ public void handle(final @NotNull QuickShopAPI plugin, final @Nullable Shop shop
7880
if(group.equalsIgnoreCase(BuiltInShopPermissionGroup.STAFF.getNamespacedNode())
7981
|| group.equalsIgnoreCase(BuiltInShopPermissionGroup.ADMINISTRATOR.getNamespacedNode())) {
8082

81-
MenuManager.instance().addViewer(viewer);
8283

83-
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(event.getPlayer());
84-
MenuManager.instance().open("qs:keeper", 1, menuPlayer);
84+
final CompletableFuture<Integer> remainingStockFuture = shop.shopType().remainingStockAsync(shop);
85+
remainingStockFuture.thenAccept(remainingStock ->{
86+
viewer.addData(ShopKeeperMenu.SHOP_STOCK_ID, remainingStock);
87+
MenuManager.instance().addViewer(viewer);
88+
89+
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(event.getPlayer());
90+
MenuManager.instance().open("qs:keeper", 1, menuPlayer);
91+
});
8592

8693
event.setCancelled(true);
8794
event.setUseInteractedBlock(Event.Result.DENY);
@@ -100,10 +107,16 @@ public void handle(final @NotNull QuickShopAPI plugin, final @Nullable Shop shop
100107
return;
101108
}
102109

103-
MenuManager.instance().addViewer(viewer);
104110

105-
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(event.getPlayer());
106-
MenuManager.instance().open("qs:trade", 1, menuPlayer);
111+
final CompletableFuture<Integer> remainingStockFuture = shop.shopType().remainingStockAsync(shop);
112+
remainingStockFuture.thenAccept(remainingStock ->{
113+
viewer.addData(ShopKeeperMenu.SHOP_STOCK_ID, remainingStock);
114+
115+
MenuManager.instance().addViewer(viewer);
116+
117+
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(event.getPlayer());
118+
MenuManager.instance().open("qs:trade", 1, menuPlayer);
119+
});
107120

108121

109122
event.setCancelled(true);
@@ -141,10 +154,17 @@ private void handle(final @NotNull QuickShopAPI plugin, @NotNull final Shop shop
141154
if(group.equalsIgnoreCase(BuiltInShopPermissionGroup.STAFF.getNamespacedNode())
142155
|| group.equalsIgnoreCase(BuiltInShopPermissionGroup.ADMINISTRATOR.getNamespacedNode())) {
143156

144-
MenuManager.instance().addViewer(viewer);
145157

146-
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(player);
147-
MenuManager.instance().open("qs:keeper", 1, menuPlayer);
158+
final CompletableFuture<Integer> remainingStockFuture = shop.shopType().remainingStockAsync(shop);
159+
remainingStockFuture.thenAccept(remainingStock ->{
160+
161+
viewer.addData(ShopKeeperMenu.SHOP_STOCK_ID, remainingStock);
162+
163+
MenuManager.instance().addViewer(viewer);
164+
165+
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(player);
166+
MenuManager.instance().open("qs:keeper", 1, menuPlayer);
167+
});
148168
return;
149169
}
150170

@@ -159,9 +179,15 @@ private void handle(final @NotNull QuickShopAPI plugin, @NotNull final Shop shop
159179
return;
160180
}
161181

162-
MenuManager.instance().addViewer(viewer);
182+
final CompletableFuture<Integer> remainingStockFuture = shop.shopType().remainingStockAsync(shop);
183+
remainingStockFuture.thenAccept(remainingStock ->{
163184

164-
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(player);
165-
MenuManager.instance().open("qs:trade", 1, menuPlayer);
185+
viewer.addData(ShopKeeperMenu.SHOP_STOCK_ID, remainingStock);
186+
187+
MenuManager.instance().addViewer(viewer);
188+
189+
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(player);
190+
MenuManager.instance().open("qs:trade", 1, menuPlayer);
191+
});
166192
}
167193
}

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/shop/interaction/behaviors/TradeUI.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.jetbrains.annotations.NotNull;
3939
import org.jetbrains.annotations.Nullable;
4040

41+
import java.util.concurrent.CompletableFuture;
42+
4143
/**
4244
* TradeUI
4345
*
@@ -93,12 +95,18 @@ public void handle(final @NotNull QuickShopAPI plugin, final @Nullable Shop shop
9395
return;
9496
}
9597

96-
final MenuViewer viewer = new MenuViewer(event.getPlayer().getUniqueId());
97-
viewer.addData(ShopKeeperMenu.SHOP_DATA_ID, shop.getShopId());
98-
MenuManager.instance().addViewer(viewer);
98+
final CompletableFuture<Integer> remainingStockFuture = shop.shopType().remainingStockAsync(shop);
99+
remainingStockFuture.thenAccept(remainingStock -> {
99100

100-
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(event.getPlayer());
101-
MenuManager.instance().open("qs:trade", 1, menuPlayer);
101+
102+
final MenuViewer viewer = new MenuViewer(event.getPlayer().getUniqueId());
103+
viewer.addData(ShopKeeperMenu.SHOP_DATA_ID, shop.getShopId());
104+
viewer.addData(ShopKeeperMenu.SHOP_STOCK_ID, remainingStock);
105+
MenuManager.instance().addViewer(viewer);
106+
107+
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(event.getPlayer());
108+
MenuManager.instance().open("qs:trade", 1, menuPlayer);
109+
});
102110

103111
//cancel our item use
104112
event.setCancelled(true);
@@ -141,12 +149,17 @@ private void handle(final @NotNull QuickShopAPI plugin, final Cancellable event,
141149
return;
142150
}
143151

144-
final MenuViewer viewer = new MenuViewer(player.getUniqueId());
145-
viewer.addData(ShopKeeperMenu.SHOP_DATA_ID, shop.getShopId());
146-
MenuManager.instance().addViewer(viewer);
152+
final CompletableFuture<Integer> remainingStockFuture = shop.shopType().remainingStockAsync(shop);
153+
remainingStockFuture.thenAccept(remainingStock ->{
147154

148-
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(player);
149-
MenuManager.instance().open("qs:trade", 1, menuPlayer);
155+
final MenuViewer viewer = new MenuViewer(player.getUniqueId());
156+
viewer.addData(ShopKeeperMenu.SHOP_DATA_ID, shop.getShopId());
157+
viewer.addData(ShopKeeperMenu.SHOP_STOCK_ID, remainingStock);
158+
MenuManager.instance().addViewer(viewer);
159+
160+
final MenuPlayer menuPlayer = QuickShop.getInstance().createMenuPlayer(player);
161+
MenuManager.instance().open("qs:trade", 1, menuPlayer);
162+
});
150163

151164
//cancel our item use
152165
event.setCancelled(true);

quickshop-bukkit/src/main/java/com/ghostchu/quickshop/util/matcher/item/ModernCustomMatcher.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,14 @@ private void expandGroup(final Set<DataComponentType.Valued<?>> out,
256256
"DYED_COLOR"
257257
);
258258

259-
// Fish bucket entity data
259+
// Fish bucket entity data, and various fish variants
260260
case "fish_bucket" -> add(out, registry,
261-
"BUCKET_ENTITY_DATA"
261+
"BUCKET_ENTITY_DATA",
262+
"AXOLOTL/VARIANT",
263+
"SALMON/SIZE",
264+
"TROPICAL_FISH/PATTERN",
265+
"TROPICAL_FISH/BASE_COLOR",
266+
"TROPICAL_FISH/BASE_COLOR"
262267
);
263268

264269
// Suspicious stew effects

0 commit comments

Comments
 (0)