use of org.spongepowered.api.service.economy.EconomyService in project Nucleus by NucleusPowered.
the class EconHelper method withdrawFromPlayer.
public boolean withdrawFromPlayer(Player src, double cost, boolean message) {
Optional<EconomyService> oes = Sponge.getServiceManager().provide(EconomyService.class);
if (oes.isPresent()) {
// Check balance.
EconomyService es = oes.get();
Optional<UniqueAccount> a = es.getOrCreateAccount(src.getUniqueId());
if (!a.isPresent()) {
src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("cost.noaccount"));
return false;
}
TransactionResult tr = a.get().withdraw(es.getDefaultCurrency(), BigDecimal.valueOf(cost), CauseStackHelper.createCause(src));
if (tr.getResult() == ResultType.ACCOUNT_NO_FUNDS) {
if (message) {
src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("cost.nofunds", getCurrencySymbol(cost)));
}
return false;
} else if (tr.getResult() != ResultType.SUCCESS) {
src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("cost.error"));
return false;
}
if (message) {
src.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("cost.complete", getCurrencySymbol(cost)));
}
}
return true;
}
use of org.spongepowered.api.service.economy.EconomyService in project Nucleus by NucleusPowered.
the class EconHelper method hasBalance.
public boolean hasBalance(Player src, double balance) {
Optional<EconomyService> oes = Sponge.getServiceManager().provide(EconomyService.class);
if (oes.isPresent()) {
// Check balance.
EconomyService es = oes.get();
Optional<UniqueAccount> ua = es.getOrCreateAccount(src.getUniqueId());
return ua.isPresent() && ua.get().getBalance(es.getDefaultCurrency()).doubleValue() >= balance;
}
// No economy
return true;
}
use of org.spongepowered.api.service.economy.EconomyService in project Nucleus by NucleusPowered.
the class EconHelper method depositInPlayer.
public boolean depositInPlayer(User src, double cost, boolean message) {
Optional<EconomyService> oes = Sponge.getServiceManager().provide(EconomyService.class);
if (oes.isPresent()) {
// Check balance.
EconomyService es = oes.get();
Optional<UniqueAccount> a = es.getOrCreateAccount(src.getUniqueId());
if (!a.isPresent()) {
src.getPlayer().ifPresent(x -> x.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("cost.noaccount")));
return false;
}
TransactionResult tr = a.get().deposit(es.getDefaultCurrency(), BigDecimal.valueOf(cost), CauseStackHelper.createCause(src));
if (tr.getResult() != ResultType.SUCCESS && src.isOnline()) {
src.getPlayer().ifPresent(x -> x.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("cost.error")));
return false;
}
if (message && src.isOnline()) {
src.getPlayer().ifPresent(x -> x.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("cost.refund", getCurrencySymbol(cost))));
}
}
return true;
}
use of org.spongepowered.api.service.economy.EconomyService in project Almura by AlmuraDev.
the class MembershipHandler method requestClientGui.
public void requestClientGui(Player player) {
final EconomyService service = Sponge.getServiceManager().provide(EconomyService.class).orElse(null);
final LuckPerms permService = Sponge.getServiceManager().provide(LuckPerms.class).orElse(null);
int currentMembershipLevel = -1;
if (player.hasPermission("almura.membership.gui.open")) {
if (service != null && skillsManager != null && permService != null) {
final Account account = service.getOrCreateAccount(player.getUniqueId()).orElse(null);
BigDecimal balance;
if (account != null) {
final Currency currency = service.getDefaultCurrency();
balance = account.getBalance(currency);
String currentGroup = permService.getUserManager().getUser(player.getUniqueId()).getPrimaryGroup();
if (currentGroup.equalsIgnoreCase("default")) {
currentMembershipLevel = -1;
// should be impossible to reach this unless permissions system is screwed up.
} else if (currentGroup.equalsIgnoreCase("survivor")) {
currentMembershipLevel = 0;
} else if (currentGroup.equalsIgnoreCase("citizen")) {
currentMembershipLevel = 1;
} else if (currentGroup.equalsIgnoreCase("explorer")) {
currentMembershipLevel = 2;
} else if (currentGroup.equalsIgnoreCase("pioneer")) {
currentMembershipLevel = 3;
}
this.network.sendTo(player, new ClientboundMembershipGuiOpenPacket(player.hasPermission("almura.membership.admin"), skillsManager.getTotalSkillLevel(player), balance.doubleValue(), currentMembershipLevel));
}
} else {
serverNotificationManager.sendWindowMessage(player, Text.of("Init Error"), Text.of("Economy Service offline!"));
}
} else {
serverNotificationManager.sendPopupNotification(player, Text.of("Insufficient Permissions"), Text.of("Missing [almura.membership.gui.open]"), 5);
}
}
use of org.spongepowered.api.service.economy.EconomyService in project Almura by AlmuraDev.
the class CoinExchange method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer mcPlayer, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
final Player player = (Player) mcPlayer;
if (mcPlayer.getHeldItemMainhand().isEmpty()) {
serverNotificationManager.sendPopupNotification(player, Text.of("Coin Exchange"), Text.of("Place coins in hand prior to clicking on Coin Exchange"), 5);
return true;
}
final EconomyService service = Sponge.getServiceManager().provide(EconomyService.class).orElse(null);
if (service != null) {
final Account account = service.getOrCreateAccount(player.getUniqueId()).orElse(null);
if (account != null) {
final Currency currency = service.getDefaultCurrency();
final double coinValue = getCoinValue(player.getItemInHand(HandTypes.MAIN_HAND).get());
if (coinValue == 0) {
serverNotificationManager.sendPopupNotification(player, Text.of("Coin Exchange"), Text.of("This item is not a coin..."), 5);
// Not Coins
return true;
}
final BigDecimal depositAmount = new BigDecimal((coinValue * player.getItemInHand(HandTypes.MAIN_HAND).get().getQuantity()));
account.deposit(currency, depositAmount, Sponge.getCauseStackManager().getCurrentCause());
// Clear ItemStack from Players hand.
((Player) mcPlayer).setItemInHand(HandTypes.MAIN_HAND, null);
}
}
return true;
}
Aggregations