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


Java UniqueAccount.withdraw方法代码示例

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


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

示例1: withdraw

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的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: trigger

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的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.account.UniqueAccount; //导入方法依赖的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.account.UniqueAccount; //导入方法依赖的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.account.UniqueAccount; //导入方法依赖的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: trigger

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的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

示例7: buyHandler

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void buyHandler(Player player, long value, Region r) {

	if (r.isLeader(RPUtil.PlayerToUUID(player.getName()))){
		RPLang.sendMessage(player, "economy.region.buy.own");
		return;
	}

	UniqueAccount acc = RedProtect.get().econ.getOrCreateAccount(player.getUniqueId()).get();
	Double money = acc.getBalance(RedProtect.get().econ.getDefaultCurrency()).doubleValue();
	if (money >= value){
		String rname = r.getName();
		ArrayList<String> sellers = new ArrayList<>(r.getLeaders());
		if (RPEconomy.BuyRegion(r, RPUtil.PlayerToUUID(player.getName()))){
			acc.withdraw(RedProtect.get().econ.getDefaultCurrency(), BigDecimal.valueOf(value), RedProtect.get().getPVHelper().getCause(player));
			for (String seller : sellers){
				UserStorageService uss = Sponge.getGame().getServiceManager().provide(UserStorageService.class).get();
				Optional<User> offp = uss.get(RPUtil.UUIDtoPlayer(seller));
				if (!seller.equals(RedProtect.get().cfgs.getString("region-settings.default-leader")) && offp.isPresent()){
					UniqueAccount offAcc = RedProtect.get().econ.getOrCreateAccount(offp.get().getUniqueId()).get();
					offAcc.deposit(RedProtect.get().econ.getDefaultCurrency(), BigDecimal.valueOf(value), RedProtect.get().getPVHelper().getCause(player));
					if (offp.get().isOnline()){
						RPLang.sendMessage(offp.get().getPlayer().get(), RPLang.get("economy.region.buy.bought").replace("{player}", player.getName()).replace("{region}", rname).replace("{world}", r.getWorld()));
					}
				}
			}
			RPLang.sendMessage(player, RPLang.get("economy.region.buy.success").replace("{region}", r.getName()).replace("{value}", String.valueOf(value)).replace("{ecosymbol}", RedProtect.get().cfgs.getEcoString("economy-name")));
           } else {
			RPLang.sendMessage(player, "economy.region.error");
           }
	} else {
		RPLang.sendMessage(player, "economy.region.buy.nomoney");
       }
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:35,代码来源:RPCommands.java

示例8: take

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的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

示例9: withdrawMoney

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的package包/类
@Override
public void withdrawMoney(PlotPlayer player, double amount) {
    if (econ != null) {
        Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
        if (accOpt.isPresent()) {
            UniqueAccount acc = accOpt.get();

            acc.withdraw(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
        }
    }
}
 
开发者ID:IntellectualSites,项目名称:PlotSquared,代码行数:12,代码来源:SpongeEconHandler.java

示例10: withdrawPlayer

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的package包/类
public boolean withdrawPlayer(Player player, double price)
{
    UniqueAccount acc = economy.getOrCreateAccount(player.getUniqueId()).get();// Make sure account exists
    TransactionResult result = acc.withdraw(economy.getDefaultCurrency(), new BigDecimal(price), Cause.of(EventContext.empty(), player));
    if (result.getResult() == ResultType.SUCCESS)
    {
        // TODO bankAccounts
        return true;
    }
    return false;
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:12,代码来源:RepairBlock.java

示例11: trigger

import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的package包/类
@Override
public boolean trigger(Player player) {
	Optional<TileEntity> chestToGive = sellerChest.getTileEntity();
	if (chestToGive.isPresent() && chestToGive.get() instanceof TileEntityCarrier) {
		if (!hasEnough(((TileEntityCarrier) chestToGive.get()).getInventory(), itemsTemplate)) {
			player.sendMessage(Text.of(TextColors.GOLD, "This shop is empty!"));
			update();
			return false;
		}
	} else {
		return false;
	}
	UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
	TransactionResult accountResult = buyerAccount.withdraw(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
	if (accountResult.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);

	Inventory invToGive = ((TileEntityCarrier) chestToGive.get()).getInventory();

	Builder itemsName = Text.builder();

	for (Inventory item : itemsTemplate.slots()) {
		if (item.peek().isPresent()) {
			Optional<ItemStack> template = getTemplate(invToGive, 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 = invToGive.query(template.get()).poll(item.peek().get().getQuantity());
				if (items.isPresent()) {
					inv.offer(items.get()).getRejectedItems().forEach(action -> {
						putItemInWorld(action, player.getLocation());
					});
				} else {
					return false;
				}
			}
		}
	}

	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)));

	update();
	return true;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:49,代码来源:aBuy.java


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