AppleDash / SaneEconomy

Finally, a sane economy plugin for Bukkit.
https://www.spigotmc.org/resources/saneeconomy-simple-but-featureful-economy.26223/
GNU General Public License v3.0
19 stars 24 forks source link

Transactions amounts are rounded but event goes out with original amount. #80

Closed queuedpixel closed 4 years ago

queuedpixel commented 6 years ago

Summary

I'm working on a plugin that gives money to players. I've discovered that if I send a currency amount with a level of precision that is smaller than what is configured the amount is rounded to the configured precision level but the SaneEconomyTransactionEvent gets sent out with the original amount.

Example

I have my currency format set to 0.000 I send currency to a player in the amount of 0.0025. An event goes out with 0.0025 as the amount. However, the player's balance is increased by 0.003.

Proposed Fix

In transact() method in class org.appledash.saneeconomy.economy.EconomyManager you send the event on line 170 and then call subtractBalance() or addBalance(). Both subtractBalance() and addBalance() round the amount in the first line of their function:

https://github.com/AppleDash/SaneEconomy/blob/6be741b047901a08934192806577a9d371fbe4fd/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/economy/EconomyManager.java#L95

https://github.com/AppleDash/SaneEconomy/blob/6be741b047901a08934192806577a9d371fbe4fd/SaneEconomyCore/src/main/java/org/appledash/saneeconomy/utils/NumberUtils.java#L46-L52

The currency amount should be rounded before you send the event.

AppleDash commented 6 years ago

Oops! Feel free to submit a PR, otherwise I'll get around to it eventually... My dev machine is currently out of commission.

AppleDash commented 4 years ago

Looks like this is working as expected in latest.