本文整理汇总了Java中org.spongepowered.api.service.economy.account.UniqueAccount.deposit方法的典型用法代码示例。如果您正苦于以下问题:Java UniqueAccount.deposit方法的具体用法?Java UniqueAccount.deposit怎么用?Java UniqueAccount.deposit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.service.economy.account.UniqueAccount
的用法示例。
在下文中一共展示了UniqueAccount.deposit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trigger
import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的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;
}
示例2: 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");
}
}
示例3: give
import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的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;
}
}
}
}
示例4: depositMoney
import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的package包/类
@Override
public void depositMoney(PlotPlayer player, double amount) {
if (econ != null) {
Optional<UniqueAccount> accOpt = econ.getOrCreateAccount(player.getUUID());
if (accOpt.isPresent()) {
UniqueAccount acc = accOpt.get();
acc.deposit(econ.getDefaultCurrency(), new BigDecimal(amount), SpongeUtil.CAUSE);
}
}
}
示例5: trigger
import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的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;
}
Optional<TileEntity> chest = sellerChest.getTileEntity();
if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
Inventory chestInv = ((TileEntityCarrier) chest.get()).getInventory();
if (chestInv.capacity() - chestInv.size() < itemsTemplate.size()) {
player.sendMessage(Text.of(TextColors.GOLD, "This shop is full!"));
update();
return false;
}
}
Inventory invChest = ((TileEntityCarrier) chest.get()).getInventory();
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()) {
invChest.offer(items.get());
} else {
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());
Text report = Text.of(" sold", itemsName.build(), " for ", formatPrice(price));
player.sendMessage(Text.of("You", report));
if (!CarrotShop.noSpam(getOwner())) {
Optional<Player> seller = Sponge.getServer().getPlayer(getOwner());
if (seller.isPresent()) {
seller.get().sendMessage(Text.of(player.getName(), report));
}
}
update();
return true;
}
示例6: awardPlayer
import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的package包/类
@Override
public boolean awardPlayer(Player player) {
Optional<BigDecimal> amountOpt = Util.safeGetBigDecimal(this.data, "amount");
if (!amountOpt.isPresent()) {
this.plugin.getLogger().error("No amount specified. Aborting.");
return false;
}
final Optional<EconomyService> econSvcOpt = Sponge.getServiceManager().provide(EconomyService.class);
if (!econSvcOpt.isPresent()) {
this.plugin.getLogger().error("No EconomyService present. Cannot give monetary award.");
return false;
}
final EconomyService economy = econSvcOpt.get();
final Optional<UniqueAccount> accountOpt = economy.getOrCreateAccount(player.getUniqueId());
if (!accountOpt.isPresent()) {
this.plugin.getLogger()
.error("Unable to retrieve economy account for player " + player.getUniqueId().toString());
return false;
}
final UniqueAccount playerAccount = accountOpt.get();
Optional<String> currencyIDOpt = Util.safeGetString(this.data, "currency");
Optional<Currency> currencyOpt = Optional.empty();
if (currencyIDOpt.isPresent()) {
final Iterator<Currency> iter = economy.getCurrencies().iterator();
while (iter.hasNext()) {
Currency currency = iter.next();
if (currency.getId().equalsIgnoreCase(currencyIDOpt.get())) {
currencyOpt = Optional.of(currency);
}
}
} else {
currencyOpt = Optional.of(economy.getDefaultCurrency());
}
if (!currencyOpt.isPresent()) {
this.plugin.getLogger().error("Could not find currency " + currencyIDOpt.get()
+ ". Cannot award monetary award to player " + player.getUniqueId().toString());
return false;
}
// TODO add more stuff to the cause chain
TransactionResult result = playerAccount.deposit(currencyOpt.get(), amountOpt.get(), Cause.builder()
.build(EventContext.builder().add(EventContextKeys.PLUGIN, BadgeUpSponge.getContainer()).build()));
return result.getResult().equals(ResultType.SUCCESS);
}
示例7: deleteClaimInternal
import org.spongepowered.api.service.economy.account.UniqueAccount; //导入方法依赖的package包/类
public void deleteClaimInternal(Claim claim, boolean deleteChildren) {
final GPClaim gpClaim = (GPClaim) claim;
List<Claim> subClaims = claim.getChildren(false);
for (Claim child : subClaims) {
if (deleteChildren) {
this.deleteClaimInternal(child, true);
continue;
}
GPClaim childClaim = (GPClaim) child;
((GPClaim) claim).children.remove(childClaim);
childClaim.parent = gpClaim.parent;
String fileName = childClaim.getClaimStorage().filePath.getFileName().toString();
final Path newPath = gpClaim.getClaimStorage().filePath.getParent().getParent().resolve(childClaim.getType().name().toLowerCase()).resolve(fileName);
try {
Files.createDirectories(newPath.getParent());
Files.move(childClaim.getClaimStorage().filePath, newPath);
childClaim.setClaimStorage(new ClaimStorageData(newPath, this.getWorldProperties().getUniqueId(), (ClaimDataConfig) childClaim.getInternalClaimData()));
if (childClaim.parent == null) {
this.addClaim(childClaim, false);
}
} catch (IOException e) {
e.printStackTrace();
}
}
// player may be offline so check is needed
GPPlayerData playerData = this.getPlayerDataMap().get(claim.getOwnerUniqueId());
if (playerData != null) {
playerData.getInternalClaims().remove(claim);
if (playerData.lastClaim != null) {
playerData.lastClaim.clear();
}
}
// transfer bank balance to owner
final Account bankAccount = claim.getEconomyAccount().orElse(null);
if (bankAccount != null) {
try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(GriefPreventionPlugin.instance);
final EconomyService economyService = GriefPreventionPlugin.instance.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((GPClaim) claim);
if (gpClaim.parent != null) {
gpClaim.parent.children.remove(claim);
}
// revert visuals for all players watching this claim
List<UUID> playersWatching = new ArrayList<>(((GPClaim) claim).playersWatching);
for (UUID playerUniqueId : playersWatching) {
Player player = Sponge.getServer().getPlayer(playerUniqueId).orElse(null);
if (player != null) {
playerData = this.getOrCreatePlayerData(playerUniqueId);
playerData.revertActiveVisual(player);
if (playerData.lastClaim != null) {
playerData.lastClaim.clear();
}
if (GriefPreventionPlugin.instance.worldEditProvider != null) {
GriefPreventionPlugin.instance.worldEditProvider.revertVisuals(player, playerData, claim.getUniqueId());
}
}
}
DATASTORE.deleteClaimFromSecondaryStorage((GPClaim) claim);
}