Instead of buy/sell all, shift sells one stack

This commit is contained in:
Acrobot 2013-04-05 14:17:34 +02:00
parent e0fbe9f31a
commit f5f883df8e
2 changed files with 10 additions and 9 deletions

View File

@ -20,10 +20,10 @@ public class Properties {
@ConfigurationComment("If true, people will buy with left-click and sell with right-click.") @ConfigurationComment("If true, people will buy with left-click and sell with right-click.")
public static boolean REVERSE_BUTTONS = false; public static boolean REVERSE_BUTTONS = false;
@ConfigurationComment("If true, people will be able to sell/buy everything available of the same type.") @ConfigurationComment("If true, people will be able to buy/sell in 64 stacks while holding the crouch button.")
public static boolean SHIFT_SELLS_EVERYTHING = false; 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"; public static String SHIFT_ALLOWS = "ALL";
@ConfigurationComment("Can shop's chest be opened by owner with right-clicking a shop's sign?") @ConfigurationComment("Can shop's chest be opened by owner with right-clicking a shop's sign?")

View File

@ -137,8 +137,8 @@ public class PlayerInteract implements Listener {
amount = 1; amount = 1;
} }
if (Properties.SHIFT_SELLS_EVERYTHING && player.isSneaking() && price != PriceUtil.NO_PRICE && isAllowedForShift(action == buy)) { if (Properties.SHIFT_SELLS_IN_STACKS && player.isSneaking() && price != PriceUtil.NO_PRICE && isAllowedForShift(action == buy)) {
int newAmount = getItemAmount(item, ownerInventory, player, action); int newAmount = getStackAmount(item, ownerInventory, player, action);
if (newAmount > 0) { if (newAmount > 0) {
price = (price / amount) * newAmount; price = (price / amount) * newAmount;
amount = newAmount; amount = newAmount;
@ -163,13 +163,14 @@ public class PlayerInteract implements Listener {
return allowed.equalsIgnoreCase(buyTransaction ? "BUY" : "SELL"); 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; Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK;
Inventory checkedInventory = (action == buy ? inventory : player.getInventory());
if (action == buy) { if (checkedInventory.containsAtLeast(item, item.getMaxStackSize())) {
return InventoryUtil.getAmount(item, inventory); return item.getMaxStackSize();
} else { } else {
return InventoryUtil.getAmount(item, player.getInventory()); return InventoryUtil.getAmount(item, checkedInventory);
} }
} }