mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-09-26 21:52:57 +02:00
Properly set scale and rounding mode for divisions (Fixes #220)
This commit is contained in:
parent
f0bc277566
commit
8cf9934a32
@ -32,7 +32,7 @@ public class TaxModule implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static BigDecimal getTaxAmount(BigDecimal price, float taxAmount) {
|
private static BigDecimal getTaxAmount(BigDecimal price, float taxAmount) {
|
||||||
return price.multiply(BigDecimal.valueOf(taxAmount)).divide(BigDecimal.valueOf(100), BigDecimal.ROUND_DOWN);
|
return price.multiply(BigDecimal.valueOf(taxAmount)).divide(BigDecimal.valueOf(100), Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
@ -196,7 +196,7 @@ public class PlayerInteract implements Listener {
|
|||||||
if (Properties.SHIFT_SELLS_IN_STACKS && 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 = adminShop ? InventoryUtil.getMaxStackSize(item) : getStackAmount(item, ownerInventory, player, action);
|
int newAmount = adminShop ? InventoryUtil.getMaxStackSize(item) : getStackAmount(item, ownerInventory, player, action);
|
||||||
if (newAmount > 0) {
|
if (newAmount > 0) {
|
||||||
price = price.divide(BigDecimal.valueOf(amount), MathContext.UNLIMITED).multiply(BigDecimal.valueOf(newAmount));
|
price = price.divide(BigDecimal.valueOf(amount), Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(newAmount));
|
||||||
amount = newAmount;
|
amount = newAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.Acrobot.ChestShop.Listeners.PreTransaction;
|
|||||||
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
import com.Acrobot.Breeze.Utils.InventoryUtil;
|
||||||
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||||
import com.Acrobot.ChestShop.Economy.Economy;
|
import com.Acrobot.ChestShop.Economy.Economy;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyAmountEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencyAmountEvent;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
|
||||||
@ -40,7 +41,7 @@ public class PartialTransactionModule implements Listener {
|
|||||||
|
|
||||||
Player client = event.getClient();
|
Player client = event.getClient();
|
||||||
|
|
||||||
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())));
|
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
||||||
|
|
||||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(client);
|
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(client);
|
||||||
ChestShop.callEvent(currencyAmountEvent);
|
ChestShop.callEvent(currencyAmountEvent);
|
||||||
@ -106,7 +107,7 @@ public class PartialTransactionModule implements Listener {
|
|||||||
Player client = event.getClient();
|
Player client = event.getClient();
|
||||||
UUID owner = event.getOwnerAccount().getUuid();
|
UUID owner = event.getOwnerAccount().getUuid();
|
||||||
|
|
||||||
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())));
|
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
||||||
|
|
||||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(owner, client.getWorld());
|
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(owner, client.getWorld());
|
||||||
ChestShop.callEvent(currencyAmountEvent);
|
ChestShop.callEvent(currencyAmountEvent);
|
||||||
@ -164,7 +165,7 @@ public class PartialTransactionModule implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int getAmountOfAffordableItems(BigDecimal walletMoney, BigDecimal pricePerItem) {
|
private static int getAmountOfAffordableItems(BigDecimal walletMoney, BigDecimal pricePerItem) {
|
||||||
return walletMoney.divide(pricePerItem, MathContext.UNLIMITED).setScale(0, RoundingMode.FLOOR).intValueExact();
|
return walletMoney.divide(pricePerItem, 0, RoundingMode.FLOOR).intValueExact();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemStack[] getItems(ItemStack[] stock, Inventory inventory) {
|
private static ItemStack[] getItems(ItemStack[] stock, Inventory inventory) {
|
||||||
|
Loading…
Reference in New Issue
Block a user