Search in sources :

Example 1 with ContributorService

use of gg.projecteden.nexus.models.store.ContributorService in project Nexus by ProjectEdenGG.

the class HandlePurchaseCommand method run.

@Path("<data...>")
void run(String data) {
    Nexus.log("Purchase caught; processing... " + data);
    String[] args = data.split("\\|");
    Purchase purchase = Purchase.builder().id(UUID.randomUUID()).name(args[0]).uuid(UUID.fromString(uuidFormat(args[1]))).transactionId(args[2]).price(Double.parseDouble(args[3])).currency(args[4]).timestamp(LocalDateTime.parse(args[6] + " " + args[5], formatter)).email(args[7]).ip(args[8]).packageId(args[9]).packagePrice(Double.parseDouble(args[10])).packageExpiry(args[11]).packageName(args[12]).purchaserName(args[13]).purchaserUuid(UUID.fromString(uuidFormat(args[14]))).build();
    String discordMessage = purchase.toDiscordString();
    final ContributorService contributorService = new ContributorService();
    final Contributor contributor = contributorService.get(purchase.getPurchaserUuid());
    Package packageType = Package.getPackage(purchase.getPackageId());
    if (packageType == null)
        discordMessage += "\nPackage not recognized!";
    else {
        if (purchase.getPrice() > 0) {
            send(purchase.getUuid(), PREFIX + "Thank you for buying &e" + purchase.getPackageName() + "&3! " + "Your contribution is &3&ogreatly &3appreciated and will be put to good use.");
            if (contributor.isBroadcasts())
                if (packageType == Package.CUSTOM_DONATION) {
                    Koda.say("Thank you for your custom donation, " + purchase.getNickname() + "! " + "We greatly appreciate your selfless contribution &4❤");
                    // this is not necessarily what they donated
                    // if they make a custom donation and purchase items at the same
                    // time, i have no way to break down the price from the payload
                    // but that is very rare, so its better than nothing i guess
                    contributor.giveCredit(purchase.getPrice());
                } else
                    Koda.say("Thank you for your purchase, " + purchase.getNickname() + "! " + "Enjoy your " + purchase.getPackageName() + " perk!");
            if (packageType.getCategory() == StoreCategory.BOOSTS)
                send(purchase.getUuid(), PREFIX + "Make sure you activate your boost with &c/boost menu");
            if (isV4Uuid(purchase.getPurchaserUuid())) {
                new BadgeUserService().edit(purchase.getPurchaserUuid(), badgeUser -> badgeUser.give(Badge.SUPPORTER));
                DiscordUser user = new DiscordUserService().get(purchase.getPurchaserUuid());
                if (user.getUserId() != null)
                    Discord.addRole(user.getUserId(), Role.SUPPORTER);
                else
                    discordMessage += "\nUser does not have a linked discord account";
            }
        } else {
            send(purchase.getUuid(), PREFIX + "Your free " + purchase.getPackageName() + " has been successfully processed, enjoy!");
        }
        packageType.apply(purchase.getUuid());
        discordMessage += "\nPurchase successfully processed.";
    }
    Discord.send(discordMessage, TextChannel.ADMIN_LOG);
    contributor.add(purchase);
    contributorService.save(contributor);
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Purchase(gg.projecteden.nexus.models.store.Contributor.Purchase) ContributorService(gg.projecteden.nexus.models.store.ContributorService) Contributor(gg.projecteden.nexus.models.store.Contributor) BadgeUserService(gg.projecteden.nexus.models.badge.BadgeUserService) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 2 with ContributorService

use of gg.projecteden.nexus.models.store.ContributorService in project Nexus by ProjectEdenGG.

the class BankCommand method wallet.

@Path("[player]")
@Description("Displays all currencies owned by the player")
void wallet(@Arg("self") Nerd nerd) {
    send(PREFIX + "&e" + nerd.getNickname() + "&3's Wallet: ");
    // Store Credit
    Contributor contributor = new ContributorService().get(nerd);
    send("&3Store Credit: &e" + contributor.getCreditFormatted());
    // Vote Points
    Voter voter = new VoterService().get(nerd);
    send("&3Vote Points: &e" + voter.getPoints());
    // Event Store
    EventUser eventUser = new EventUserService().get(nerd);
    send("&3Event Tokens: &e" + eventUser.getTokens());
    // Minigames
    PerkOwner perkOwner = new PerkOwnerService().get(nerd);
    send("&3Minigame Tokens: &e" + perkOwner.getTokens());
    // Economy
    send("&3Economy Balances: &e");
    Banker banker = new BankerService().get(nerd);
    Map<ShopGroup, BigDecimal> balances = banker.getBalances();
    for (ShopGroup shopGroup : balances.keySet()) {
        String name = StringUtils.camelCase(shopGroup);
        String bal = banker.getBalanceFormatted(shopGroup);
        send("&3 - " + name + ": &e" + bal);
    }
    line();
}
Also used : PerkOwner(gg.projecteden.nexus.models.perkowner.PerkOwner) Banker(gg.projecteden.nexus.models.banker.Banker) Contributor(gg.projecteden.nexus.models.store.Contributor) VoterService(gg.projecteden.nexus.models.voter.VoterService) BigDecimal(java.math.BigDecimal) PerkOwnerService(gg.projecteden.nexus.models.perkowner.PerkOwnerService) ShopGroup(gg.projecteden.nexus.models.shop.Shop.ShopGroup) ContributorService(gg.projecteden.nexus.models.store.ContributorService) EventUser(gg.projecteden.nexus.models.eventuser.EventUser) Voter(gg.projecteden.nexus.models.voter.Voter) BankerService(gg.projecteden.nexus.models.banker.BankerService) EventUserService(gg.projecteden.nexus.models.eventuser.EventUserService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Description(gg.projecteden.nexus.framework.commands.models.annotations.Description)

Aggregations

Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)2 Contributor (gg.projecteden.nexus.models.store.Contributor)2 ContributorService (gg.projecteden.nexus.models.store.ContributorService)2 Description (gg.projecteden.nexus.framework.commands.models.annotations.Description)1 BadgeUserService (gg.projecteden.nexus.models.badge.BadgeUserService)1 Banker (gg.projecteden.nexus.models.banker.Banker)1 BankerService (gg.projecteden.nexus.models.banker.BankerService)1 DiscordUser (gg.projecteden.nexus.models.discord.DiscordUser)1 DiscordUserService (gg.projecteden.nexus.models.discord.DiscordUserService)1 EventUser (gg.projecteden.nexus.models.eventuser.EventUser)1 EventUserService (gg.projecteden.nexus.models.eventuser.EventUserService)1 PerkOwner (gg.projecteden.nexus.models.perkowner.PerkOwner)1 PerkOwnerService (gg.projecteden.nexus.models.perkowner.PerkOwnerService)1 ShopGroup (gg.projecteden.nexus.models.shop.Shop.ShopGroup)1 Purchase (gg.projecteden.nexus.models.store.Contributor.Purchase)1 Voter (gg.projecteden.nexus.models.voter.Voter)1 VoterService (gg.projecteden.nexus.models.voter.VoterService)1 BigDecimal (java.math.BigDecimal)1