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


Java Inventory.totalItems方法代码示例

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


在下文中一共展示了Inventory.totalItems方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: aSell

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public aSell(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.admin.asell"))
		throw new ExceptionInInitializerError("You don't have perms to build an aSell sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("Sell signs require a chest");
	Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
	if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
		throw new ExceptionInInitializerError("Sell signs require a chest");
	Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
	if (items.totalItems() == 0)
		throw new ExceptionInInitializerError("chest cannot be empty");
	price = getPrice(sign);
	if (price < 0)
		throw new ExceptionInInitializerError("bad price");
	sellerChest = locations.peek();
	itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
	for(Inventory item : items.slots()) {
		if (item.peek().isPresent())
			itemsTemplate.offer(item.peek().get());
	}

	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an aSell shop:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:29,代码来源:aSell.java

示例3: hasEnough

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
static public boolean hasEnough(Inventory inventory, Inventory needs) {
	for (Inventory item : needs.slots()) {
		if (item.peek().isPresent()) {
			Optional<ItemStack> template = getTemplate(inventory, item.peek().get());
			if (!template.isPresent() || inventory.query(template.get()).totalItems() < item.totalItems())
				return false;
		}
	}
	return true;
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:11,代码来源:Shop.java

示例4: Buy

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public Buy(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.create.buy"))
		throw new ExceptionInInitializerError("You don't have perms to build a Buy sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("Buy signs require a chest");
	Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
	if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
		throw new ExceptionInInitializerError("Buy signs require a chest");
	Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
	if (items.totalItems() == 0)
		throw new ExceptionInInitializerError("chest cannot be empty");
	price = getPrice(sign);
	if (price < 0)
		throw new ExceptionInInitializerError("bad price");
	sellerChest = locations.peek();
	itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
	for(Inventory item : items.slots()) {
		if (item.peek().isPresent())
			itemsTemplate.offer(item.peek().get());
	}
	setOwner(player);
	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup a Buy shop:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:29,代码来源:Buy.java

示例5: aBuy

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public aBuy(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.admin.abuy"))
		throw new ExceptionInInitializerError("You don't have perms to build an aBuy sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("aBuy signs require a chest");
	Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
	if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
		throw new ExceptionInInitializerError("aBuy signs require a chest");
	Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
	if (items.totalItems() == 0)
		throw new ExceptionInInitializerError("chest cannot be empty");
	price = getPrice(sign);
	if (price < 0)
		throw new ExceptionInInitializerError("bad price");
	sellerChest = locations.peek();
	itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
	for(Inventory item : items.slots()) {
		if (item.peek().isPresent())
			itemsTemplate.offer(item.peek().get());
	}
	
	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an aBuy shop:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:29,代码来源:aBuy.java

示例6: iBuy

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public iBuy(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.admin.ibuy"))
		throw new ExceptionInInitializerError("You don't have perms to build an iTrade sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("Buy signs require a chest");
	Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
	if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
		throw new ExceptionInInitializerError("Buy signs require a chest");
	Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
	if (items.totalItems() == 0)
		throw new ExceptionInInitializerError("chest cannot be empty");
	price = getPrice(sign);
	if (price < 0)
		throw new ExceptionInInitializerError("bad price");
	itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
	for(Inventory item : items.slots()) {
		if (item.peek().isPresent())
			itemsTemplate.offer(item.peek().get());
	}

	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an iBuy shop:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:28,代码来源:iBuy.java

示例7: iSell

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public iSell(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.admin.isell"))
		throw new ExceptionInInitializerError("You don't have perms to build an iTrade sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("iSell signs require a chest");
	Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
	if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
		throw new ExceptionInInitializerError("iSell signs require a chest");
	Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
	if (items.totalItems() == 0)
		throw new ExceptionInInitializerError("chest cannot be empty");
	price = getPrice(sign);
	if (price < 0)
		throw new ExceptionInInitializerError("bad price");
	itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
	for(Inventory item : items.slots()) {
		if (item.peek().isPresent())
			itemsTemplate.offer(item.peek().get());
	}

	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup an iSell shop:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:28,代码来源:iSell.java

示例8: Sell

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public Sell(Player player, Location<World> sign) throws ExceptionInInitializerError {
	super(sign);
	if (!player.hasPermission("carrotshop.create.sell"))
		throw new ExceptionInInitializerError("You don't have perms to build a Sell sign");
	Stack<Location<World>> locations = ShopsData.getItemLocations(player);
	if (locations.isEmpty())
		throw new ExceptionInInitializerError("Sell signs require a chest");
	Optional<TileEntity> chestOpt = locations.peek().getTileEntity();
	if (!chestOpt.isPresent() || !(chestOpt.get() instanceof TileEntityCarrier))
		throw new ExceptionInInitializerError("Sell signs require a chest");
	Inventory items = ((TileEntityCarrier) chestOpt.get()).getInventory();
	if (items.totalItems() == 0)
		throw new ExceptionInInitializerError("chest cannot be empty");
	price = getPrice(sign);
	if (price < 0)
		throw new ExceptionInInitializerError("bad price");
	sellerChest = locations.peek();
	itemsTemplate = Inventory.builder().from(items).build(CarrotShop.getInstance());
	for(Inventory item : items.slots()) {
		if (item.peek().isPresent())
			itemsTemplate.offer(item.peek().get());
	}
	setOwner(player);
	ShopsData.clearItemLocations(player);
	player.sendMessage(Text.of(TextColors.DARK_GREEN, "You have setup a Sell shop:"));
	done(player);
	info(player);
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:29,代码来源:Sell.java

示例9: updateStock

import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public void updateStock(Inventory container) {
	Inventory result = container.queryAny(item);
	int count = 0;
	for (Inventory s : result.slots()) count += s.totalItems();
	stocked = Math.min(maxStock, count);
}
 
开发者ID:DosMike,项目名称:VillagerShops,代码行数:7,代码来源:StockItem.java


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