org.spongepowered.api.service.economy.account.Account Java Examples

The following examples show how to use org.spongepowered.api.service.economy.account.Account. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GDClaim.java    From GriefDefender with MIT License 6 votes vote down vote up
public Account getEconomyAccount() {
    if (this.isAdminClaim() || this.isSubdivision() || !GriefDefenderPlugin.getGlobalConfig().getConfig().economy.bankSystem) {
        return null;
    }

    if (this.economyAccount != null) {
        return this.economyAccount;
    }
    EconomyService economyService = GriefDefenderPlugin.getInstance().economyService.orElse(null);
    if (economyService != null) {
        this.economyAccount = economyService.getOrCreateAccount(this.id.toString()).orElse(null);
        return this.economyAccount;
    }

    return null;
}
 
Example #2
Source File: VirtualServiceCommon.java    From EconomyLite with MIT License 6 votes vote down vote up
public List<VirtualAccount> getTopAccounts(int start, int end, Cause cause) {
    debug("virtcommon: Getting top accounts - " + cause.toString());
    String mid = start + "-" + end + ":" + EconomyLite.getEconomyService().getDefaultCurrency().getId();
    List<VirtualAccount> accounts = topCache.getIfPresent(mid);
    if (accounts != null) {
        return accounts;
    }
    int offset = start - 1;
    int limit = end - offset;
    accounts = new ArrayList<>();
    List<String> ids =
            manager.queryTypeList("id", String.class, "SELECT id FROM economylitevirts WHERE currency = ? ORDER BY balance DESC LIMIT ?, ?",
                    EconomyLite.getEconomyService().getDefaultCurrency().getId(), offset, limit);
    EconomyService ecoService = EconomyLite.getEconomyService();
    for (String id : ids) {
        Optional<Account> vOpt = ecoService.getOrCreateAccount(id);
        if (vOpt.isPresent() && (vOpt.get() instanceof VirtualAccount)) {
            accounts.add((VirtualAccount) vOpt.get());
        }
    }
    topCache.update(mid, accounts);
    return accounts;
}
 
Example #3
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = to.getBalance(currency).add(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, to, cause);
    }
    // Check if the account has enough funds
    if (amount.compareTo(getBalance(currency)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, to, cause);
    }
    if (withdraw(currency, amount, cause).getResult().equals(ResultType.SUCCESS)
            && to.deposit(currency, amount, cause).getResult().equals(ResultType.SUCCESS)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, to, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, to, cause);
    }
}
 
Example #4
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
    BigDecimal newBal = to.getBalance(currency).add(amount);
    // Check if the new balance is in bounds
    if (newBal.compareTo(BigDecimal.ZERO) == -1 || newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, to, cause);
    }
    // Check if the account has enough funds
    if (amount.compareTo(getBalance(currency)) == 1) {
        return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, to, cause);
    }
    if (withdraw(currency, amount, cause).getResult().equals(ResultType.SUCCESS)
            && to.deposit(currency, amount, cause).getResult().equals(ResultType.SUCCESS)) {
        return resultAndEvent(this, amount, currency, ResultType.SUCCESS, to, cause);
    } else {
        return resultAndEvent(this, amount, currency, ResultType.FAILED, to, cause);
    }
}
 
Example #5
Source File: LiteEconomyService.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public Optional<Account> getOrCreateAccount(String id) {
    if (virtualService.accountExists(id, getDefaultCurrency(), CauseFactory.create("New account check"))) {
        // Return the account
        return Optional.of(new LiteVirtualAccount(id));
    } else {
        // Make a new account
        VirtualAccount account = new LiteVirtualAccount(id);
        if (virtualService.setBalance(id, account.getDefaultBalance(getDefaultCurrency()), getDefaultCurrency(),
                CauseFactory.create("Creating account"))) {
            return Optional.of(account);
        } else {
            return Optional.empty();
        }
    }
}
 
Example #6
Source File: VirtualAddCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("account").get();
        BigDecimal toAdd = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        if (aOpt.isPresent()) {
            Account targetAccount = aOpt.get();
            if (targetAccount.deposit(EconomyLite.getCurrencyService().getCurrentCurrency(), toAdd,
                    Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.addsuccess", "name", target));
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.addfail", "name", target));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #7
Source File: VirtualRemoveCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("account").get();
        BigDecimal toRemove = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        if (aOpt.isPresent()) {
            Account targetAccount = aOpt.get();
            if (targetAccount.withdraw(EconomyLite.getCurrencyService().getCurrentCurrency(), toRemove,
                    Cause.of(EventContext.empty(),(EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.removesuccess", "name", target));
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.removefail", "name", target));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #8
Source File: VirtualSetCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("account").get();
        BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        if (aOpt.isPresent()) {
            Account targetAccount = aOpt.get();
            if (targetAccount.setBalance(EconomyLite.getCurrencyService().getCurrentCurrency(), newBal,
                    Cause.of(EventContext.empty(), (EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetAccount.getDisplayName().toPlain()));
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetAccount.getDisplayName().toPlain()));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #9
Source File: VirtualBalanceCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    Currency currency = currencyService.getCurrentCurrency();
    if (args.getOne("account").isPresent()) {
        if (src.hasPermission("economylite.admin.virtualbalance")) {
            String target = args.<String>getOne("account").get();
            Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
            if (aOpt.isPresent()) {
                BigDecimal bal = aOpt.get().getBalance(currency);
                Text label = currency.getPluralDisplayName();
                if (bal.equals(BigDecimal.ONE)) {
                    label = currency.getDisplayName();
                }
                src.sendMessage(messageStorage.getMessage("command.balanceother", "player", aOpt.get().getDisplayName().toPlain(), "balance",
                        String.format(Locale.ENGLISH, "%,.2f", bal), "label", label.toPlain()));
            } else {
                src.sendMessage(messageStorage.getMessage("command.error"));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.noperm"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #10
Source File: PayVirtualCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(Player src, CommandContext args) {
    if (args.getOne("target").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("target").get();
        BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(src.getUniqueId());
        // Check for negative payments
        if (amount.doubleValue() <= 0) {
            src.sendMessage(messageStorage.getMessage("command.pay.invalid"));
        } else {
            if (aOpt.isPresent() && uOpt.isPresent()) {
                Account receiver = aOpt.get();
                UniqueAccount payer = uOpt.get();
                if (payer.transfer(receiver, ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), (EconomyLite.getInstance())))
                        .getResult().equals(ResultType.SUCCESS)) {
                    src.sendMessage(messageStorage.getMessage("command.pay.success", "target", receiver.getDisplayName().toPlain()));
                } else {
                    src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", receiver.getDisplayName().toPlain()));
                }
            }
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #11
Source File: TaxApplyTask.java    From GriefPrevention with MIT License 6 votes vote down vote up
private void handleTownTax(GPClaim town, GPPlayerData playerData) {
    Account townAccount = town.getEconomyAccount().orElse(null);
    if (townAccount == null) {
        // Virtual Accounts not supported by Economy Plugin so ignore
        return;
    }
    List<Claim> children = town.getChildren(true);
    for (Claim child : children) {
        // resident tax
        if (child.isBasicClaim()) {
            handleClaimTax((GPClaim) child, playerData, true);
        }
    }
    if (town.getOwnerUniqueId().equals(playerData.playerID)) {
        handleClaimTax(town, playerData, false);
    }
}
 
Example #12
Source File: GPClaim.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Override
public Optional<Account> getEconomyAccount() {
    if (this.isAdminClaim() || this.isSubdivision() || !GriefPreventionPlugin.getGlobalConfig().getConfig().claim.bankTaxSystem) {
        return Optional.empty();
    }

    if (this.economyAccount != null) {
        return Optional.of(this.economyAccount);
    }
    EconomyService economyService = GriefPreventionPlugin.instance.economyService.orElse(null);
    if (economyService != null) {
        this.economyAccount = economyService.getOrCreateAccount(this.claimStorage.filePath.getFileName().toString()).orElse(null);
        return Optional.ofNullable(this.economyAccount);
    }
    return Optional.empty();
}
 
Example #13
Source File: EconomyServlet.java    From Web-API with MIT License 6 votes vote down vote up
@GET
@Path("/account/{id}")
@Permission({ "account", "one" })
@ApiOperation(
        value = "List currencies",
        notes = "Lists all the currencies that the current economy supports.")
public Account getAccount(@PathParam("id") String id) {
    EconomyService srv = getEconomyService();
    if (!srv.hasAccount(id))
        throw new NotFoundException("Could not find account with id " + id);

    Optional<Account> optAcc = srv.getOrCreateAccount(id);
    if (!optAcc.isPresent())
        throw new InternalServerErrorException("Could not get account " + id);

    return optAcc.get();
}
 
Example #14
Source File: TaxApplyTask.java    From GriefDefender with MIT License 6 votes vote down vote up
private void handleTownTax(GDClaim town, GDPlayerData playerData) {
    Account townAccount = town.getEconomyAccount();
    if (townAccount == null) {
        // Virtual Accounts not supported by Economy Plugin so ignore
        return;
    }
    Set<Claim> children = town.getChildren(true);
    for (Claim child : children) {
        // resident tax
        if (child.isBasicClaim()) {
            handleClaimTax((GDClaim) child, playerData, true);
        }
    }
    if (town.getOwnerUniqueId().equals(playerData.playerID)) {
        handleClaimTax(town, playerData, false);
    }
}
 
Example #15
Source File: LiteTransactionResult.java    From EconomyLite with MIT License 5 votes vote down vote up
public LiteTransactionResult(Account account, BigDecimal amount, Currency currency, ResultType result, TransactionType transactionType) {
	this.account = account;
	this.amount = amount;
	this.contexts = new HashSet<Context>();
	this.currency = currency;
	this.result = result;
	this.transactionType = transactionType;
}
 
Example #16
Source File: GDPlayerData.java    From GriefDefender with MIT License 5 votes vote down vote up
public int getInternalEconomyAvailablePurchaseCost() {
    if (GriefDefenderPlugin.getInstance().isEconomyModeEnabled()) {
        final Account playerAccount = GriefDefenderPlugin.getInstance().economyService.get().getOrCreateAccount(this.playerID).orElse(null);
        if (playerAccount == null) {
            return 0;
        }

        final Currency defaultCurrency = GriefDefenderPlugin.getInstance().economyService.get().getDefaultCurrency();
        final BigDecimal currentFunds = playerAccount.getBalance(defaultCurrency);
        final Double economyBlockCost = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), this.getSubject(), Options.ECONOMY_BLOCK_COST);
        return (int) Math.round((currentFunds.doubleValue() / economyBlockCost));
    }
    return 0;
}
 
Example #17
Source File: VirtualPayCommand.java    From EconomyLite with MIT License 5 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("target").isPresent() && args.getOne("amount").isPresent()) {
        String account = args.<String>getOne("account").get();
        User target = args.<User>getOne("target").get();
        BigDecimal amount = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(account);
        Optional<UniqueAccount> uOpt = EconomyLite.getEconomyService().getOrCreateAccount(target.getUniqueId());
        // Check for negative payments
        if (amount.compareTo(BigDecimal.ONE) == -1) {
            src.sendMessage(messageStorage.getMessage("command.pay.invalid"));
        } else {
            if (aOpt.isPresent() && uOpt.isPresent()) {
                Account payer = aOpt.get();
                UniqueAccount receiver = uOpt.get();
                if (payer.transfer(receiver, ecoService.getDefaultCurrency(), amount, Cause.of(EventContext.empty(), EconomyLite.getInstance
                        ()))
                        .getResult().equals(ResultType.SUCCESS)) {
                    src.sendMessage(messageStorage.getMessage("command.pay.success", "target", target.getName()));
                    if (target instanceof Player) {
                        Text label = ecoService.getDefaultCurrency().getPluralDisplayName();
                        if (amount.equals(BigDecimal.ONE)) {
                            label = ecoService.getDefaultCurrency().getDisplayName();
                        }
                        ((Player) target).sendMessage(messageStorage.getMessage("command.pay.target", "amountandlabel",
                                String.format(Locale.ENGLISH, "%,.2f", amount) + " " + label.toPlain(), "sender",
                                payer.getDisplayName().toPlain()));
                    }
                } else {
                    src.sendMessage(messageStorage.getMessage("command.pay.failed", "target", target.getName()));
                }
            }
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #18
Source File: NationDepositExecutor.java    From Nations with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		if (!ctx.<Double>getOne("amount").isPresent())
		{
			src.sendMessage(Text.of(TextColors.YELLOW, "/n deposit <amount>\n/n withdraw <amount>"));
			return CommandResult.success();
		}
		
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		
		if (NationsPlugin.getEcoService() == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOECO));
			return CommandResult.success();
		}
		Optional<UniqueAccount> optAccount = NationsPlugin.getEcoService().getOrCreateAccount(player.getUniqueId());
		if (!optAccount.isPresent())
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ECONOACCOUNT));
			return CommandResult.success();
		}
		Optional<Account> optNationAccount = NationsPlugin.getEcoService().getOrCreateAccount("nation-" + nation.getUUID().toString());
		if (!optNationAccount.isPresent())
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ECONONATION));
			return CommandResult.success();
		}
		BigDecimal amount = BigDecimal.valueOf(ctx.<Double>getOne("amount").get());
		TransactionResult result = optAccount.get().transfer(optNationAccount.get(), NationsPlugin.getEcoService().getDefaultCurrency(), amount, NationsPlugin.getCause());
		if (result.getResult() == ResultType.ACCOUNT_NO_FUNDS)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOENOUGHMONEY));
			return CommandResult.success();
		}
		else if (result.getResult() != ResultType.SUCCESS)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ECOTRANSACTION));
			return CommandResult.success();
		}
		
		String[] s1 = LanguageHandler.SUCCESS_DEPOSIT.split("\\{AMOUNT\\}");
		Builder builder = Text.builder();
		if (s1[0].indexOf("{BALANCE}") >= 0)
		{
			String[] splited0 = s1[0].split("\\{BALANCE\\}");
			builder
			.append(Text.of(TextColors.GREEN, (splited0.length > 0) ? splited0[0] : ""))
			.append(Utils.formatPrice(TextColors.GREEN, optNationAccount.get().getBalance(NationsPlugin.getEcoService().getDefaultCurrency())))
			.append(Text.of(TextColors.GREEN, (splited0.length > 1) ? splited0[1] : ""));
		}
		else
		{
			builder.append(Text.of(TextColors.GREEN, s1[0]));
		}
		builder.append(Utils.formatPrice(TextColors.GREEN, amount));
		if (s1[1].indexOf("{BALANCE}") >= 0)
		{
			String[] splited1 = s1[1].split("\\{BALANCE\\}");
			builder
			.append(Text.of(TextColors.GREEN, (splited1.length > 0) ? splited1[0] : ""))
			.append(Utils.formatPrice(TextColors.GREEN, optNationAccount.get().getBalance(NationsPlugin.getEcoService().getDefaultCurrency())))
			.append(Text.of(TextColors.GREEN, (splited1.length > 1) ? splited1[1] : ""));
		}
		else
		{
			builder.append(Text.of(TextColors.GREEN, s1[1]));
		}
		src.sendMessage(builder.build());
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #19
Source File: GDClaimManager.java    From GriefDefender with MIT License 4 votes vote down vote up
public ClaimResult deleteClaimInternal(Claim claim, boolean deleteChildren) {
    final GDClaim gdClaim = (GDClaim) claim;
    Set<Claim> subClaims = claim.getChildren(false);
    for (Claim child : subClaims) {
        if (deleteChildren || (gdClaim.parent == null && child.isSubdivision())) {
            this.deleteClaimInternal(child, true);
            continue;
        }

        final GDClaim parentClaim = (GDClaim) claim;
        final GDClaim childClaim = (GDClaim) child;
        if (parentClaim.parent != null) {
            migrateChildToNewParent(parentClaim.parent, childClaim);
        } else {
            // move child to parent folder
            migrateChildToNewParent(null, childClaim);
        }
    }

    resetPlayerClaimVisuals(claim);
    // transfer bank balance to owner
    final Account bankAccount = ((GDClaim) claim).getEconomyAccount();
    if (bankAccount != null) {
        try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
            Sponge.getCauseStackManager().pushCause(GriefDefenderPlugin.getInstance());
            final EconomyService economyService = GriefDefenderPlugin.getInstance().economyService.get();
            final UniqueAccount ownerAccount = economyService.getOrCreateAccount(claim.getOwnerUniqueId()).orElse(null);
            if (ownerAccount != null) {
                ownerAccount.deposit(economyService.getDefaultCurrency(), bankAccount.getBalance(economyService.getDefaultCurrency()),
                    Sponge.getCauseStackManager().getCurrentCause());
            }
            bankAccount.resetBalance(economyService.getDefaultCurrency(), Sponge.getCauseStackManager().getCurrentCause());
        }
    }
    this.worldClaims.remove(claim);
    this.claimUniqueIdMap.remove(claim.getUniqueId());
    this.deleteChunkHashes((GDClaim) claim);
    if (gdClaim.parent != null) {
        gdClaim.parent.children.remove(claim);
    }
    for (UUID playerUniqueId : gdClaim.playersWatching) {
        final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(playerUniqueId);
        if (user != null && user.getOnlinePlayer() != null) {
            user.getInternalPlayerData().revertClaimVisual(gdClaim);
        }
    }

    return DATASTORE.deleteClaimFromStorage((GDClaim) claim);
}
 
Example #20
Source File: LiteTransactionResult.java    From EconomyLite with MIT License 4 votes vote down vote up
@Override
public Account getAccount() {
	return this.account;
}
 
Example #21
Source File: LiteTransferResult.java    From EconomyLite with MIT License 4 votes vote down vote up
@Override
public Account getAccountTo() {
    return this.toWho;
}
 
Example #22
Source File: LiteTransferResult.java    From EconomyLite with MIT License 4 votes vote down vote up
public LiteTransferResult(Account account, BigDecimal amount, Currency currency, ResultType result, Account toWho) {
    super(account, amount, currency, result, TransactionTypes.TRANSFER);
    this.toWho = toWho;
}
 
Example #23
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 4 votes vote down vote up
private TransferResult resultAndEvent(Account account, BigDecimal amount, Currency currency, ResultType resultType, Account toWho, Cause cause) {
    TransferResult result = new LiteTransferResult(account, amount, currency, resultType, toWho);
    Sponge.getEventManager().post(new LiteEconomyTransactionEvent(result, cause));
    return result;
}
 
Example #24
Source File: LiteVirtualAccount.java    From EconomyLite with MIT License 4 votes vote down vote up
private TransactionResult resultAndEvent(Account account, BigDecimal amount, Currency currency, ResultType resultType,
        TransactionType transactionType, Cause cause) {
    TransactionResult result = new LiteTransactionResult(account, amount, currency, resultType, transactionType);
    Sponge.getEventManager().post(new LiteEconomyTransactionEvent(result, cause));
    return result;
}
 
Example #25
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 4 votes vote down vote up
private TransferResult resultAndEvent(Account account, BigDecimal amount, Currency currency, ResultType resultType, Account toWho, Cause cause) {
    TransferResult result = new LiteTransferResult(account, amount, currency, resultType, toWho);
    Sponge.getEventManager().post(new LiteEconomyTransactionEvent(result, UUID.fromString(account.getIdentifier()), cause));
    return result;
}
 
Example #26
Source File: LiteUniqueAccount.java    From EconomyLite with MIT License 4 votes vote down vote up
private TransactionResult resultAndEvent(Account account, BigDecimal amount, Currency currency, ResultType resultType,
        TransactionType transactionType, Cause cause) {
    TransactionResult result = new LiteTransactionResult(account, amount, currency, resultType, transactionType);
    Sponge.getEventManager().post(new LiteEconomyTransactionEvent(result, UUID.fromString(account.getIdentifier()), cause));
    return result;
}
 
Example #27
Source File: EconomyUtil.java    From GriefDefender with MIT License 4 votes vote down vote up
public static TransactionResult depositFunds(UUID uuid, double amount) {
    final Account playerAccount = GriefDefenderPlugin.getInstance().economyService.get().getOrCreateAccount(uuid).orElse(null);
    final Currency defaultCurrency = GriefDefenderPlugin.getInstance().economyService.get().getDefaultCurrency();
    return playerAccount.deposit(defaultCurrency, BigDecimal.valueOf(amount), Sponge.getCauseStackManager().getCurrentCause());
}
 
Example #28
Source File: EconomyUtil.java    From GriefDefender with MIT License 4 votes vote down vote up
public static TransactionResult withdrawFunds(UUID uuid, double amount) {
    final Account playerAccount = GriefDefenderPlugin.getInstance().economyService.get().getOrCreateAccount(uuid).orElse(null);
    final Currency defaultCurrency = GriefDefenderPlugin.getInstance().economyService.get().getDefaultCurrency();
    return playerAccount.withdraw(defaultCurrency, BigDecimal.valueOf(amount), Sponge.getCauseStackManager().getCurrentCause());
}
 
Example #29
Source File: LiteEconomyService.java    From EconomyLite with MIT License 4 votes vote down vote up
@Override
public void registerContextCalculator(ContextCalculator<Account> arg0) {
    return;
}
 
Example #30
Source File: CommandClaimBuy.java    From GriefDefender with MIT License 4 votes vote down vote up
@CommandAlias("claimbuy")
@Description("List all claims available for purchase.\nNote: Requires economy plugin.")
@Subcommand("buy claim")
public void execute(Player player) {
    if (!GriefDefenderPlugin.getInstance().economyService.isPresent()) {
        GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().ECONOMY_NOT_INSTALLED);
        return;
    }

    Account playerAccount = GriefDefenderPlugin.getInstance().economyService.get().getOrCreateAccount(player.getUniqueId()).orElse(null);
    if (playerAccount == null) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.ECONOMY_PLAYER_NOT_FOUND, ImmutableMap.of(
                "player", player.getName()));
        GriefDefenderPlugin.sendMessage(player, message);
        return;
    }

    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    Set<Claim> claimsForSale = new HashSet<>();
    GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(player.getWorld().getUniqueId());
    for (Claim worldClaim : claimManager.getWorldClaims()) {
        if (worldClaim.isWilderness()) {
            continue;
        }
        if (!worldClaim.isAdminClaim() && worldClaim.getEconomyData().isForSale() && worldClaim.getEconomyData().getSalePrice() > -1) {
            claimsForSale.add(worldClaim);
        }
        for (Claim child : worldClaim.getChildren(true)) {
            if (child.isAdminClaim()) {
                continue;
            }
            if (child.getEconomyData().isForSale() && child.getEconomyData().getSalePrice() > -1) {
                claimsForSale.add(child);
            }
        }
    }

    List<Component> textList = CommandHelper.generateClaimTextListCommand(new ArrayList<Component>(), claimsForSale, player.getWorld().getName(), null, player, CommandHelper.createCommandConsumer(player, "claimbuy", ""), false);
    Component footer = null;
    int fillSize = 20 - (textList.size() + 2);
    if (player.hasPermission(GDPermissions.CHAT_CAPTURE)) {
        footer = TextComponent.builder()
                    .append(ChatCaptureUtil.getInstance().createRecordChatComponent(player, null, playerData, "claimbuy"))
                    .build();
        fillSize = 20 - (textList.size() + 3);
    }

    for (int i = 0; i < fillSize; i++) {
        textList.add(TextComponent.of(" "));
    }

    PaginationList.Builder paginationBuilder = PaginationList.builder()
            .title(MessageCache.getInstance().COMMAND_CLAIMBUY_TITLE).padding(TextComponent.of(" ").decoration(TextDecoration.STRIKETHROUGH, true)).contents(textList).footer(footer);
    paginationBuilder.sendTo(player);
    return;
}