Search in sources :

Example 16 with LanternPlayer

use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.

the class VanillaContainerInteractionBehavior method handleDoubleClick.

@Override
public void handleDoubleClick(ClientContainer clientContainer, ClientSlot clientSlot) {
    final LanternPlayer player = clientContainer.getPlayer();
    if (player != this.container.getPlayerInventory().getCarrier().orElse(null) || !(clientSlot instanceof ClientSlot.Slot)) {
        return;
    }
    final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
    final ItemStackSnapshot oldItem = LanternItemStack.toSnapshot(getCursorItem());
    ItemStackSnapshot newItem = oldItem;
    final List<SlotTransaction> transactions = new ArrayList<>();
    if (getCursorItem() != null && !(slot instanceof OutputSlot)) {
        final ItemStack cursorItem = getCursorItem().copy();
        int quantity = cursorItem.getQuantity();
        final int maxQuantity = cursorItem.getMaxStackQuantity();
        if (quantity < maxQuantity) {
            final AbstractInventory inventory;
            if (clientContainer instanceof PlayerClientContainer) {
                inventory = this.container.getPlayerInventory().getView(LanternPlayerInventory.View.ALL_PRIORITY_MAIN);
            } else {
                inventory = AbstractOrderedInventory.viewBuilder().inventory(this.container.getOpenInventory()).inventory(this.container.getPlayerInventory().getView(LanternPlayerInventory.View.PRIORITY_MAIN_AND_HOTBAR)).build();
            }
            // Try first to get enough unfinished stacks
            PeekedPollTransactionResult peekResult = inventory.peekPoll(maxQuantity - quantity, stack -> stack.getQuantity() < stack.getMaxStackQuantity() && ((LanternItemStack) cursorItem).similarTo(stack)).orElse(null);
            if (peekResult != null) {
                quantity += peekResult.getPolledItem().getQuantity();
                transactions.addAll(peekResult.getTransactions());
            }
            // Get the last items for the stack from a full stack
            if (quantity <= maxQuantity) {
                peekResult = this.container.peekPoll(maxQuantity - quantity, stack -> stack.getQuantity() >= stack.getMaxStackQuantity() && ((LanternItemStack) cursorItem).similarTo(stack)).orElse(null);
                if (peekResult != null) {
                    quantity += peekResult.getPolledItem().getQuantity();
                    transactions.addAll(peekResult.getTransactions());
                }
            }
            cursorItem.setQuantity(quantity);
            newItem = cursorItem.createSnapshot();
        }
    }
    final CauseStack causeStack = CauseStack.current();
    final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(oldItem, newItem);
    final ClickInventoryEvent.Double event = SpongeEventFactory.createClickInventoryEventDouble(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
    finishInventoryEvent(event);
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) MatrixResult(org.lanternpowered.server.item.recipe.crafting.MatrixResult) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) Tuple(org.spongepowered.api.util.Tuple) Streams(com.google.common.collect.Streams) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) World(org.spongepowered.api.world.World) Optional(java.util.Optional) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory) Player(org.spongepowered.api.entity.living.player.Player) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) IInventory(org.lanternpowered.server.inventory.IInventory) Keys(org.spongepowered.api.data.key.Keys) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ArrayList(java.util.ArrayList) CauseStack(org.lanternpowered.server.event.CauseStack) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) LanternWorld(org.lanternpowered.server.world.LanternWorld) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) Nullable(javax.annotation.Nullable) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) LanternEventHelper(org.lanternpowered.server.event.LanternEventHelper) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Slot(org.spongepowered.api.item.inventory.Slot) Entity(org.spongepowered.api.entity.Entity) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) LanternHotbarInventory(org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) CauseStack(org.lanternpowered.server.event.CauseStack) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ArrayList(java.util.ArrayList) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 17 with LanternPlayer

use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.

the class VanillaContainerInteractionBehavior method handleDrag.

@Override
public void handleDrag(ClientContainer clientContainer, List<ClientSlot> clientSlots, MouseButton mouseButton) {
    final LanternPlayer player = clientContainer.getPlayer();
    if (player != this.container.getPlayerInventory().getCarrier().orElse(null)) {
        return;
    }
    final List<AbstractSlot> slots = clientSlots.stream().filter(clientSlot -> clientSlot instanceof ClientSlot.Slot).map(clientSlot -> ((ClientSlot.Slot) clientSlot).getSlot()).collect(Collectors.toList());
    if (slots.size() != clientSlots.size()) {
        // TODO: Is this the behavior we want?
        return;
    }
    final ItemStack cursorItem = getCursorItem();
    if (cursorItem == null || cursorItem.isEmpty()) {
        return;
    }
    final CauseStack causeStack = CauseStack.current();
    if (mouseButton == MouseButton.LEFT) {
        final int quantity = cursorItem.getQuantity();
        final int slotCount = slots.size();
        final int itemsPerSlot = quantity / slotCount;
        final int rest = quantity - itemsPerSlot * slotCount;
        final List<SlotTransaction> transactions = new ArrayList<>();
        for (AbstractSlot slot : slots) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(itemsPerSlot);
            transactions.addAll(slot.peekOffer(itemStack).getTransactions());
        }
        ItemStackSnapshot newCursorItem = ItemStackSnapshot.NONE;
        if (rest > 0) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(rest);
            newCursorItem = LanternItemStackSnapshot.wrap(itemStack);
        }
        final ItemStackSnapshot oldCursorItem = cursorItem.createSnapshot();
        final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(oldCursorItem, newCursorItem);
        final ClickInventoryEvent.Drag.Primary event = SpongeEventFactory.createClickInventoryEventDragPrimary(causeStack.getCurrentCause(), cursorTransaction, this.container, transactions);
        finishInventoryEvent(event);
    } else if (mouseButton == MouseButton.RIGHT) {
        int quantity = cursorItem.getQuantity();
        final int size = Math.min(slots.size(), quantity);
        final List<SlotTransaction> transactions = new ArrayList<>();
        for (AbstractSlot slot : slots) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(1);
            transactions.addAll(slot.peekOffer(itemStack).getTransactions());
        }
        quantity -= size;
        ItemStackSnapshot newCursorItem = ItemStackSnapshot.NONE;
        if (quantity > 0) {
            final ItemStack itemStack = cursorItem.copy();
            itemStack.setQuantity(quantity);
            newCursorItem = LanternItemStackSnapshot.wrap(itemStack);
        }
        final ItemStackSnapshot oldCursorItem = getCursorItem().createSnapshot();
        final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(oldCursorItem, newCursorItem);
        final ClickInventoryEvent.Drag.Secondary event = SpongeEventFactory.createClickInventoryEventDragSecondary(causeStack.getCurrentCause(), cursorTransaction, this.container, this.container.transformSlots(transactions));
        finishInventoryEvent(event);
    } else {
    // TODO: Middle mouse drag mode
    }
}
Also used : EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerInventory) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) CraftingResult(org.spongepowered.api.item.recipe.crafting.CraftingResult) ItemStack(org.spongepowered.api.item.inventory.ItemStack) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) ExtendedCraftingResult(org.lanternpowered.server.item.recipe.crafting.ExtendedCraftingResult) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) MatrixResult(org.lanternpowered.server.item.recipe.crafting.MatrixResult) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) Tuple(org.spongepowered.api.util.Tuple) Streams(com.google.common.collect.Streams) CraftingOutput(org.spongepowered.api.item.inventory.crafting.CraftingOutput) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Lantern(org.lanternpowered.server.game.Lantern) Transform(org.spongepowered.api.entity.Transform) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) ChangeInventoryEvent(org.spongepowered.api.event.item.inventory.ChangeInventoryEvent) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) World(org.spongepowered.api.world.World) Optional(java.util.Optional) AbstractOrderedInventory(org.lanternpowered.server.inventory.AbstractOrderedInventory) Player(org.spongepowered.api.entity.living.player.Player) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) ClientContainer(org.lanternpowered.server.inventory.client.ClientContainer) IInventory(org.lanternpowered.server.inventory.IInventory) Keys(org.spongepowered.api.data.key.Keys) PeekedSetTransactionResult(org.lanternpowered.server.inventory.PeekedSetTransactionResult) GameModes(org.spongepowered.api.entity.living.player.gamemode.GameModes) ArrayList(java.util.ArrayList) CauseStack(org.lanternpowered.server.event.CauseStack) PlayerInventoryContainer(org.lanternpowered.server.inventory.PlayerInventoryContainer) LanternContainer(org.lanternpowered.server.inventory.LanternContainer) PlayerClientContainer(org.lanternpowered.server.inventory.client.PlayerClientContainer) LanternWorld(org.lanternpowered.server.world.LanternWorld) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) Nullable(javax.annotation.Nullable) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) LanternEventHelper(org.lanternpowered.server.event.LanternEventHelper) PeekedPollTransactionResult(org.lanternpowered.server.inventory.PeekedPollTransactionResult) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Slot(org.spongepowered.api.item.inventory.Slot) Entity(org.spongepowered.api.entity.Entity) PeekedOfferTransactionResult(org.lanternpowered.server.inventory.PeekedOfferTransactionResult) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) LanternHotbarInventory(org.lanternpowered.server.inventory.vanilla.LanternHotbarInventory) AbstractInventory(org.lanternpowered.server.inventory.AbstractInventory) CauseStack(org.lanternpowered.server.event.CauseStack) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ArrayList(java.util.ArrayList) ClickInventoryEvent(org.spongepowered.api.event.item.inventory.ClickInventoryEvent) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Transaction(org.spongepowered.api.data.Transaction) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 18 with LanternPlayer

use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.

the class NetworkSession method initPlayer.

/**
 * Initializes the {@link LanternPlayer} instance
 * and spawns it in a world if permitted to join
 * the server.
 */
public void initPlayer() {
    initKeepAliveTask();
    if (this.gameProfile == null) {
        throw new IllegalStateException("The game profile must first be available!");
    }
    this.player = new LanternPlayer(this.gameProfile, this);
    this.player.setNetworkId(EntityProtocolManager.acquireEntityId());
    this.player.setEntityProtocolType(EntityProtocolTypes.PLAYER);
    LanternWorld world = this.player.getWorld();
    if (world == null) {
        LanternWorldProperties worldProperties = this.player.getUserWorld();
        boolean fixSpawnLocation = false;
        if (worldProperties == null) {
            Lantern.getLogger().warn("The player [{}] attempted to login in a non-existent world, this is not possible " + "so we have moved them to the default's world spawn point.", this.gameProfile.getName().get());
            worldProperties = (LanternWorldProperties) Lantern.getServer().getDefaultWorld().get();
            fixSpawnLocation = true;
        } else if (!worldProperties.isEnabled()) {
            Lantern.getLogger().warn("The player [{}] attempted to login in a unloaded and not-enabled world [{}], this is not possible " + "so we have moved them to the default's world spawn point.", this.gameProfile.getName().get(), worldProperties.getWorldName());
            worldProperties = (LanternWorldProperties) Lantern.getServer().getDefaultWorld().get();
            fixSpawnLocation = true;
        }
        final Optional<World> optWorld = Lantern.getWorldManager().loadWorld(worldProperties);
        // Use the raw method to avoid triggering any network messages
        this.player.setRawWorld((LanternWorld) optWorld.get());
        this.player.setUserWorld(null);
        if (fixSpawnLocation) {
            // TODO: Use a proper spawn position
            this.player.setRawPosition(new Vector3d(0, 100, 0));
            this.player.setRawRotation(new Vector3d(0, 0, 0));
        }
    }
    // The kick reason
    Text kickReason = null;
    final BanService banService = Sponge.getServiceManager().provideUnchecked(BanService.class);
    // Check whether the player is banned and kick if necessary
    Ban ban = banService.getBanFor(this.gameProfile).orElse(null);
    if (ban == null) {
        final SocketAddress address = getChannel().remoteAddress();
        if (address instanceof InetSocketAddress) {
            ban = banService.getBanFor(((InetSocketAddress) address).getAddress()).orElse(null);
        }
    }
    if (ban != null) {
        final Optional<Instant> optExpirationDate = ban.getExpirationDate();
        final Optional<Text> optReason = ban.getReason();
        // Generate the kick message
        Text.Builder builder = Text.builder();
        if (ban instanceof Ban.Profile) {
            builder.append(t("multiplayer.disconnect.ban.banned"));
        } else {
            builder.append(t("multiplayer.disconnect.ban.ip_banned"));
        }
        // There is optionally a reason
        optReason.ifPresent(reason -> builder.append(Text.NEW_LINE).append(t("multiplayer.disconnect.ban.reason", reason)));
        // And a expiration date if present
        optExpirationDate.ifPresent(expirationDate -> {
            final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(tr("multiplayer.disconnect.ban.expiration_date_format").get());
            builder.append(Text.NEW_LINE).append(t("multiplayer.disconnect.ban.expiration", formatter.format(expirationDate)));
        });
        kickReason = builder.build();
    // Check for white-list
    } else if (!isWhitelisted(this.gameProfile)) {
        kickReason = t("multiplayer.disconnect.not_whitelisted");
    // Check whether the server is full
    } else if (Lantern.getServer().getOnlinePlayers().size() >= Lantern.getServer().getMaxPlayers() && !canBypassPlayerLimit(this.gameProfile)) {
        kickReason = t("multiplayer.disconnect.server_full");
    }
    final MessageEvent.MessageFormatter messageFormatter = new MessageEvent.MessageFormatter(kickReason != null ? kickReason : t("multiplayer.disconnect.not_allowed_to_join"));
    final Cause cause = Cause.builder().append(this).build(EventContext.builder().add(EventContextKeys.PLAYER, this.player).build());
    final Transform<World> fromTransform = this.player.getTransform();
    final ClientConnectionEvent.Login loginEvent = SpongeEventFactory.createClientConnectionEventLogin(cause, fromTransform, fromTransform, this, messageFormatter, this.gameProfile, this.player, false);
    if (kickReason != null) {
        loginEvent.setCancelled(true);
    }
    Sponge.getEventManager().post(loginEvent);
    if (loginEvent.isCancelled()) {
        disconnect(loginEvent.isMessageCancelled() ? t("multiplayer.disconnect.generic") : loginEvent.getMessage());
        return;
    }
    Lantern.getLogger().debug("The player {} successfully to joined from {}.", this.gameProfile.getName().get(), this.channel.remoteAddress());
    // Update the first join and last played data
    final Instant lastJoined = Instant.now();
    this.player.offer(Keys.LAST_DATE_PLAYED, lastJoined);
    if (!this.player.get(Keys.FIRST_DATE_PLAYED).isPresent()) {
        this.player.offer(Keys.FIRST_DATE_PLAYED, lastJoined);
    }
    final Transform<World> toTransform = loginEvent.getToTransform();
    world = (LanternWorld) toTransform.getExtent();
    final WorldConfig config = world.getProperties().getConfig();
    // Update the game mode if necessary
    if (config.isGameModeForced() || this.player.get(Keys.GAME_MODE).get().equals(GameModes.NOT_SET)) {
        this.player.offer(Keys.GAME_MODE, config.getGameMode());
    }
    // Reset the raw world
    this.player.setRawWorld(null);
    // Set the transform, this will trigger the initial
    // network messages to be send
    this.player.setTransform(toTransform);
    final MessageChannel messageChannel = this.player.getMessageChannel();
    final Text joinMessage;
    final GameProfile previousProfile = this.channel.attr(PREVIOUS_GAME_PROFILE).getAndSet(null);
    if (previousProfile != null && previousProfile.getName().isPresent() && !previousProfile.getName().get().equals(this.gameProfile.getName().get())) {
        joinMessage = t("multiplayer.player.joined.renamed", this.player.getName(), previousProfile.getName().get());
    } else {
        joinMessage = t("multiplayer.player.joined", this.player.getName());
    }
    final ClientConnectionEvent.Join joinEvent = SpongeEventFactory.createClientConnectionEventJoin(cause, messageChannel, Optional.of(messageChannel), new MessageEvent.MessageFormatter(joinMessage), this.player, false);
    Sponge.getEventManager().post(joinEvent);
    if (!joinEvent.isMessageCancelled()) {
        joinEvent.getChannel().ifPresent(channel -> channel.send(this.player, joinEvent.getMessage()));
    }
    this.server.getDefaultResourcePack().ifPresent(this.player::sendResourcePack);
    this.player.resetIdleTimeoutCounter();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) MessageEvent(org.spongepowered.api.event.message.MessageEvent) WorldConfig(org.lanternpowered.server.config.world.WorldConfig) LanternWorld(org.lanternpowered.server.world.LanternWorld) World(org.spongepowered.api.world.World) LanternWorld(org.lanternpowered.server.world.LanternWorld) GameProfile(org.spongepowered.api.profile.GameProfile) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) Cause(org.spongepowered.api.event.cause.Cause) BanService(org.spongepowered.api.service.ban.BanService) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) LanternWorldProperties(org.lanternpowered.server.world.LanternWorldProperties) Instant(java.time.Instant) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Text(org.spongepowered.api.text.Text) Ban(org.spongepowered.api.util.ban.Ban) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) Vector3d(com.flowpowered.math.vector.Vector3d) GameProfile(org.spongepowered.api.profile.GameProfile) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) DateTimeFormatter(java.time.format.DateTimeFormatter) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 19 with LanternPlayer

use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.

the class HandlerPlayInUseEntityInteract method handle.

@Override
public void handle(NetworkContext context, MessagePlayInUseEntity.Interact message) {
    final LanternPlayer player = context.getSession().getPlayer();
    player.getWorld().getEntityProtocolManager().playerInteract(player, message.getEntityId(), message.getPosition().orElse(null));
}
Also used : LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 20 with LanternPlayer

use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.

the class HandlerPlayInPlayerOnGroundState method handle.

@Override
public void handle(NetworkContext context, MessagePlayInPlayerOnGroundState message) {
    final LanternPlayer player = context.getSession().getPlayer();
    player.handleOnGroundState(message.isOnGround());
}
Also used : LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Aggregations

LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)48 ArrayList (java.util.ArrayList)13 CauseStack (org.lanternpowered.server.event.CauseStack)12 AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)11 ItemStack (org.spongepowered.api.item.inventory.ItemStack)11 World (org.spongepowered.api.world.World)11 Optional (java.util.Optional)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Nullable (javax.annotation.Nullable)9 Sponge (org.spongepowered.api.Sponge)9 SlotTransaction (org.spongepowered.api.item.inventory.transaction.SlotTransaction)9 Lantern (org.lanternpowered.server.game.Lantern)8 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)8 Player (org.spongepowered.api.entity.living.player.Player)8 ChangeInventoryEvent (org.spongepowered.api.event.item.inventory.ChangeInventoryEvent)8 AbstractInventory (org.lanternpowered.server.inventory.AbstractInventory)7 PlayerInventoryContainer (org.lanternpowered.server.inventory.PlayerInventoryContainer)7 ClientContainer (org.lanternpowered.server.inventory.client.ClientContainer)7