mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-05 22:57:49 +01:00
Improve internal precision of calculations (Fixes #221)
This commit is contained in:
parent
8cf9934a32
commit
6773f89221
@ -193,10 +193,10 @@ public class PlayerInteract implements Listener {
|
||||
amount = 1;
|
||||
}
|
||||
|
||||
if (Properties.SHIFT_SELLS_IN_STACKS && player.isSneaking() && price != PriceUtil.NO_PRICE && isAllowedForShift(action == buy)) {
|
||||
if (Properties.SHIFT_SELLS_IN_STACKS && player.isSneaking() && !price.equals(PriceUtil.NO_PRICE) && isAllowedForShift(action == buy)) {
|
||||
int newAmount = adminShop ? InventoryUtil.getMaxStackSize(item) : getStackAmount(item, ownerInventory, player, action);
|
||||
if (newAmount > 0) {
|
||||
price = price.divide(BigDecimal.valueOf(amount), Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(newAmount));
|
||||
price = price.divide(BigDecimal.valueOf(amount), MathContext.DECIMAL128).multiply(BigDecimal.valueOf(newAmount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
||||
amount = newAmount;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class PartialTransactionModule implements Listener {
|
||||
|
||||
Player client = event.getClient();
|
||||
|
||||
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
||||
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), MathContext.DECIMAL128);
|
||||
|
||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(client);
|
||||
ChestShop.callEvent(currencyAmountEvent);
|
||||
@ -59,7 +59,7 @@ public class PartialTransactionModule implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setExactPrice(pricePerItem.multiply(new BigDecimal(amountAffordable)));
|
||||
event.setExactPrice(pricePerItem.multiply(new BigDecimal(amountAffordable)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP));
|
||||
event.setStock(getCountedItemStack(event.getStock(), amountAffordable));
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public class PartialTransactionModule implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)));
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP));
|
||||
event.setStock(itemsHad);
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public class PartialTransactionModule implements Listener {
|
||||
}
|
||||
|
||||
event.setStock(itemsFit);
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)));
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
|
||||
UUID seller = event.getOwnerAccount().getUuid();
|
||||
@ -107,7 +107,7 @@ public class PartialTransactionModule implements Listener {
|
||||
Player client = event.getClient();
|
||||
UUID owner = event.getOwnerAccount().getUuid();
|
||||
|
||||
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP);
|
||||
BigDecimal pricePerItem = event.getExactPrice().divide(BigDecimal.valueOf(InventoryUtil.countItems(event.getStock())), MathContext.DECIMAL128);
|
||||
|
||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(owner, client.getWorld());
|
||||
ChestShop.callEvent(currencyAmountEvent);
|
||||
@ -126,7 +126,7 @@ public class PartialTransactionModule implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(amountAffordable)));
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(amountAffordable)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP));
|
||||
event.setStock(getCountedItemStack(event.getStock(), amountAffordable));
|
||||
}
|
||||
}
|
||||
@ -140,7 +140,7 @@ public class PartialTransactionModule implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)));
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP));
|
||||
event.setStock(itemsHad);
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ public class PartialTransactionModule implements Listener {
|
||||
}
|
||||
|
||||
event.setStock(itemsFit);
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)));
|
||||
event.setExactPrice(pricePerItem.multiply(BigDecimal.valueOf(possessedItemCount)).setScale(Properties.PRICE_PRECISION, BigDecimal.ROUND_HALF_UP));
|
||||
}
|
||||
|
||||
CurrencyHoldEvent currencyHoldEvent = new CurrencyHoldEvent(event.getExactPrice(), client);
|
||||
|
Loading…
Reference in New Issue
Block a user