Changed getStock to only return the actual stock they have left instead of the total amount of items left (and protected it)

This commit is contained in:
Teriuihi 2023-01-22 22:04:46 +01:00
parent da5e514422
commit 55cb197b0b
2 changed files with 11 additions and 3 deletions

View File

@ -111,7 +111,7 @@ public class TransactionListener extends EventListener {
switch (playerShop.getType()) {
case SELL -> {
type = Placeholder.unparsed("type", "Sell");
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock() / playerShop.getAmount()));
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock()));
}
case BUY -> {
type = Placeholder.unparsed("type", "Buy");
@ -119,7 +119,7 @@ public class TransactionListener extends EventListener {
}
case GAMBLE -> {
type = Placeholder.unparsed("type", "Gamble");
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock() / playerShop.getAmount()));
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock()));
}
default -> {
type = Placeholder.unparsed("type", "UNKNOWN");

View File

@ -84,8 +84,16 @@ public class PlayerShop {
return playerShop;
}
/**
* @return total amount of purchases left until the shop can't sell/buy anymore
*/
public int getRemainingStock() {
return InventoryUtils.countItems(getInventory(), getItemStack());
int totalItems = InventoryUtils.countItems(getInventory(), getItemStack());
if (totalItems == 0)
return 0;
if (getAmount() == 0)
return 0;
return totalItems / getAmount();
}
public int getRemainingSpace() {