Add option to sell/buy all with shift (#320)

This commit is contained in:
Phoenix616 2020-05-31 14:50:53 +01:00
parent f0641abf2e
commit 9f84ca8551
2 changed files with 17 additions and 0 deletions

View File

@ -130,6 +130,9 @@ public class Properties {
@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("If true, people will be able to sell/buy everything available of the same type.")
public static boolean SHIFT_SELLS_EVERYTHING = false;
@ConfigurationComment("What can you do by clicking shift with SHIFT_SELLS_IN_STACKS turned on? (ALL/BUY/SELL)")
public static String SHIFT_ALLOWS = "ALL";

View File

@ -203,6 +203,20 @@ public class PlayerInteract implements Listener {
price = price.divide(BigDecimal.valueOf(amount), MathContext.DECIMAL128).multiply(BigDecimal.valueOf(newAmount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
amount = newAmount;
}
} else if (Properties.SHIFT_SELLS_EVERYTHING && player.isSneaking() && !price.equals(PriceUtil.NO_PRICE) && isAllowedForShift(action == buy)) {
if (action != buy) {
int newAmount = InventoryUtil.getAmount(item, player.getInventory());
if (newAmount > 0) {
price = price.divide(BigDecimal.valueOf(amount), MathContext.DECIMAL128).multiply(BigDecimal.valueOf(newAmount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
amount = newAmount;
}
} else if (!adminShop && ownerInventory != null) {
int newAmount = InventoryUtil.getAmount(item, ownerInventory);
if (newAmount > 0) {
price = price.divide(BigDecimal.valueOf(amount), MathContext.DECIMAL128).multiply(BigDecimal.valueOf(newAmount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
amount = newAmount;
}
}
}
item.setAmount(amount);