mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-24 17:17:49 +01:00
Instead of buy/sell all, shift sells one stack
This commit is contained in:
parent
e0fbe9f31a
commit
f5f883df8e
@ -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?")
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user