Search in sources :

Example 1 with LanternContainer

use of org.lanternpowered.server.inventory.LanternContainer 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)

Example 2 with LanternContainer

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

the class LanternPlayer method pulse.

@Override
public void pulse(int deltaTicks) {
    // Check whether the player is still active
    int timeout = Lantern.getGame().getGlobalConfig().getPlayerIdleTimeout();
    if (timeout > 0 && System.currentTimeMillis() - this.lastActiveTime >= timeout * 60000) {
        this.session.disconnect(t("multiplayer.disconnect.idling"));
        return;
    }
    super.pulse(deltaTicks);
    // TODO: Maybe async?
    pulseChunkChanges();
    // Pulse the interaction handler
    this.interactionHandler.pulse();
    // Stream the inventory updates
    final LanternContainer container = this.containerSession.getOpenContainer();
    (container == null ? this.inventoryContainer : container).tryGetClientContainer(this).update();
    this.resourcePackSendQueue.pulse();
    if (get(LanternKeys.IS_ELYTRA_FLYING).get()) {
        if (get(Keys.IS_SNEAKING).get()) {
            offer(LanternKeys.IS_ELYTRA_FLYING, false);
            offer(LanternKeys.ELYTRA_SPEED_BOOST, false);
        } else {
            offer(LanternKeys.ELYTRA_SPEED_BOOST, get(Keys.IS_SPRINTING).get());
        }
    }
    this.cooldownTracker.process();
    this.advancementsProgress.pulse();
}
Also used : LanternContainer(org.lanternpowered.server.inventory.LanternContainer)

Aggregations

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