本文整理汇总了Java中org.spongepowered.api.item.inventory.Inventory.offer方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.offer方法的具体用法?Java Inventory.offer怎么用?Java Inventory.offer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.offer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInventory
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public Inventory getInventory() {
Inventory woop = Inventory.builder()
.property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9,1))
.property(InventoryTitle.PROPERTY_NAME,InventoryTitle.of(Text.of(TextColors.DARK_RED,"INVALID CRATE TYPE!")))
.listener(InteractInventoryEvent.class, evt ->{
if(!(evt instanceof InteractInventoryEvent.Open) && !(evt instanceof InteractInventoryEvent.Close)){
evt.setCancelled(true);
}
//System.out.println(evt.getClass());
})
.build(plugin);
woop.offer(ItemStack.of(ItemTypes.BARRIER,256*2 + 64));
for(Inventory e : woop.slots()){
ItemStack b = e.peek().get();
b.setQuantity(1);
e.set(b);
}
return woop;
}
示例2: getFrom
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
/** Tries to take a certain amount of items represented by this item from the inventory
* @param quantity the amount of items supposed to take, overriding the default in item
* @returns the amount of items taken out of the inventory */
public int getFrom(Inventory inv, int quantity) {
int ammountLeft = quantity;
Inventory result = inv.queryAny(item);
for (Inventory s : result.slots()) {
ItemStack onSlot = s.poll(ammountLeft).orElse(null);
if (onSlot == null)continue;
if (onSlot.getQuantity()<=ammountLeft) {
ammountLeft -= onSlot.getQuantity();
} else {
onSlot.setQuantity(onSlot.getQuantity()-ammountLeft);
ammountLeft = 0;
s.offer(onSlot);
}
if (ammountLeft == 0) break;
}
return quantity-ammountLeft;
}
示例3: deserialize
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
@Override
public Inventory deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
Inventory inv = Inventory.builder().build(CarrotShop.getInstance());
ConfigurationNode items = value.getNode("items");
for (ConfigurationNode item : items.getChildrenList()) {
inv.offer(item.getValue(TypeToken.of(ItemStack.class)));
}
return inv;
}
示例4: repair
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public static void repair(final Inventory inventory) {
for (Inventory stack : inventory.slots()){
Optional<ItemStack> item = stack.poll();
if (item.isPresent()) {
stack.offer(UtilsItemStack.repairInventory(item.get()));
}
}
}
示例5: offerTo
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
/** Try to add the represented itemstack to the target inventory without doing any economy changes.
* This function is able to give a fraction of the represented stack size.
* @param quantity the amount of items supposed to give, overriding the default in item
* @returns the amount of given items */
public int offerTo(Inventory inv, int quantity) {
ItemStack copy = item.copy();
copy.setQuantity(quantity);
inv.offer(copy);
int c = copy.getQuantity();
// VillagerShops.l("Rejected "+c);
return quantity-c;
}
示例6: displayCommonMenu
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
private void displayCommonMenu(IActiveCharacter character, Collection<? extends PlayerGroup> g, PlayerGroup default_) {
Inventory i = Inventory.builder()
.of(InventoryArchetypes.DOUBLE_CHEST)
.build(plugin);
for (PlayerGroup cc : g) {
if (cc == default_) {
continue;
}
if (!cc.isShowsInMenu() && !character.getPlayer().hasPermission("ntrpg.admin")) {
continue;
}
i.offer(createItemRepresentingGroup(cc));
}
character.getPlayer().openInventory(i);
}
示例7: giveItems
import org.spongepowered.api.item.inventory.Inventory; //导入方法依赖的package包/类
public static Clause<Boolean, List<Clause<ItemStack, Integer>>> giveItems(Player player, Collection<ItemStack> stacks, Cause cause) {
List<Clause<ItemStack, Integer>> transactions = new ArrayList<>(stacks.size());
List<ItemStackSnapshot> itemBuffer = new ArrayList<>();
itemBuffer.addAll(stacks.stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));
PlayerInventory playerInventory = player.getInventory().query(PlayerInventory.class);
List<Inventory> inventories = new ArrayList<>();
inventories.add(playerInventory.getHotbar());
inventories.add(playerInventory.getMain());
// Loop through replacing empty space with the requested items
for (Inventory inventory : inventories) {
List<ItemStackSnapshot> newBuffer = new ArrayList<>();
for (ItemStackSnapshot snapshot : itemBuffer) {
ItemStack stack = snapshot.createStack();
InventoryTransactionResult result = inventory.offer(stack);
newBuffer.addAll(result.getRejectedItems());
transactions.add(new Clause<>(stack, stack.getQuantity()));
}
itemBuffer = newBuffer;
}
// Drop remaining items
new ItemDropper(player.getLocation()).dropStackSnapshots(itemBuffer, SpawnTypes.PLUGIN);
return new Clause<>(true, transactions);
}
示例8: 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;
}
示例9: 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;
}