Fix getRemainingStock not accounting for shop type (it assumed all shops were buy shops)
This commit is contained in:
parent
59ef4c23ea
commit
af59775ac3
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user