本文整理汇总了Java中org.spongepowered.api.service.economy.transaction.ResultType.ACCOUNT_NO_FUNDS属性的典型用法代码示例。如果您正苦于以下问题:Java ResultType.ACCOUNT_NO_FUNDS属性的具体用法?Java ResultType.ACCOUNT_NO_FUNDS怎么用?Java ResultType.ACCOUNT_NO_FUNDS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.spongepowered.api.service.economy.transaction.ResultType
的用法示例。
在下文中一共展示了ResultType.ACCOUNT_NO_FUNDS属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: withdraw
@Override
public TransactionResult withdraw(final Currency currency, final BigDecimal amount, final Cause cause, final Set<Context> contexts) {
BigDecimal before = this.getBalance(currency);
BigDecimal after = before.subtract(amount);
// Quantité positive
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
// Séperieur au min
if (after.compareTo(ECurrency.getBalanceMin(currency)) >= 0) {
// Transfére
this.setBalance(currency, after);
this.log(currency, before, after, TransactionTypes.WITHDRAW, cause);
return new ETransactionResult(this.plugin, this, currency, amount, contexts, ResultType.SUCCESS, TransactionTypes.WITHDRAW);
}
return new ETransactionResult(this.plugin, this, currency, amount, contexts, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.WITHDRAW);
}
return new ETransactionResult(this.plugin, this, currency, amount, contexts, ResultType.FAILED, TransactionTypes.WITHDRAW);
}
示例2: execute
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
if (src instanceof Player)
{
Player player = (Player) src;
if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean())
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PLUGINDISABLEDINWORLD));
return CommandResult.success();
}
Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
if (nation == null)
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
return CommandResult.success();
}
if (!nation.isStaff(player.getUniqueId()))
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
return CommandResult.success();
}
Location<World> loc = player.getLocation();
if (!DataHandler.canClaim(loc, false, nation.getUUID()))
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_TOOCLOSE));
return CommandResult.success();
}
if (NationsPlugin.getEcoService() == null)
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOECO));
return CommandResult.success();
}
Optional<Account> optAccount = NationsPlugin.getEcoService().getOrCreateAccount("nation-" + nation.getUUID());
if (!optAccount.isPresent())
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ECONONATION));
return CommandResult.success();
}
BigDecimal price = BigDecimal.valueOf(ConfigHandler.getNode("prices", "outpostCreationPrice").getDouble());
TransactionResult result = optAccount.get().withdraw(NationsPlugin.getEcoService().getDefaultCurrency(), price, NationsPlugin.getCause());
if (result.getResult() == ResultType.ACCOUNT_NO_FUNDS)
{
src.sendMessage(Text.builder()
.append(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDMONEYNATION.split("\\{AMOUNT\\}")[0]))
.append(Utils.formatPrice(TextColors.RED, price))
.append(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDMONEYNATION.split("\\{AMOUNT\\}")[1])).build());
return CommandResult.success();
}
else if (result.getResult() != ResultType.SUCCESS)
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ECOTRANSACTION));
return CommandResult.success();
}
nation.getRegion().addRect(new Rect(loc.getExtent().getUniqueId(), loc.getBlockX(), loc.getBlockX(), loc.getBlockZ(), loc.getBlockZ()));
DataHandler.addToWorldChunks(nation);
DataHandler.saveNation(nation.getUUID());
src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_OUTPOST));
}
else
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
}
return CommandResult.success();
}
示例3: execute
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
if (src instanceof Player)
{
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 (!nation.isStaff(player.getUniqueId()))
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONPRES));
return CommandResult.success();
}
if (!ctx.<String>getOne("amount").isPresent())
{
src.sendMessage(Text.of(TextColors.YELLOW, "/n buyextra <amount>"));
return CommandResult.success();
}
int n = ctx.<Integer>getOne("amount").get();
int maxToBuy = ConfigHandler.getNode("others", "maxExtra").getInt() - nation.getExtras();
if (n > maxToBuy)
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOMOREBLOCK.replaceAll("\\{NUM\\}", Integer.toString(maxToBuy))));
return CommandResult.success();
}
if (NationsPlugin.getEcoService() == null)
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOECO));
return CommandResult.success();
}
Optional<Account> optAccount = NationsPlugin.getEcoService().getOrCreateAccount("nation-" + nation.getUUID().toString());
if (!optAccount.isPresent())
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ECONONATION));
return CommandResult.success();
}
BigDecimal price = BigDecimal.valueOf(n * ConfigHandler.getNode("prices", "extraPrice").getDouble());
TransactionResult result = optAccount.get().withdraw(NationsPlugin.getEcoService().getDefaultCurrency(), price, NationsPlugin.getCause());
if (result.getResult() == ResultType.ACCOUNT_NO_FUNDS)
{
String[] splited = LanguageHandler.ERROR_NEEDMONEY.split("\\{AMOUNT\\}");
src.sendMessage(Text.builder()
.append(Text.of(TextColors.RED, (splited.length > 0) ? splited[0] : ""))
.append(Utils.formatPrice(TextColors.RED, price))
.append(Text.of(TextColors.RED, (splited.length > 1) ? splited[1] : "")).build());
return CommandResult.success();
}
else if (result.getResult() != ResultType.SUCCESS)
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ECOTRANSACTION));
return CommandResult.success();
}
nation.addExtras(n);
DataHandler.saveNation(nation.getUUID());
String[] splited2 = LanguageHandler.SUCCESS_ADDBLOCKS.replaceAll("\\{NUM\\}", Integer.toString(n)).split("\\{AMOUNT\\}");
src.sendMessage(Text.builder()
.append(Text.of(TextColors.AQUA, (splited2.length > 0) ? splited2[0] : ""))
.append(Utils.formatPrice(TextColors.AQUA, price))
.append(Text.of(TextColors.AQUA, (splited2.length > 1) ? splited2[1] : "")).build());
}
else
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
}
return CommandResult.success();
}
示例4: execute
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 (!nation.isStaff(player.getUniqueId()))
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
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 = optNationAccount.get().transfer(optAccount.get(), NationsPlugin.getEcoService().getDefaultCurrency(), amount, NationsPlugin.getCause());
if (result.getResult() == ResultType.ACCOUNT_NO_FUNDS)
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOENOUGHMONEYNATION));
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_WITHDRAW.split("\\{AMOUNT\\}");
Builder builder = Text.builder();
if (s1[0].indexOf("\\{BALANCE\\}") >= 0)
{
builder
.append(Text.of(TextColors.GREEN, s1[0].split("\\{BALANCE\\}")[0]))
.append(Utils.formatPrice(TextColors.GREEN, optNationAccount.get().getBalance(NationsPlugin.getEcoService().getDefaultCurrency())))
.append(Text.of(TextColors.GREEN, s1[0].split("\\{BALANCE\\}")[1]));
}
builder.append(Utils.formatPrice(TextColors.GREEN, amount));
if (s1[1].indexOf("\\{BALANCE\\}") >= 0)
{
builder
.append(Text.of(TextColors.GREEN, s1[1].split("\\{BALANCE\\}")[0]))
.append(Utils.formatPrice(TextColors.GREEN, optNationAccount.get().getBalance(NationsPlugin.getEcoService().getDefaultCurrency())))
.append(Text.of(TextColors.GREEN, s1[1].split("\\{BALANCE\\}")[1]));
}
src.sendMessage(builder.build());
}
else
{
src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
}
return CommandResult.success();
}
示例5: transfer
@Override
public TransferResult transfer(final Account to, final Currency currency, final BigDecimal amount, final Cause cause, final Set<Context> contexts) {
ResultType result = ResultType.SUCCESS;
BigDecimal player_before = this.getBalance(currency);
BigDecimal player_after = player_before.subtract(amount);
// Quantité positive
if (amount.compareTo(BigDecimal.ZERO) > 0) {
// Séperieur au min
if (player_after.compareTo(ECurrency.getBalanceMin(currency)) >= 0) {
// Transfére
BigDecimal to_before = to.getBalance(currency);
BigDecimal to_after = to_before.add(amount);
// Inférieur au max
if (to_after.compareTo(ECurrency.getBalanceMax(currency)) <= 0) {
if (to instanceof EAccount) {
EAccount account = (EAccount) to;
this.setBalance(currency, player_after);
account.setBalance(currency, to_after);
this.log(currency, player_before, player_after, TransactionTypes.TRANSFER, cause, to.getIdentifier());
account.log(currency, to_before, to_after, TransactionTypes.TRANSFER, cause, this.getIdentifier());
} else {
result = this.deposit(currency, amount, cause, contexts).getResult();
if (result.equals(ResultType.SUCCESS)) {
this.setBalance(currency, player_after);
this.log(currency, player_before, player_after, TransactionTypes.TRANSFER, cause);
}
}
return new ETransferResult(this.plugin, this, to, currency, amount, contexts, result, TransactionTypes.TRANSFER);
} else {
return new ETransferResult(this.plugin, this, to, currency, amount, contexts, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.TRANSFER);
}
} else {
return new ETransferResult(this.plugin, this, to, currency, amount, contexts, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.TRANSFER);
}
}
return new ETransferResult(this.plugin, this, to, currency, amount, contexts, ResultType.FAILED, TransactionTypes.TRANSFER);
}