Skip to content

Instantly share code, notes, and snippets.

@theresajayne
Last active June 21, 2019 08:35
Show Gist options
  • Save theresajayne/adb1412ac4ef97be1eda6a002bcebc2c to your computer and use it in GitHub Desktop.
Save theresajayne/adb1412ac4ef97be1eda6a002bcebc2c to your computer and use it in GitHub Desktop.
//Amount is now the total number of items in the chest - we will need this later
if (amount >= shop.getQuantity()) {
//We have enough items so sell to the shopper
player.sendMessage("You paid $" + shop.getBuyPrice() + " for " + shop.getQuantity() + " " + shop.getDescription());
PayDay.getInstance().getEconomyService().subtract(player, shop.getBuyPrice());
PayDay.getInstance().getEconomyService().add(shop.getPlayerName(), shop.getBuyPrice());
player.getInventory().addItem(item);
amount = amount - shop.getQuantity();
int remaining = amount;
chest.getInventory().clear();
while (remaining > 0) {
if (remaining > item.getMaxStackSize()) {
ItemStack itemStack = new ItemStack(item.getType(), item.getMaxStackSize(),item.getDurability());
chest.getInventory().addItem(itemStack);
remaining = remaining - item.getMaxStackSize();
} else {
//Last bit of a stack
ItemStack itemStack = new ItemStack(item.getType(), remaining,item.getDurability());
chest.getInventory().addItem(itemStack);
remaining = 0;
}
}
chest.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment