diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index e7e54f4..ac2834a 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -20,10 +20,10 @@ public class Properties { @ConfigurationComment("If true, people will buy with left-click and sell with right-click.") public static boolean REVERSE_BUTTONS = false; - @ConfigurationComment("If true, people will be able to sell/buy everything available of the same type.") - public static boolean SHIFT_SELLS_EVERYTHING = false; + @ConfigurationComment("If true, people will be able to buy/sell in 64 stacks while holding the crouch button.") + public static boolean SHIFT_SELLS_IN_STACKS = false; - @ConfigurationComment("What can you do by clicking shift with SHIFT_SELLS_EVERYTHING turned on? (ALL/BUY/SELL)") + @ConfigurationComment("What can you do by clicking shift with SHIFT_SELLS_IN_STACKS turned on? (ALL/BUY/SELL)") public static String SHIFT_ALLOWS = "ALL"; @ConfigurationComment("Can shop's chest be opened by owner with right-clicking a shop's sign?") diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java index 0827dc3..f22756b 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -137,8 +137,8 @@ public class PlayerInteract implements Listener { amount = 1; } - if (Properties.SHIFT_SELLS_EVERYTHING && player.isSneaking() && price != PriceUtil.NO_PRICE && isAllowedForShift(action == buy)) { - int newAmount = getItemAmount(item, ownerInventory, player, action); + if (Properties.SHIFT_SELLS_IN_STACKS && player.isSneaking() && price != PriceUtil.NO_PRICE && isAllowedForShift(action == buy)) { + int newAmount = getStackAmount(item, ownerInventory, player, action); if (newAmount > 0) { price = (price / amount) * newAmount; amount = newAmount; @@ -163,13 +163,14 @@ public class PlayerInteract implements Listener { return allowed.equalsIgnoreCase(buyTransaction ? "BUY" : "SELL"); } - private static int getItemAmount(ItemStack item, Inventory inventory, Player player, Action action) { + private static int getStackAmount(ItemStack item, Inventory inventory, Player player, Action action) { Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK; + Inventory checkedInventory = (action == buy ? inventory : player.getInventory()); - if (action == buy) { - return InventoryUtil.getAmount(item, inventory); + if (checkedInventory.containsAtLeast(item, item.getMaxStackSize())) { + return item.getMaxStackSize(); } else { - return InventoryUtil.getAmount(item, player.getInventory()); + return InventoryUtil.getAmount(item, checkedInventory); } }