From af59775ac3458a25a8b8b37817dc86094223c84a Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sun, 4 Jun 2023 21:34:21 +0200 Subject: [PATCH] Fix getRemainingStock not accounting for shop type (it assumed all shops were buy shops) --- .../alttd/playershops/shop/PlayerShop.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/alttd/playershops/shop/PlayerShop.java b/src/main/java/com/alttd/playershops/shop/PlayerShop.java index 495fc3e..79aa5b9 100644 --- a/src/main/java/com/alttd/playershops/shop/PlayerShop.java +++ b/src/main/java/com/alttd/playershops/shop/PlayerShop.java @@ -2,10 +2,7 @@ package com.alttd.playershops.shop; import com.alttd.playershops.PlayerShops; import com.alttd.playershops.events.*; -import com.alttd.playershops.utils.EconomyUtils; -import com.alttd.playershops.utils.InventoryUtils; -import com.alttd.playershops.utils.ShopUtil; -import com.alttd.playershops.utils.Util; +import com.alttd.playershops.utils.*; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -88,12 +85,26 @@ public class PlayerShop { * @return total amount of purchases left until the shop can't sell/buy anymore */ public int getRemainingStock() { - int totalItems = InventoryUtils.countItems(getInventory(), getItemStack()); - if (totalItems == 0) - return 0; - if (getAmount() == 0) - return 0; - return totalItems / getAmount(); + switch (type) { + case SELL -> { + int totalItems = InventoryUtils.countItems(getInventory(), getItemStack()); + if (totalItems == 0 || getAmount() == 0) + return 0; + return totalItems / getAmount(); + } + case BUY -> { + if (balance == 0 || getAmount() == 0) + return 0; + return (int) (balance / getPrice()); + } + case GAMBLE -> { + Logger.warn("Tried to call getRemainingStock on unimplemented GAMBLE type"); + return 0; //not implemented since gamble shops don't exist yet + } + default -> { + return 0; + } + } } public int getRemainingSpace() {