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


Java Inventory.capacity方法代码示例

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


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

示例1: CachedInventory

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public CachedInventory(Inventory inv) {
    super(inv, false);

    this.name = inv.getName().get();
    this.capacity = inv.capacity();
    this.totalItems = inv.totalItems();
    this.type = new CachedCatalogType(inv.getArchetype());

    items = new ArrayList<>();
    try {
        for (Inventory subInv : inv.slots()) {
            Slot slot = (Slot) subInv;
            Optional<ItemStack> optItem = slot.peek();
            optItem.ifPresent(itemStack -> items.add(itemStack.copy()));
        }
    } catch (AbstractMethodError ignored) {}
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:18,代码来源:CachedInventory.java

示例2: update

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public boolean update() {
	Optional<TileEntity> chest = toGiveChest.getTileEntity();
	if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
		if (!hasEnough(((TileEntityCarrier) chest.get()).getInventory(), toGive)) {
			setFail();
			return false;
		}
	} else {
		setFail();
		return false;
	}
	chest = toTakeChest.getTileEntity();
	if (chest.isPresent() && chest.get() instanceof TileEntityCarrier) {
		Inventory chestInv = ((TileEntityCarrier) chest.get()).getInventory();
		if (chestInv.capacity() - chestInv.size() < toTake.size()) {
			setFail();
			return false;
		}
	} else {
		setFail();
		return false;
	}

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

示例3: update

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public boolean update() {
	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()) {
			setOK();
			return true;
		}
	}
	setFail();
	return false;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:14,代码来源:aSell.java

示例4: trigger

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的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;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:60,代码来源:aSell.java

示例5: trigger

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的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;
		}
	}

	UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(getOwner()).get();
	if (buyerAccount.getBalance(getCurrency()).compareTo(BigDecimal.valueOf(price)) < 0) {
		player.sendMessage(Text.of(TextColors.DARK_RED, "Shop owner don't have enough money!"));
		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 = buyerAccount.transfer(sellerAccount, getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
	if (result.getResult() != ResultType.SUCCESS) {
		player.sendMessage(Text.of(TextColors.DARK_RED, "Shop owner don't have enough 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;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:66,代码来源:Sell.java


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