com.nukkitx.protocol.bedrock.packet.PlayStatusPacket Java Examples

The following examples show how to use com.nukkitx.protocol.bedrock.packet.PlayStatusPacket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaJoinGameTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ServerJoinGamePacket packet, GeyserSession session) {
    PlayerEntity entity = session.getPlayerEntity();
    entity.setEntityId(packet.getEntityId());

    AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
    bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
    bedrockPacket.setPlayerPermission(PlayerPermission.MEMBER);
    session.sendUpstreamPacket(bedrockPacket);

    PlayStatusPacket playStatus = new PlayStatusPacket();
    playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
    // session.sendPacket(playStatus);

    SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
    playerGameTypePacket.setGamemode(packet.getGameMode().ordinal());
    session.sendUpstreamPacket(playerGameTypePacket);
    session.setGameMode(packet.getGameMode());

    SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
    entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
    entityDataPacket.getMetadata().putAll(entity.getMetadata());
    session.sendUpstreamPacket(entityDataPacket);

    session.setRenderDistance(packet.getViewDistance());

    // We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc
    String locale = session.getClientData().getLanguageCode();
    List<SkinPart> skinParts = Arrays.asList(SkinPart.values());
    ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, Hand.MAIN_HAND);
    session.sendDownstreamPacket(clientSettingsPacket);

    if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) {
        DimensionUtils.switchDimension(session, packet.getDimension());
    }
}
 
Example #2
Source File: BedrockActionTranslator.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void translate(PlayerActionPacket packet, GeyserSession session) {
    Entity entity = session.getPlayerEntity();
    if (entity == null)
        return;

    Vector3i vector = packet.getBlockPosition();
    Position position = new Position(vector.getX(), vector.getY(), vector.getZ());

    switch (packet.getAction()) {
        case RESPAWN:
            // Don't put anything here as respawn is already handled
            // in BedrockRespawnTranslator
            break;
        case START_SWIMMING:
            ClientPlayerStatePacket startSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
            session.sendDownstreamPacket(startSwimPacket);
            break;
        case STOP_SWIMMING:
            ClientPlayerStatePacket stopSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
            session.sendDownstreamPacket(stopSwimPacket);
            break;
        case START_GLIDE:
        case STOP_GLIDE:
            ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
            session.sendDownstreamPacket(glidePacket);
            break;
        case START_SNEAK:
            ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
            session.sendDownstreamPacket(startSneakPacket);
            session.setSneaking(true);
            break;
        case STOP_SNEAK:
            ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SNEAKING);
            session.sendDownstreamPacket(stopSneakPacket);
            session.setSneaking(false);
            break;
        case START_SPRINT:
            ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
            session.sendDownstreamPacket(startSprintPacket);
            session.setSprinting(true);
            break;
        case STOP_SPRINT:
            ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
            session.sendDownstreamPacket(stopSprintPacket);
            session.setSprinting(false);
            break;
        case DROP_ITEM:
            ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
            session.sendDownstreamPacket(dropItemPacket);
            break;
        case STOP_SLEEP:
            ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.LEAVE_BED);
            session.sendDownstreamPacket(stopSleepingPacket);
            break;
        case BLOCK_INTERACT:
            // Handled in BedrockInventoryTransactionTranslator
            break;
        case START_BREAK:
            ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(packet.getBlockPosition().getX(),
                    packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.values()[packet.getFace()]);
            session.sendDownstreamPacket(startBreakingPacket);
            break;
        case CONTINUE_BREAK:
            LevelEventPacket continueBreakPacket = new LevelEventPacket();
            continueBreakPacket.setType(LevelEventType.PUNCH_BLOCK);
            continueBreakPacket.setData(BlockTranslator.getBedrockBlockId(session.getBreakingBlock() == null ? BlockTranslator.AIR : session.getBreakingBlock()));
            continueBreakPacket.setPosition(packet.getBlockPosition().toFloat());
            session.sendUpstreamPacket(continueBreakPacket);
            break;
        case ABORT_BREAK:
            ClientPlayerActionPacket abortBreakingPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, new Position(packet.getBlockPosition().getX(),
                    packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()), BlockFace.DOWN);
            session.sendDownstreamPacket(abortBreakingPacket);
            break;
        case STOP_BREAK:
            // Handled in BedrockInventoryTransactionTranslator
            break;
        case DIMENSION_CHANGE_SUCCESS:
            if (session.getPendingDimSwitches().decrementAndGet() == 0) {
                //sometimes the client doesn't feel like loading
                PlayStatusPacket spawnPacket = new PlayStatusPacket();
                spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
                session.sendUpstreamPacket(spawnPacket);
                entity.updateBedrockAttributes(session);
                session.getEntityCache().updateBossBars();
            }
            break;
        case JUMP:
            session.setJumping(true);
            session.getConnector().getGeneralThreadPool().schedule(() -> {
                session.setJumping(false);
            }, 1, TimeUnit.SECONDS);
            break;
    }
}
 
Example #3
Source File: PlayStatusSerializer_v354.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayStatusPacket packet) {
    buffer.writeInt(packet.getStatus().ordinal());
}
 
Example #4
Source File: PlayStatusSerializer_v354.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, PlayStatusPacket packet) {
    packet.setStatus(Status.values()[buffer.readInt()]);
}
 
Example #5
Source File: PlayStatusSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayStatusPacket packet) {
    buffer.writeInt(packet.getStatus().ordinal());
}
 
Example #6
Source File: PlayStatusSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, PlayStatusPacket packet) {
    packet.setStatus(Status.values()[buffer.readInt()]);
}
 
Example #7
Source File: PlayStatusSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayStatusPacket packet) {
    buffer.writeInt(packet.getStatus().ordinal());
}
 
Example #8
Source File: PlayStatusSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, PlayStatusPacket packet) {
    packet.setStatus(Status.values()[buffer.readInt()]);
}
 
Example #9
Source File: PlayStatusSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayStatusPacket packet) {
    buffer.writeInt(packet.getStatus().ordinal());
}
 
Example #10
Source File: PlayStatusSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, PlayStatusPacket packet) {
    packet.setStatus(Status.values()[buffer.readInt()]);
}
 
Example #11
Source File: PlayStatusSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayStatusPacket packet) {
    buffer.writeInt(packet.getStatus().ordinal());
}
 
Example #12
Source File: PlayStatusSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, PlayStatusPacket packet) {
    packet.setStatus(Status.values()[buffer.readInt()]);
}
 
Example #13
Source File: PlayStatusSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayStatusPacket packet) {
    buffer.writeInt(packet.getStatus().ordinal());
}
 
Example #14
Source File: PlayStatusSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, PlayStatusPacket packet) {
    packet.setStatus(Status.values()[buffer.readInt()]);
}
 
Example #15
Source File: PlayStatusSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayStatusPacket packet) {
    buffer.writeInt(packet.getStatus().ordinal());
}
 
Example #16
Source File: PlayStatusSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, PlayStatusPacket packet) {
    packet.setStatus(Status.values()[buffer.readInt()]);
}