mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Fix SpongeEconHandler
This commit is contained in:
parent
c719d548d0
commit
63cd7c8b97
@ -1,51 +1,55 @@
|
||||
package com.plotsquared.sponge.util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.SpongeMain;
|
||||
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 {
|
||||
|
||||
private Object TE_SERVICE;
|
||||
private Object EL_SERVICE;
|
||||
|
||||
private EconomyService economyService;
|
||||
public SpongeEconHandler() {
|
||||
try {
|
||||
Class<?> clazz = Class.forName("com.erigitic.service.TEService");
|
||||
this.TE_SERVICE = SpongeMain.THIS.getGame().getServiceManager().provide(clazz).get();
|
||||
|
||||
} 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)");
|
||||
}
|
||||
if (Sponge.getServiceManager().isRegistered(EconomyService.class)) {
|
||||
economyService = Sponge.getServiceManager().provide(EconomyService.class).get();
|
||||
} else {
|
||||
PS.log("No economy service was registered.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
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
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user