当前位置: 首页>>代码示例>>Java>>正文


Java TransactionResult.getResult方法代码示例

本文整理汇总了Java中org.spongepowered.api.service.economy.transaction.TransactionResult.getResult方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionResult.getResult方法的具体用法?Java TransactionResult.getResult怎么用?Java TransactionResult.getResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.service.economy.transaction.TransactionResult的用法示例。


在下文中一共展示了TransactionResult.getResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例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("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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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 toggled for 2 seconds for ", formatPrice(price)));
	} else {
		player.sendMessage(Text.of("Device toggled for 2 seconds"));
	}

	lever.offer(Keys.POWERED, true, CarrotShop.getCause());

	Sponge.getScheduler().createTaskBuilder().execute(new Consumer<Task>() {

		@Override
		public void accept(Task t) {
			t.cancel();
			lever.offer(Keys.POWERED, false, CarrotShop.getCause());
		}
	}).delay(2, TimeUnit.SECONDS).submit(CarrotShop.getInstance());



	return true;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:30,代码来源:Toggle.java

示例12: trigger

import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入方法依赖的package包/类
@Override
public boolean trigger(Player player) {
	Inventory inv = player.getInventory().query(InventoryRow.class);
	
	if (!hasEnough(inv, itemsTemplate)) {
		player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have the items to sell!"));
		return false;
	}

	Builder itemsName = Text.builder();
	for (Inventory item : itemsTemplate.slots()) {
		if (item.peek().isPresent()) {
			Optional<ItemStack> template = getTemplate(inv, item.peek().get());
			if (template.isPresent()) {
				itemsName.append(Text.of(TextColors.YELLOW, " ", item.peek().get().getTranslation().get(), " x", item.peek().get().getQuantity()));
				Optional<ItemStack> items = inv.query(template.get()).poll(item.peek().get().getQuantity());
				if (!items.isPresent()) {
					return false;
				}
			}
		}
	}

	UniqueAccount sellerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
	TransactionResult result = sellerAccount.deposit(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
	if (result.getResult() != ResultType.SUCCESS) {
		player.sendMessage(Text.of(TextColors.DARK_RED, "Unable to give you the money!"));
		return false;
	}
	
	ShopsLogs.log(getOwner(), player, "sell", super.getLocation(), Optional.of(price), getRawCurrency(), Optional.of(itemsTemplate), Optional.empty());

	player.sendMessage(Text.of("You sold", itemsName.build(), " for ", formatPrice(price)));
	
	return true;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:37,代码来源:iSell.java

示例13: transfer

import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入方法依赖的package包/类
@Override
public TransferResult transfer(Account to, Currency currency, BigDecimal amount, Cause cause, Set<Context> contexts)
{
    if (this == to)
    {
        return new Result.Transfer(this, to, currency, amount, contexts, ResultType.SUCCESS, TRANSFER, cause);
    }
    // TODO disallow user -> bank if not at least member of bank
    // TODO disallow bank -> user if cause is not admin?
    // TODO check for visibility of account for causer
    TransactionResult result = this.withdraw(currency, amount, cause, contexts);
    if (result.getResult() == SUCCESS)
    {
        result = to.deposit(currency, amount, cause, contexts);
        if (result.getResult() == SUCCESS)
        {
            return new Result.Transfer(this, to, currency, amount, contexts, SUCCESS, TRANSFER, cause);
        }
        else
        {
            this.deposit(currency, amount, cause, contexts); // rollback withdraw action
            return new Result.Transfer(this, to, currency, amount, contexts, result.getResult(), TRANSFER, cause);
        }
    }
    else
    {
        return new Result.Transfer(this, to, currency, amount, contexts, result.getResult(), TRANSFER, cause);
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:30,代码来源:BaseAccount.java

示例14: give

import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入方法依赖的package包/类
@Command(alias = "grant", desc = "Gives money to one or all players.")
public void give(CommandSource context,
                 @Label("*|<players>") PlayerList users,
                 Double amount)
{
    for (User user : users.list())
    {
        UniqueAccount target = getAccount(context, user);
        if (target != null)
        {
            Currency cur = service.getDefaultCurrency();
            TransactionResult result = target.deposit(cur, new BigDecimal(amount), causeOf(context));
            Text formatAmount = cur.format(result.getAmount());
            switch (result.getResult())
            {
                case SUCCESS:

                    i18n.send(context, POSITIVE, "You gave {txt} to {user}!", formatAmount, user.getName());
                    if (!context.equals(user) && user.isOnline())
                    {
                        i18n.send(user.getPlayer().get(), POSITIVE, "You were granted {txt}.", formatAmount);
                    }
                    break;
                default:
                    i18n.send(context, NEGATIVE, "Could not give the money to {user}!", user);
                    break;
            }
        }
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:31,代码来源:EcoCommand.java

示例15: take

import org.spongepowered.api.service.economy.transaction.TransactionResult; //导入方法依赖的package包/类
@Command(alias = "remove", desc = "Takes money from given user")
public void take(CommandSource context, @Label("*|<players>") PlayerList users, Double amount)
{
    for (User user : users.list())
    {
        UniqueAccount target = getAccount(context, user);
        if (target != null)
        {
            Currency cur = service.getDefaultCurrency();
            TransactionResult result = target.withdraw(cur, new BigDecimal(amount), causeOf(context));
            Text formatAmount = cur.format(result.getAmount());
            switch (result.getResult())
            {
                case SUCCESS:
                    i18n.send(context, POSITIVE, "You took {txt} from {user}!", formatAmount, user);
                    if (!context.equals(user) && user.isOnline())
                    {
                        i18n.send(user.getPlayer().get(), NEUTRAL, "Withdrew {txt} from your account.", formatAmount);
                    }
                    break;
                default:
                    i18n.send(context, NEGATIVE, "Could not take the money from {user}!", user);
                    break;
            }
        }
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:28,代码来源:EcoCommand.java


注:本文中的org.spongepowered.api.service.economy.transaction.TransactionResult.getResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。