use of org.spongepowered.api.service.economy.Currency 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;
}
use of org.spongepowered.api.service.economy.Currency 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.Currency in project TotalEconomy by Erigitic.
the class TEJobManager method notifyPlayer.
/**
* Notifies a player when they are rewarded for completing a job action
*
* @param amount
*/
private void notifyPlayer(Player player, BigDecimal amount) {
Currency defaultCurrency = totalEconomy.getDefaultCurrency();
player.sendMessage(Text.of(TextColors.GOLD, defaultCurrency.format(amount, defaultCurrency.getDefaultFractionDigits()), TextColors.GRAY, " has been added to your balance."));
}
use of org.spongepowered.api.service.economy.Currency in project Almura by AlmuraDev.
the class DeathHandler method onPlayerDeath.
@Listener(order = Order.LAST)
public void onPlayerDeath(final DestructEntityEvent.Death event, @Root final DamageSource damageSource, @Getter("getTargetEntity") final Player player) {
this.cacheItemTypes();
final EconomyService service = Sponge.getServiceManager().provide(EconomyService.class).orElse(null);
if (service != null) {
final Server server = Sponge.getServer();
final double deathTax = RANGE.random(RANDOM);
final Account account = service.getOrCreateAccount(player.getUniqueId()).orElse(null);
BigDecimal balance;
if (account != null && this.areCoinsLoaded()) {
final Currency currency = service.getDefaultCurrency();
double deathTaxAmount = 0;
double droppedAmount = 0;
boolean displayDrops = false;
final DecimalFormat dFormat = new DecimalFormat("###,###,###,###.##");
balance = account.getBalance(currency);
if (balance.doubleValue() > 0 && !player.hasPermission(Almura.ID + ".death.exempt")) {
double dropAmount = balance.doubleValue() - (balance.doubleValue() * (deathTax / 100));
if (dropAmount > balance.doubleValue()) {
dropAmount = balance.doubleValue();
}
BigDecimal deduct = new BigDecimal(dropAmount);
account.withdraw(currency, deduct, Sponge.getCauseStackManager().getCurrentCause());
deathTaxAmount = this.dropAmountReturnChange(player, dropAmount);
droppedAmount = (dropAmount - deathTaxAmount);
displayDrops = true;
}
final double finalDroppedAmount = droppedAmount;
final double finalDeathTaxAmount = deathTaxAmount;
final boolean finalDisplayDrops = displayDrops;
if (event.getMessage().toPlain().isEmpty()) {
// Note: noticed that sometimes, for what ever reason the message is empty... Mojang bug?
UchatUtil.relayMessageToDiscord(":skull:", Text.of(player.getName() + " has died, dropped: $" + dFormat.format(finalDroppedAmount) + " and lost: $" + dFormat.format(finalDeathTaxAmount) + " to death taxes.").toPlain(), true);
} else {
UchatUtil.relayMessageToDiscord(":skull:", Text.of(event.getMessage().toPlain() + ", dropped: $" + dFormat.format(finalDroppedAmount) + " and lost: $" + dFormat.format(finalDeathTaxAmount) + " to death taxes.").toPlain(), true);
}
server.getOnlinePlayers().forEach(onlinePlayer -> {
if (onlinePlayer.getUniqueId().equals(player.getUniqueId())) {
this.network.sendTo(player, new ClientboundPlayerDiedPacket(finalDroppedAmount, finalDeathTaxAmount, finalDisplayDrops, player.hasPermission(Almura.ID + ".death.revive")));
} else {
serverNotificationManager.sendPopupNotification(onlinePlayer, Text.of(player.getName() + " has died!"), Text.of("Dropped: " + TextFormatting.GOLD + "$" + dFormat.format(finalDroppedAmount) + TextFormatting.RESET + " and " + "lost: " + TextFormatting.RED + "$" + dFormat.format(finalDeathTaxAmount) + TextFormatting.RESET + " to death taxes."), 5);
}
});
return;
}
}
// Service or Account was null, fallback.
this.network.sendTo(player, new ClientboundPlayerDiedPacket(0.00, 0.00, false, player.hasPermission(Almura.ID + "death.revive")));
}
use of org.spongepowered.api.service.economy.Currency in project Almura by AlmuraDev.
the class MembershipHandler method handleMembershipPurchase.
public void handleMembershipPurchase(Player player, int newMembershipLevel) {
// Typically only thing that fails here is if someone is running a hacked client. This method double checks that.
if (!player.hasPermission("almura.membership.purchase")) {
serverNotificationManager.sendWindowMessage(player, Text.of("Permission Denied"), Text.of("Missing: almura.membership.purchase"));
return;
}
final EconomyService econService = Sponge.getServiceManager().provide(EconomyService.class).orElse(null);
final LuckPerms permService = Sponge.getServiceManager().provide(LuckPerms.class).orElse(null);
if (econService != null && permService != null) {
final Account account = econService.getOrCreateAccount(player.getUniqueId()).orElse(null);
if (account != null) {
BigDecimal balance;
final Currency currency = econService.getDefaultCurrency();
balance = account.getBalance(currency);
double fee = 0;
if (newMembershipLevel == 1) {
fee = 2500000;
if (!(balance.doubleValue() >= fee)) {
serverNotificationManager.sendWindowMessage(player, Text.of("Insufficient Funds"), Text.of("Insufficient Funds to purchase Citizen Membership."));
return;
}
}
if (newMembershipLevel == 2) {
fee = 5000000;
if (!(balance.doubleValue() >= fee)) {
serverNotificationManager.sendWindowMessage(player, Text.of("Insufficient Funds"), Text.of("Insufficient Funds to purchase Explorer Membership."));
return;
}
}
if (newMembershipLevel == 3) {
fee = 10000000;
if (!(balance.doubleValue() >= fee)) {
serverNotificationManager.sendWindowMessage(player, Text.of("Insufficient Funds"), Text.of("Insufficient Funds to purchase Pioneer Membership."));
return;
}
}
String currentGroup = permService.getUserManager().getUser(player.getUniqueId()).getPrimaryGroup();
String newMembership = "";
if (newMembershipLevel == 1)
newMembership = "Citizen";
if (newMembershipLevel == 2)
newMembership = "Explorer";
if (newMembershipLevel == 3)
newMembership = "Pioneer";
BigDecimal deduct = new BigDecimal(fee);
final String command = "lp user " + player.getName() + " promote members";
if (newMembershipLevel == 1 && currentGroup.equalsIgnoreCase("survivor")) {
this.commandManager.process(Sponge.getServer().getConsole(), command);
account.withdraw(currency, deduct, Sponge.getCauseStackManager().getCurrentCause());
this.network.sendTo(player, new ClientboundMembershipSuccessPacket(newMembership));
return;
}
if (newMembershipLevel == 2 && (currentGroup.equalsIgnoreCase("survivor") || currentGroup.equalsIgnoreCase("citizen"))) {
if (currentGroup.equalsIgnoreCase("survivor")) {
this.commandManager.process(Sponge.getServer().getConsole(), command);
}
this.commandManager.process(Sponge.getServer().getConsole(), command);
account.withdraw(currency, deduct, Sponge.getCauseStackManager().getCurrentCause());
this.network.sendTo(player, new ClientboundMembershipSuccessPacket(newMembership));
return;
}
if (newMembershipLevel == 3 && (currentGroup.equalsIgnoreCase("survivor") || currentGroup.equalsIgnoreCase("citizen") || currentGroup.equalsIgnoreCase("explorer"))) {
if (currentGroup.equalsIgnoreCase("survivor")) {
this.commandManager.process(Sponge.getServer().getConsole(), command);
this.commandManager.process(Sponge.getServer().getConsole(), command);
}
if (currentGroup.equalsIgnoreCase("citizen")) {
this.commandManager.process(Sponge.getServer().getConsole(), command);
}
this.commandManager.process(Sponge.getServer().getConsole(), command);
account.withdraw(currency, deduct, Sponge.getCauseStackManager().getCurrentCause());
this.network.sendTo(player, new ClientboundMembershipSuccessPacket(newMembership));
return;
}
// This should be impossible, leaving this debug line.
System.out.println("Current Group: " + currentGroup + " Failed to upgrade, no path found");
}
} else {
serverNotificationManager.sendWindowMessage(player, Text.of("Error"), Text.of("Economy or Permission Service offline!"));
}
}
Aggregations