本文整理汇总了Java中org.spongepowered.api.service.economy.transaction.TransactionResult类的典型用法代码示例。如果您正苦于以下问题:Java TransactionResult类的具体用法?Java TransactionResult怎么用?Java TransactionResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionResult类属于org.spongepowered.api.service.economy.transaction包,在下文中一共展示了TransactionResult类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: withdraw
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
public static boolean withdraw(UUID uuid, double charge) {
if (charge == 0) {
return true;
}
EconomyService economyService = MCClans.getPlugin().getServiceHelper().economyService;
Currency currency = MCClans.getPlugin().getServiceHelper().currency;
Optional<UniqueAccount> accountOpt = economyService.getOrCreateAccount(uuid);
if (!accountOpt.isPresent()) {
return false;
}
UniqueAccount account = accountOpt.get();
TransactionResult result = account.withdraw(
currency,
BigDecimal.valueOf(charge),
Cause.of(NamedCause.of("MCClans", MCClans.getPlugin()))
);
return (result.getResult().equals(ResultType.SUCCESS));
}
开发者ID:iLefty,项目名称:mcClans,代码行数:21,代码来源:EconomyUtils.java
示例2: buyShop
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
public ShopTransactionResult buyShop(Player player) {
if (!isForSale()) {
return new ShopTransactionResult(Messages.THIS_SHOP_IS_NOT_FOR_SALE);
}
// Transfer funds from the purchaser to the owner
EconManager manager = EconManager.getInstance();
Optional<UniqueAccount> playerAccountOptional = manager.getOrCreateAccount(player.getUniqueId());
Optional<UniqueAccount> ownerAccountOptional = manager.getOrCreateAccount(ownerUUID);
TransactionResult result =
playerAccountOptional.get()
.transfer(ownerAccountOptional.get(), getShopCurrency(), BigDecimal.valueOf(price), Sponge.getCauseStackManager().getCurrentCause());
if(result.getResult() == ResultType.SUCCESS) {
ownerUUID = player.getUniqueId();
price = -1;
rent = -1;
managerUUIDset.clear();
return ShopTransactionResult.SUCCESS;
} else {
return new ShopTransactionResult(Messages.YOU_DON_T_HAVE_ENOUGH_FUNDS);
}
}
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:26,代码来源:Shop.java
示例3: trigger
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public boolean trigger(Player player) {
if (CarrotShop.getEcoService() != null) {
UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
TransactionResult result = buyerAccount.withdraw(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
if (result.getResult() != ResultType.SUCCESS) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have enough money!"));
return false;
}
player.sendMessage(Text.of("Device deactivated for ", formatPrice(price)));
} else {
player.sendMessage(Text.of("Device deactivated"));
}
lever.offer(Keys.POWERED, false, CarrotShop.getCause());
return true;
}
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:19,代码来源:DeviceOff.java
示例4: trigger
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public boolean trigger(Player player) {
if (CarrotShop.getEcoService() != null) {
UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
TransactionResult result = buyerAccount.withdraw(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
if (result.getResult() != ResultType.SUCCESS) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have enough money!"));
return false;
}
player.sendMessage(Text.of("You healed for ", formatPrice(price)));
}
else
player.sendMessage(Text.of("You healed"));
player.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());
return true;
}
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:19,代码来源:Heal.java
示例5: trigger
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public boolean trigger(Player player) {
UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
TransactionResult result = buyerAccount.withdraw(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
if (result.getResult() != ResultType.SUCCESS) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have enough money!"));
return false;
}
Inventory inv = player.getInventory().query(InventoryRow.class);
Builder itemsName = Text.builder();
for (Inventory item : itemsTemplate.slots()) {
if (item.peek().isPresent()) {
itemsName.append(Text.of(TextColors.YELLOW, " ", item.peek().get().getTranslation().get(), " x", item.peek().get().getQuantity()));
inv.offer(item.peek().get().copy()).getRejectedItems().forEach(action -> {
putItemInWorld(action, player.getLocation());
});
}
}
ShopsLogs.log(getOwner(), player, "buy", super.getLocation(), Optional.of(price), getRawCurrency(), Optional.of(itemsTemplate), Optional.empty());
player.sendMessage(Text.of("You bought", itemsName.build(), " for ", formatPrice(price)));
return true;
}
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:27,代码来源:iBuy.java
示例6: trigger
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public boolean trigger(Player player) {
if (CarrotShop.getEcoService() != null) {
UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
TransactionResult result = buyerAccount.withdraw(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
if (result.getResult() != ResultType.SUCCESS) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have enough money!"));
return false;
}
player.sendMessage(Text.of("Device activated for ", formatPrice(price)));
} else {
player.sendMessage(Text.of("Device activated"));
}
lever.offer(Keys.POWERED, true, CarrotShop.getCause());
return true;
}
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:21,代码来源:DeviceOn.java
示例7: setBalance
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public TransactionResult setBalance(final Currency currency, final BigDecimal after, final Cause cause, final Set<Context> contexts) {
TransactionType transaction = TransactionTypes.WITHDRAW;
BigDecimal before = this.getBalance(currency);
BigDecimal amount = before.subtract(after);
// Si le changement est supérieur ou égal à 0 c'est que l'on dépose de l'argent
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
transaction = TransactionTypes.DEPOSIT;
}
// Transfére
this.setBalance(currency, after);
this.log(currency, before, after, transaction, cause);
return new ETransactionResult(this.plugin, this, currency, amount.abs(), contexts, ResultType.SUCCESS, transaction);
}
开发者ID:EverCraft,项目名称:EverEconomy,代码行数:19,代码来源:EAccount.java
示例8: resetBalances
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public Map<Currency, TransactionResult> resetBalances(final Cause cause, final Set<Context> contexts) {
Map<Currency, TransactionResult> list = new HashMap<Currency, TransactionResult>();
// Pour tous les monnaies
for (Currency currency : this.currencies.keySet()){
TransactionType transaction = TransactionTypes.WITHDRAW;
BigDecimal before = this.getBalance(currency);
BigDecimal after = getDefaultBalance(currency);
BigDecimal amount = before.subtract(after);
// Si le changement est supérieur ou égal à 0 c'est que l'on dépose de l'argent
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
transaction = TransactionTypes.DEPOSIT;
}
// Transfére
this.setBalance(currency, after);
this.log(currency, before, after, transaction, cause);
list.put(currency, new ETransactionResult(this.plugin, this, currency, amount.abs(), contexts, ResultType.SUCCESS, transaction));
}
this.plugin.getThreadAsync().execute(() -> this.delete());
return list;
}
开发者ID:EverCraft,项目名称:EverEconomy,代码行数:26,代码来源:EAccount.java
示例9: resetBalance
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public TransactionResult resetBalance(final Currency currency, final Cause cause, final Set<Context> contexts) {
TransactionType transaction = TransactionTypes.WITHDRAW;
BigDecimal before = this.getBalance(currency);
BigDecimal after = getDefaultBalance(currency);
BigDecimal amount = before.subtract(after);
// Si le changement est supérieur ou égal à 0 c'est que l'on dépose de l'argent
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
transaction = TransactionTypes.DEPOSIT;
}
// Transfére
this.setBalance(currency, after);
this.log(currency, before, after, transaction, cause);
return new ETransactionResult(this.plugin, this, currency, amount.abs(), contexts, ResultType.SUCCESS, transaction);
}
开发者ID:EverCraft,项目名称:EverEconomy,代码行数:20,代码来源:EAccount.java
示例10: deposit
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public TransactionResult deposit(final Currency currency, final BigDecimal amount, final Cause cause, final Set<Context> contexts) {
BigDecimal before = this.getBalance(currency);
BigDecimal after = before.add(amount);
// Quantité positive
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
// Inférieur au max
if (after.compareTo(ECurrency.getBalanceMax(currency)) <= 0) {
// Transfére
this.setBalance(currency, after);
this.log(currency, before, after, TransactionTypes.DEPOSIT, cause);
return new ETransactionResult(this.plugin, this, currency, amount, contexts, ResultType.SUCCESS, TransactionTypes.DEPOSIT);
}
return new ETransactionResult(this.plugin, this, currency, amount, contexts, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.DEPOSIT);
}
return new ETransactionResult(this.plugin, this, currency, amount, contexts, ResultType.FAILED, TransactionTypes.DEPOSIT);
}
开发者ID:EverCraft,项目名称:EverEconomy,代码行数:19,代码来源:EAccount.java
示例11: withdraw
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@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);
}
开发者ID:EverCraft,项目名称:EverEconomy,代码行数:19,代码来源:EAccount.java
示例12: withdraw
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public TransactionResult withdraw(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
BigDecimal newBal = getBalance(currency).subtract(amount);
// Check if the new balance is in bounds
if (newBal.compareTo(BigDecimal.ZERO) == -1) {
return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.WITHDRAW, cause);
}
if (newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.WITHDRAW, cause);
}
if (playerService.withdraw(uuid, amount, currency, cause)) {
return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause);
} else {
return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause);
}
}
开发者ID:Flibio,项目名称:EconomyLite,代码行数:17,代码来源:LiteUniqueAccount.java
示例13: withdraw
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public TransactionResult withdraw(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts) {
BigDecimal newBal = getBalance(currency).subtract(amount);
// Check if the new balance is in bounds
if (newBal.compareTo(BigDecimal.ZERO) == -1) {
return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_FUNDS, TransactionTypes.WITHDRAW, cause);
}
if (newBal.compareTo(BigDecimal.valueOf(999999999)) == 1) {
return resultAndEvent(this, amount, currency, ResultType.ACCOUNT_NO_SPACE, TransactionTypes.WITHDRAW, cause);
}
if (virtualService.withdraw(name, amount, currency, cause)) {
return resultAndEvent(this, amount, currency, ResultType.SUCCESS, TransactionTypes.WITHDRAW, cause);
} else {
return resultAndEvent(this, amount, currency, ResultType.FAILED, TransactionTypes.WITHDRAW, cause);
}
}
开发者ID:Flibio,项目名称:EconomyLite,代码行数:17,代码来源:LiteVirtualAccount.java
示例14: give
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Command(alias = "grant", desc = "Gives money to a bank or all banks")
public void give(CommandSource context, BaseAccount.Virtual bank, Double amount)
{
TransactionResult result = bank.deposit(service.getDefaultCurrency(), new BigDecimal(amount), causeOf(context));
switch (result.getResult())
{
case SUCCESS:
Text formatAmount = result.getCurrency().format(result.getAmount());
i18n.send(context, POSITIVE, "You gave {txt#amount} to the bank {account}!",
formatAmount, bank);
Sponge.getServer().getOnlinePlayers().stream()
.filter(onlineUser -> service.hasAccess(bank, AccessLevel.WITHDRAW, onlineUser))
.forEach(onlineUser -> i18n.send(onlineUser, POSITIVE, "{user} granted {input#amount} to your bank {account}!",
onlineUser, formatAmount, bank));
break;
default:
i18n.send(context, NEGATIVE, "Transaction failed!");
break;
}
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:21,代码来源:EcoBankCommand.java
示例15: take
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Command(alias = "remove", desc = "Takes money from given bank or all banks")
public void take(CommandSource context, BaseAccount.Virtual bank, Double amount)
{
TransactionResult result = bank.withdraw(service.getDefaultCurrency(), new BigDecimal(amount), causeOf(context));
switch (result.getResult())
{
case SUCCESS:
Text formatAmount = result.getCurrency().format(result.getAmount());
i18n.send(context, POSITIVE, "You took {input#amount} from the bank {account}!",
formatAmount, bank);
Sponge.getServer().getOnlinePlayers().stream()
.filter(onlineUser -> service.hasAccess(bank, AccessLevel.WITHDRAW, onlineUser))
.forEach(onlineUser -> i18n.send(onlineUser, POSITIVE, "{user} charged your bank {account} for {input#amount}!",
onlineUser, bank, formatAmount));
break;
default:
i18n.send(context, NEGATIVE, "Transaction failed!");
break;
}
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:22,代码来源:EcoBankCommand.java
示例16: reset
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Command(desc = "Reset the money from given banks")
public void reset(CommandSource context, BaseAccount.Virtual bank)
{
TransactionResult result = bank.resetBalance(service.getDefaultCurrency(), causeOf(context));
switch (result.getResult())
{
case SUCCESS:
Text formatAmount = result.getCurrency().format(result.getAmount());
i18n.send(context, POSITIVE, "The account of the bank {account} got reset to {txt#balance}!",
bank, formatAmount);
Sponge.getServer().getOnlinePlayers().stream()
.filter(onlineUser -> service.hasAccess(bank, AccessLevel.WITHDRAW, onlineUser))
.forEach(onlineUser -> i18n.send(onlineUser, POSITIVE, "{user} reset the money of your bank {account} to {txt#balance}!",
onlineUser, bank, formatAmount));
break;
default:
i18n.send(context, NEGATIVE, "Transaction failed!");
break;
}
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:22,代码来源:EcoBankCommand.java
示例17: set
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Command(desc = "Sets the money from given banks")
public void set(CommandSource context, BaseAccount.Virtual bank, Double amount)
{
TransactionResult result = bank.setBalance(service.getDefaultCurrency(), new BigDecimal(amount), causeOf(context));
switch (result.getResult())
{
case SUCCESS:
Text formatAmount = result.getCurrency().format(result.getAmount());
i18n.send(context, POSITIVE, "The money of bank account {account} got set to {txt#balance}!",
bank, formatAmount);
Sponge.getServer().getOnlinePlayers().stream()
.filter(onlineUser -> service.hasAccess(bank, AccessLevel.WITHDRAW, onlineUser))
.forEach(onlineUser -> i18n.send(onlineUser, POSITIVE, "{user} set the money of your bank {account} to {txt#balance}!",
onlineUser, bank, formatAmount));
break;
default:
i18n.send(context, NEGATIVE, "Transaction failed!");
break;
}
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:21,代码来源:EcoBankCommand.java
示例18: withdraw
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
@Override
public TransactionResult withdraw(Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts)
{
ConfigCurrency cur = cast(currency);
Optional<BalanceModel> model = getModel(cur, contexts);
if (model.isPresent())
{
long newBalance = model.get().getBalance() - cur.toLong(amount);
long min = cur.toLong(cur.getMin(this));
if (newBalance < min)
{
return new Result(this, currency, amount, contexts, ACCOUNT_NO_FUNDS, WITHDRAW, cause);
}
model.get().setBalance(newBalance);
return new Result(this, currency, amount, contexts, SUCCESS, WITHDRAW, cause);
}
return new Result(this, currency, amount, contexts, CONTEXT_MISMATCH, WITHDRAW, cause);
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:20,代码来源:BaseAccount.java
示例19: transfer
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
private static boolean transfer(Account fromAccount, Account toAccount, Currency currency, double charge) {
if (charge == 0) {
return true;
}
TransactionResult result = fromAccount.transfer(
toAccount,
currency,
BigDecimal.valueOf(charge),
Cause.of(NamedCause.of("MCClans", MCClans.getPlugin()))
);
return (result.getResult().equals(ResultType.SUCCESS));
}
开发者ID:iLefty,项目名称:mcClans,代码行数:14,代码来源:EconomyUtils.java
示例20: rentShop
import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入依赖的package包/类
public ShopTransactionResult rentShop(Player player, BigDecimal amount) {
if (!isForRent() && !player.getUniqueId().equals(renterUUID)) {
return new ShopTransactionResult(Messages.THIS_SHOP_IS_NOT_FOR_RENT);
}
long duration = amount.divide(BigDecimal.valueOf(rent), BigDecimal.ROUND_FLOOR).longValue();
if (duration < 1) {
return new ShopTransactionResult(Messages.YOU_DON_T_HAVE_ENOUGH_FUNDS);
}
// Transfer funds from the purchaser to the owner
EconManager manager = EconManager.getInstance();
TransactionResult result;
Optional<UniqueAccount> renterAccountOptional = manager.getOrCreateAccount(player.getUniqueId());
if (ownerUUID != null) {
Optional<UniqueAccount> ownerAccountOptional = manager.getOrCreateAccount(ownerUUID);
result =
renterAccountOptional.get()
.transfer(ownerAccountOptional.get(), getShopCurrency(), BigDecimal.valueOf(rent * duration), Sponge.getCauseStackManager().getCurrentCause());
} else {
result = renterAccountOptional.get().withdraw(getShopCurrency(), BigDecimal.valueOf(rent * duration), Sponge.getCauseStackManager().getCurrentCause());
}
if (result.getResult() == ResultType.SUCCESS) {
ShopRentManager.getInstance().rentShop(this, duration);
renterUUID = player.getUniqueId();
return ShopTransactionResult.SUCCESS;
} else {
return new ShopTransactionResult(Messages.YOU_DON_T_HAVE_ENOUGH_FUNDS);
}
}
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:35,代码来源:Shop.java
注:本文中的org.spongepowered.api.service.economy.transaction.TransactionResult类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论