Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Fix setHoldings for mixed type
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Dec 15, 2021
1 parent 3ac9cff commit 95559a6
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions TNE/src/net/tnemc/core/common/currency/type/MixedType.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,29 @@ public BigDecimal itemHoldings(UUID account, String world, TNECurrency currency,
*/
@Override
public void setHoldings(UUID account, String world, TNECurrency currency, BigDecimal amount, boolean skipUpdate) throws SQLException {
TNE.manager().setBalance(account, world, currency.getIdentifier(), amount, !skipUpdate);
final BigDecimal holdings = getHoldings(account, world, currency, false);

if(holdings.compareTo(BigDecimal.ZERO) != 0 && holdings.compareTo(amount) > 0) {
final BigDecimal virtualHoldings = virtualHoldings(account, world, currency);

BigDecimal toSet = amount;

if(virtualHoldings.compareTo(amount) < 0) {
final BigDecimal remaining = amount.subtract(virtualHoldings);

//TNE.saveManager().getTNEManager().getTNEProvider().saveBalance(account, world, currency.getIdentifier(), amount);
toSet = BigDecimal.ZERO;

setItemHoldings(account, world, currency, itemHoldings(account, world, currency, false).subtract(remaining));
}

setVirtualHoldings(account, world, currency, toSet, skipUpdate);

} else if(holdings.compareTo(BigDecimal.ZERO) == 0) {
setVirtualHoldings(account, world, currency, amount, skipUpdate);
setItemHoldings(account, world, currency, amount);
} else {
setVirtualHoldings(account, world, currency, amount, skipUpdate);
}
}

public void setVirtualHoldings(UUID account, String world, TNECurrency currency, BigDecimal amount, boolean skipUpdate) {
Expand Down

0 comments on commit 95559a6

Please sign in to comment.