Fix getRemainingStock not accounting for shop type (it assumed all shops were buy shops)

This commit is contained in:
Teriuihi 2023-06-04 21:34:21 +02:00
parent 59ef4c23ea
commit af59775ac3

View File

@ -2,10 +2,7 @@ package com.alttd.playershops.shop;
import com.alttd.playershops.PlayerShops; import com.alttd.playershops.PlayerShops;
import com.alttd.playershops.events.*; import com.alttd.playershops.events.*;
import com.alttd.playershops.utils.EconomyUtils; import com.alttd.playershops.utils.*;
import com.alttd.playershops.utils.InventoryUtils;
import com.alttd.playershops.utils.ShopUtil;
import com.alttd.playershops.utils.Util;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.minimessage.MiniMessage; 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 * @return total amount of purchases left until the shop can't sell/buy anymore
*/ */
public int getRemainingStock() { public int getRemainingStock() {
int totalItems = InventoryUtils.countItems(getInventory(), getItemStack()); switch (type) {
if (totalItems == 0) case SELL -> {
return 0; int totalItems = InventoryUtils.countItems(getInventory(), getItemStack());
if (getAmount() == 0) if (totalItems == 0 || getAmount() == 0)
return 0; return 0;
return totalItems / getAmount(); 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() { public int getRemainingSpace() {