Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
added multicurrency support, fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
malte-laukoetter committed Mar 11, 2017
1 parent 65513e8 commit e15a6b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Extra Settings for the different Boni Types:
|----|-----------|-------------|
|amountMin|the minimum amount of money rewarded|0.0|
|amountMax|the maximum amount of money rewarded|0.0|
|currency|the id of the currency to use, defaults to the default currency| |

#### Ability

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.NamedCause;
import org.spongepowered.api.service.economy.Currency;
import org.spongepowered.api.service.economy.EconomyService;

import java.math.BigDecimal;
Expand All @@ -20,9 +21,11 @@ public class EconomyReward extends JobBonus{
private final EconomyService service =
Sponge.getServiceManager().getRegistration(EconomyService.class).get().getProvider();
@Setting(value = "amountMax", comment = "maximal amount of money")
private final BigDecimal amountMax = BigDecimal.valueOf(0.0);
private BigDecimal amountMax = BigDecimal.valueOf(0.0);
@Setting(value = "amountMin", comment = "minimal amount of money")
private final BigDecimal amountMin = BigDecimal.valueOf(0.0);
private BigDecimal amountMin = BigDecimal.valueOf(0.0);
@Setting(value = "currency", comment = "the id of the currency to use, defaults to the default currency")
private String currency = null;
private final Cause cause = Cause.of(NamedCause.source(Sponge.getPluginManager().fromInstance(Laborus.instance())));

public EconomyReward() {
Expand All @@ -31,8 +34,17 @@ public EconomyReward() {

@Override
public void useBonus(JobItem item, Player player, Object i2) {
Currency cur;

if(currency == null){
cur = service.getDefaultCurrency();
}else{
cur = service.getCurrencies().stream()
.filter(c -> c.getId().equals(currency)).findFirst().orElseGet(service::getDefaultCurrency);
}

service.getOrCreateAccount(player.getIdentifier()).get().deposit(
service.getDefaultCurrency(),
cur,
amountMax.divide(amountMin, BigDecimal.ROUND_FLOOR).multiply(BigDecimal.valueOf(Math.random())).add(amountMin),
cause
);
Expand Down

0 comments on commit e15a6b6

Please sign in to comment.