Search in sources :

Example 1 with AbstractOrderedInventory

use of org.lanternpowered.server.inventory.AbstractOrderedInventory in project LanternServer by LanternPowered.

the class LanternPlayer method openInventory.

@Override
public Optional<Container> openInventory(Inventory inventory) {
    checkNotNull(inventory, "inventory");
    final LanternContainer container;
    if (inventory instanceof LanternContainer) {
        // You cannot open a player inventory container
        if (inventory instanceof PlayerInventoryContainer) {
            return Optional.empty();
        }
        container = (LanternContainer) inventory;
    } else {
        inventory.getInventoryProperty(GuiIdProperty.class).map(GuiIdProperty::getValue).orElseThrow(() -> new UnsupportedOperationException("Unsupported inventory type: " + inventory.getArchetype().getId()));
        container = LanternContainer.construct(this.inventory, (AbstractOrderedInventory) inventory);
    }
    if (this.containerSession.setOpenContainer(container)) {
        return Optional.of(container);
    }
    return Optional.empty();
}
Also used : LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory)

Aggregations

AbstractOrderedInventory (org.lanternpowered.server.inventory.AbstractOrderedInventory)1 LanternContainer (org.lanternpowered.server.inventory.LanternContainer)1 PlayerInventoryContainer (org.lanternpowered.server.inventory.PlayerInventoryContainer)1