Search in sources :

Example 11 with LanternWorld

use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.

the class NetworkSession method leavePlayer.

/**
 * Is called when the {@link LanternPlayer} leaves the
 * server and needs to be cleaned up.
 */
private void leavePlayer() {
    checkState(this.player != null, "The player must first be available!");
    final LanternWorld world = this.player.getWorld();
    if (world != null) {
        final CauseStack causeStack = CauseStack.current();
        causeStack.pushCause(this.player);
        // Close the open container
        this.player.getContainerSession().setRawOpenContainer(causeStack, null);
        final MessageChannel messageChannel = this.player.getMessageChannel();
        final Text quitMessage = t("multiplayer.player.left", this.player.getName());
        final ClientConnectionEvent.Disconnect event = SpongeEventFactory.createClientConnectionEventDisconnect(causeStack.getCurrentCause(), messageChannel, Optional.of(messageChannel), new MessageEvent.MessageFormatter(quitMessage), this.player, false);
        Sponge.getEventManager().post(event);
        if (!event.isMessageCancelled()) {
            event.getChannel().ifPresent(channel -> channel.send(this.player, event.getMessage()));
        }
        causeStack.popCause();
        // Remove the proxy user from the player and save the player data
        this.player.getProxyUser().setInternalUser(null);
        // Destroy the player entity
        this.player.remove(LanternEntity.RemoveState.DESTROYED);
        // Detach the player from the world
        this.player.setWorld(null);
        // Release the players entity id
        EntityProtocolManager.releaseEntityId(this.player.getNetworkId());
    }
}
Also used : CauseStack(org.lanternpowered.server.event.CauseStack) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageEvent(org.spongepowered.api.event.message.MessageEvent) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) LanternWorld(org.lanternpowered.server.world.LanternWorld) Text(org.spongepowered.api.text.Text)

Example 12 with LanternWorld

use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.

the class LanternPlayer method setRotation.

@Override
public void setRotation(Vector3d rotation) {
    super.setRotation(rotation);
    final LanternWorld world = getWorld();
    if (world != null) {
        this.session.send(new MessagePlayOutPlayerPositionAndLook(0, 0, 0, (float) rotation.getX(), (float) rotation.getY(), RELATIVE_POSITION, 0));
    }
}
Also used : LanternWorld(org.lanternpowered.server.world.LanternWorld) MessagePlayOutPlayerPositionAndLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerPositionAndLook)

Example 13 with LanternWorld

use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.

the class LanternPlayer method resetBlockChange.

@Override
public void resetBlockChange(Vector3i position) {
    checkNotNull(position, "position");
    LanternWorld world = this.getWorld();
    if (world == null) {
        return;
    }
    this.session.send(new MessagePlayOutBlockChange(position, BlockRegistryModule.get().getStateInternalIdAndData(world.getBlock(position))));
}
Also used : MessagePlayOutBlockChange(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutBlockChange) LanternWorld(org.lanternpowered.server.world.LanternWorld)

Example 14 with LanternWorld

use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.

the class LanternPlayer method setPosition.

@Override
public void setPosition(Vector3d position) {
    super.setPosition(position);
    final LanternWorld world = getWorld();
    if (world != null) {
        this.session.send(new MessagePlayOutPlayerPositionAndLook(position.getX(), position.getY(), position.getZ(), 0, 0, RELATIVE_ROTATION, 0));
    }
}
Also used : LanternWorld(org.lanternpowered.server.world.LanternWorld) MessagePlayOutPlayerPositionAndLook(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerPositionAndLook)

Example 15 with LanternWorld

use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.

the class UserStore method deserialize.

@Override
public void deserialize(T player, DataView dataView) {
    super.deserialize(player, dataView);
    final int dimension = dataView.getInt(DIMENSION).orElse(0);
    Lantern.getWorldManager().getWorldProperties(dimension).ifPresent(worldProperties -> {
        final LanternWorldProperties worldProperties0 = (LanternWorldProperties) worldProperties;
        final Optional<LanternWorld> optWorld = worldProperties0.getWorld();
        if (optWorld.isPresent()) {
            player.setRawWorld(optWorld.get());
        } else {
            player.setUserWorld(worldProperties0);
        }
    });
}
Also used : LanternWorld(org.lanternpowered.server.world.LanternWorld) LanternWorldProperties(org.lanternpowered.server.world.LanternWorldProperties)

Aggregations

LanternWorld (org.lanternpowered.server.world.LanternWorld)20 World (org.spongepowered.api.world.World)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 MessagePlayOutPlayerPositionAndLook (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutPlayerPositionAndLook)3 Text (org.spongepowered.api.text.Text)3 ArrayList (java.util.ArrayList)2 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)2 CauseStack (org.lanternpowered.server.event.CauseStack)2 LanternWorldProperties (org.lanternpowered.server.world.LanternWorldProperties)2 Vector2i (com.flowpowered.math.vector.Vector2i)1 Vector3f (com.flowpowered.math.vector.Vector3f)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 Instant (java.time.Instant)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1