Skip to content

Why is there no API to get player balance?

Jonathan Chan Kwan Yin edited this page May 22, 2022 · 2 revisions

Trying to get the player balance is most often an incorrect design choice. Why are you trying to do this?

I want to check if player has enough money to buy something

Do not try to fetch the player balance for this. Just call takeMoney directly and handle the error.

The player balance may be modified by another command/event between fetching money and the actual takeMoney call. As a result, players can exploit this to purchase the same item multiple times even without enough money.

I want to display the player money

Use InfoAPI. Users can define custom infos to display player balance in different ways, such as total/average money in a certain currency, total amount transacted in the past day, etc. Just accept a string in your config and render it with InfoAPI.

I need to implement the getBalance method in my EconomyProvider interface

Then delete that method from the interface. The existence of such a method simply didn't make sense.

But removing getBalance breaks BC!

Then tell your users to update. They most likely used getBalance incorrectly anyway.