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:
parent
da5e514422
commit
55cb197b0b
|
|
@ -111,7 +111,7 @@ public class TransactionListener extends EventListener {
|
||||||
switch (playerShop.getType()) {
|
switch (playerShop.getType()) {
|
||||||
case SELL -> {
|
case SELL -> {
|
||||||
type = Placeholder.unparsed("type", "Sell");
|
type = Placeholder.unparsed("type", "Sell");
|
||||||
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock() / playerShop.getAmount()));
|
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock()));
|
||||||
}
|
}
|
||||||
case BUY -> {
|
case BUY -> {
|
||||||
type = Placeholder.unparsed("type", "Buy");
|
type = Placeholder.unparsed("type", "Buy");
|
||||||
|
|
@ -119,7 +119,7 @@ public class TransactionListener extends EventListener {
|
||||||
}
|
}
|
||||||
case GAMBLE -> {
|
case GAMBLE -> {
|
||||||
type = Placeholder.unparsed("type", "Gamble");
|
type = Placeholder.unparsed("type", "Gamble");
|
||||||
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock() / playerShop.getAmount()));
|
stock = Placeholder.parsed("stock", "" + (playerShop.getRemainingStock()));
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
type = Placeholder.unparsed("type", "UNKNOWN");
|
type = Placeholder.unparsed("type", "UNKNOWN");
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,16 @@ public class PlayerShop {
|
||||||
return playerShop;
|
return playerShop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return total amount of purchases left until the shop can't sell/buy anymore
|
||||||
|
*/
|
||||||
public int getRemainingStock() {
|
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() {
|
public int getRemainingSpace() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user