本文整理汇总了Java中org.spongepowered.api.item.inventory.Inventory类的典型用法代码示例。如果您正苦于以下问题:Java Inventory类的具体用法?Java Inventory怎么用?Java Inventory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Inventory类属于org.spongepowered.api.item.inventory包,在下文中一共展示了Inventory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
@Override
public void open(Player player, Manager manager) {
PlayerOpenCrateEvent open_event = new PlayerOpenCrateEvent(player, manager);
Sponge.getEventManager().post(open_event);
if (open_event.isCancelled()) return;
Inventory inventory = display_name.map(text -> Inventory.builder().of(InventoryArchetypes.CHEST).
property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(text)).
build(GWMCrates.getInstance())).orElseGet(() -> Inventory.builder().of(InventoryArchetypes.CHEST).
property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, rows)).
build(GWMCrates.getInstance()));
OrderedInventory ordered = Utils.castToOrdered(inventory);
int hidden_item_quantity = hidden_item.getQuantity();
for (int i = 0; i < 9 * rows; i++) {
int quantity = increase_hidden_item_quantity ? i + 1 : hidden_item_quantity;
ItemStack copy = hidden_item.copy();
copy.setQuantity(quantity);
ordered.getSlot(new SlotIndex(i)).get().set(copy);
}
Container container = player.openInventory(inventory).get();
getOpenSound().ifPresent(open_sound -> player.playSound(open_sound, player.getLocation().getPosition(), 1.));
SECOND_GUI_INVENTORIES.put(container, new Pair<SecondOpenManager, Manager>(this, manager));
}
示例2: serializeInventory
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public static List<DataView> serializeInventory(Inventory inventory) {
DataContainer container;
List<DataView> slots = new LinkedList<>();
int i = 0;
Optional<ItemStack> stack;
for (Inventory inv : inventory.slots()) {
stack = inv.peek();
if (stack.isPresent()) {
container = new org.spongepowered.api.data.MemoryDataContainer();
container.set(SLOT, i);
container.set(STACK, serializeItemStack(stack.get()));
slots.add(container);
}
i++;
}
return slots;
}
示例3: 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;
}
示例4: loadStacks
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
private Map<String, String> loadStacks(Player player, Inventory backpack) {
for (SlotPos slotp : this.itemspos) {
if (backpack.query(slotp).size() > 0) {
if (!backpack.query(slotp).peek().get().getItem().equals(ItemTypes.NONE)) {
try {
if (backpack.query(slotp).peek().isPresent()) {
this.items.put(slotp.getX() + "," + slotp.getY(), Tools.ItemStackToBase64(backpack.query(slotp).peek().get()));
}
} catch (Exception e) {
VirtualTool.getInstance().getLogger().error("Failed to load a stack data from inventory for this user: " + player.getName() + " SlotPos: " + slotp.getX() + "X," + slotp.getY() + "Y");
e.printStackTrace();
}
} else {
if (this.items.containsKey(slotp.getX() + "," + slotp.getY())) {
this.items.remove(slotp.getX() + "," + slotp.getY());
}
}
} else {
if (this.items.containsKey(slotp.getX() + "," + slotp.getY())) {
this.items.remove(slotp.getX() + "," + slotp.getY());
}
}
}
return this.items;
}
示例5: performRemoval
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
private void performRemoval(LookupLine line) {
World w = Sponge.getServer().getWorld(line.getWorld()).orElse(null);
if (w == null) return;
if (line.getTarget() instanceof ItemType) {
Optional<TileEntity> te = w.getTileEntity(line.getPos());
if (te.isPresent() && te.get() instanceof TileEntityCarrier) {
TileEntityCarrier c = (TileEntityCarrier) te.get();
Inventory i = c.getInventory();
Inventory slot = i.query(new SlotIndex(line.getSlot()));
slot.set(ItemStack.of(ItemTypes.NONE, 0));
}
} else if (line.getTarget() instanceof BlockType) {
BlockState block = BlockState.builder().blockType(BlockTypes.AIR).build();
w.setBlock(line.getPos(), block, Cause.source(container).build());
}
}
示例6: getAddTrailCommand
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
private static CommandSpec getAddTrailCommand() {
return CommandSpec.builder()
.permission("happytrails.command.add")
.description(Text.of("Adds a new trail"))
.executor((src, args) -> {
if (!(src instanceof Player)) {
return CommandResult.empty();
}
final Inventory creator = Inventory.builder()
.of(InventoryArchetypes.CHEST)
.property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(Text.of(TextColors.AQUA, "Create a Trail")))
.listener(ClickInventoryEvent.Primary.class, (event) -> {
})
.build(HappyTrails.getInstance());
creator.offer(ItemStack.of(ItemTypes.FIREWORKS, 1));
creator.offer(ItemStack.builder().fromBlockState(BlockTypes.REDSTONE_BLOCK.getDefaultState()).build());
((Player) src).openInventory(creator);
return CommandResult.success();
})
.build();
}
示例7: openInventory
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
public static void openInventory(Player player, Inventory inventory, Object causeObj)
{
try
{
if (PLAYER_OPEN_INVENTORY.type().parameterCount() > 2)
{
PLAYER_OPEN_INVENTORY.invoke(player, inventory, createCause(causeObj));
}
else
{
PLAYER_OPEN_INVENTORY.invoke(player, inventory);
}
}
catch (Throwable throwable)
{
throw new UnsupportedOperationException(throwable);
}
}
示例8: setInventory
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
public boolean setInventory(Player player, Inventory inventory, SlotIndex pos)
{
if (!this.plugin.getScriptManager().execute(player, this.requirements))
{
return false;
}
try
{
inventory.set(this.serializer.apply(player, this.serializedStack));
return true;
}
catch (InvalidDataException e)
{
String posString = VirtualChestInventory.slotIndexToKey(pos);
throw new InvalidDataException("Find error when generating item at " + posString, e);
}
}
示例9: trigger
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的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;
}
示例10: serializeInventory
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
private static JsonArray serializeInventory(Inventory inv) {
JsonArray json = new JsonArray();
inv.slots().forEach(slot -> {
Optional<ItemStack> item = slot.peek();
if (item.isPresent()) {
try {
json.add(new JsonPrimitive(SerializationHelper.serialize(item.get())));
} catch (IOException ex) {
InfernoCore.logWarning("Failed to serialize ItemStack from inventory");
ex.printStackTrace();
}
} else {
json.add(JsonNull.INSTANCE);
}
});
return json;
}
示例11: applyContents
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
private void applyContents(Location<World> location, Backpack inv) {
if ( ! location.getTileEntity().isPresent()) {
// re run later
SilkTouch.get().getTaskBuilder().execute(
() -> this.applyContents(location, inv))
.async().delay(20, TimeUnit.MILLISECONDS)
.name("SilkTouch - (backpack) apply contents delay").submit(SilkTouch.get().getPlugin());
return;
}
Chest chest = (Chest) location.getTileEntity().get();
Inventory inventory = chest.getInventory().first();
}
示例12: onItemForge
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
@Listener
public void onItemForge(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
/*if (inventory.getArchetype() == InventoryArchetypes.ANVIL) {
Inventory forgingInputs = inventory.query(InputSlot.class);
PermHandler ph = PermHandler.getInstance();
forgingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();
if (!ph.checkPerm(player, "protectionperms.item.forge." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to forge " + itemId + '!'));
}
}));
}*/
}
示例13: onItemEnchant
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
@Listener
public void onItemEnchant(ClickInventoryEvent event, @Root Player player, @Getter("getTargetInventory") Inventory inventory) {
/*if (inventory.getArchetype() == InventoryArchetypes.ENCHANTING_TABLE) {
Inventory enchantingInputs = inventory.query(InputSlot.class);
enchantingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
String itemId = itemStack.getItem().getType().getId();
itemStack.getValue(Keys.ITEM_ENCHANTMENTS).ifPresent(itemEnchantments -> itemEnchantments.forEach(enchantment -> {
String enchantmentId = enchantment.getEnchantment().getId();
if (!player.hasPermission("protectionperms.item.enchant." + itemId + ".with." + enchantmentId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to enchant " + itemId + " with " + enchantmentId + '!'));
}
}));
}));
}*/
}
示例14: onItemEquip
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
@Listener
public void onItemEquip(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER) {
Inventory equipmentSlots = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentSlot.class));
equipmentSlots.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.equip." + itemId + ".on.self")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemType.getName() + '!'));
}
}));
}
}
示例15: onItemCraft
import org.spongepowered.api.item.inventory.Inventory; //导入依赖的package包/类
@Listener
public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {
Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class));
craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.craft." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!'));
}
}));
}
}