Fix SpongeEconHandler

This commit is contained in:
Matt 2016-02-19 12:18:15 -05:00
parent c719d548d0
commit 63cd7c8b97

View File

@ -1,51 +1,55 @@
package com.plotsquared.sponge.util; package com.plotsquared.sponge.util;
import java.util.UUID;
import org.apache.commons.lang.NotImplementedException;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.object.SpongePlayer; import com.plotsquared.sponge.object.SpongePlayer;
import org.apache.commons.lang.NotImplementedException;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.UniqueAccount;
import java.math.BigDecimal;
import java.util.Optional;
public class SpongeEconHandler extends EconHandler { public class SpongeEconHandler extends EconHandler {
private EconomyService economyService;
private Object TE_SERVICE;
private Object EL_SERVICE;
public SpongeEconHandler() { public SpongeEconHandler() {
try { if (Sponge.getServiceManager().isRegistered(EconomyService.class)) {
Class<?> clazz = Class.forName("com.erigitic.service.TEService"); economyService = Sponge.getServiceManager().provide(EconomyService.class).get();
this.TE_SERVICE = SpongeMain.THIS.getGame().getServiceManager().provide(clazz).get(); } else {
PS.log("No economy service was registered.");
} catch (Exception e) {
try {
Class<?> clazz = Class.forName("me.Flibio.EconomyLite.API.EconomyLiteAPI");
this.EL_SERVICE = SpongeMain.THIS.getGame().getServiceManager().provide(clazz).get();
} catch (Exception e2) {
PS.log("No economy service found! (EconomyLite, TotalEconomy)");
}
} }
} }
@Override @Override
public void withdrawMoney(PlotPlayer player, double amount) { public void withdrawMoney(PlotPlayer player, double amount) {
UUID uuid = ((SpongePlayer) player).player.getUniqueId(); Optional<UniqueAccount> account = economyService.getAccount(player.getUUID());
if (account.isPresent()) {
UniqueAccount acc = account.get();
acc.withdraw(economyService.getDefaultCurrency(),BigDecimal.valueOf(amount), Cause.of("PlotSquared"));
}
} }
@Override @Override
public void depositMoney(PlotPlayer player, double amount) { public void depositMoney(PlotPlayer player, double amount) {
UUID uuid = ((SpongePlayer) player).player.getUniqueId(); Optional<UniqueAccount> account = economyService.getAccount(player.getUUID());
if (account.isPresent()) {
UniqueAccount acc = account.get();
acc.deposit(economyService.getDefaultCurrency(),BigDecimal.valueOf(amount), Cause.of("PlotSquared"));
}
} }
@Override @Override
public void depositMoney(OfflinePlotPlayer player, double amount) { public void depositMoney(OfflinePlotPlayer player, double amount) {
UUID uuid = player.getUUID(); Optional<UniqueAccount> account = economyService.getAccount(player.getUUID());
if (account.isPresent()) {
UniqueAccount acc = account.get();
acc.withdraw(economyService.getDefaultCurrency(),BigDecimal.valueOf(amount), Cause.of("PlotSquared"));
}
} }
@Override @Override