Search in sources :

Example 21 with AbstractSlot

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

the class HandlerPlayInEditBook method handle.

@Override
public void handle(NetworkContext context, MessagePlayInEditBook message) {
    final LanternPlayer player = context.getSession().getPlayer();
    final AbstractSlot slot = player.getInventory().getHotbar().getSelectedSlot();
    final ItemStack itemStack = slot.peek().orElse(null);
    if (itemStack != null && itemStack.getType() == ItemTypes.WRITABLE_BOOK) {
        itemStack.offer(Keys.BOOK_PAGES, message.getPages().stream().map(Text::of).collect(Collectors.toList()));
        slot.set(itemStack);
    }
}
Also used : AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Aggregations

AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)21 ItemStack (org.spongepowered.api.item.inventory.ItemStack)15 CauseStack (org.lanternpowered.server.event.CauseStack)12 ArrayList (java.util.ArrayList)10 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)10 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)9 SlotTransaction (org.spongepowered.api.item.inventory.transaction.SlotTransaction)9 Optional (java.util.Optional)8 Nullable (javax.annotation.Nullable)8 Lantern (org.lanternpowered.server.game.Lantern)8 LanternWorld (org.lanternpowered.server.world.LanternWorld)8 Keys (org.spongepowered.api.data.key.Keys)8 EventContextKeys (org.spongepowered.api.event.cause.EventContextKeys)8 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)8 World (org.spongepowered.api.world.World)8 LanternItemStackSnapshot (org.lanternpowered.server.inventory.LanternItemStackSnapshot)7 PlayerInventoryContainer (org.lanternpowered.server.inventory.PlayerInventoryContainer)7 ClientSlot (org.lanternpowered.server.inventory.client.ClientSlot)7 LanternPlayerInventory (org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory)7 ChangeInventoryEvent (org.spongepowered.api.event.item.inventory.ChangeInventoryEvent)7