Search in sources :

Example 1 with ClientRequestPacket

use of com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket in project CyanBot by XjCyan1de.

the class PacketWorldListener method packetReceived.

@Override
public void packetReceived(PacketReceivedEvent event) {
    try {
        Packet packetHandle = event.getPacket();
        if (packetHandle instanceof ServerJoinGamePacket) {
            ServerJoinGamePacket packet = (ServerJoinGamePacket) packetHandle;
            bot.setEntityId(packet.getEntityId());
        } else if (packetHandle instanceof ServerPlayerPositionRotationPacket) {
            ServerPlayerPositionRotationPacket packet = (ServerPlayerPositionRotationPacket) packetHandle;
            Location location = new Location(packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getPitch());
            bot.setLoc(location);
            // bot.sendMessage("Меня тпхнуло: "+location);
            // System.out.println(" \nТелепортируем : ["+location.getX()+" "+location.getY()+" "+location.getZ()+"]");
            bot.sendPacket(new ClientTeleportConfirmPacket(packet.getTeleportId()));
        // bot.groundHandler.move(location);
        } else if (packetHandle instanceof ServerChunkDataPacket) {
            ServerChunkDataPacket packet = (ServerChunkDataPacket) packetHandle;
            bot.getWorld().onLoadChunk(bot, packet.getColumn());
        } else if (packetHandle instanceof ServerUnloadChunkPacket) {
            ServerUnloadChunkPacket packet = (ServerUnloadChunkPacket) packetHandle;
            bot.getWorld().onUnloadChunk(bot, packet.getX(), packet.getZ());
        } else if (packetHandle instanceof ServerPlayerHealthPacket) {
            ServerPlayerHealthPacket packet = (ServerPlayerHealthPacket) packetHandle;
            if (packet.getHealth() == 0) {
                Schedule.later(() -> {
                    bot.sendPacket(new ClientRequestPacket(ClientRequest.RESPAWN));
                }, 500);
            }
        } else if (packetHandle instanceof ServerBlockChangePacket) {
            ServerBlockChangePacket packet = (ServerBlockChangePacket) packetHandle;
            BlockState blockState = packet.getRecord().getBlock();
            if (blockState != null) {
                Position position = packet.getRecord().getPosition();
                Block block = bot.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
                if (block != null) {
                    block.setIdAndData(blockState.getId(), blockState.getData());
                // System.out.println("Новый блок = " + block);
                } else {
                    System.out.println("Чё за хуйня у нас блок == Null" + position.getX() + " " + position.getY() + " " + position.getZ());
                }
            }
        } else {
        /*if (packetHandle instanceof ServerUpdateTimePacket ||
                        packetHandle instanceof ServerKeepAlivePacket ||
                        packetHandle instanceof ServerPlaySoundPacket ||
                        packetHandle instanceof ServerEntityEffectPacket

                        ) {
                } else {
                    //System.out.println(bot.getUsername()+" <- "+packetHandle);
                }*/
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) Packet(com.github.steveice10.packetlib.packet.Packet) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState) Block(me.xjcyan1de.cyanbot.world.Block) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) Location(me.xjcyan1de.cyanbot.world.Location)

Example 2 with ClientRequestPacket

use of com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket in project DragonProxy by DragonetMC.

the class PEPlayerActionPacketTranslator method translate.

public Packet[] translate(UpstreamSession session, PlayerActionPacket packet) {
    if (packet.action == PlayerActionPacket.ACTION_RESPAWN) {
        return new Packet[] { new ClientRequestPacket(ClientRequest.RESPAWN) };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_SPRINT) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SPRINTING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SPRINT) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SPRINTING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_GLIDE) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_GLIDE) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_ELYTRA_FLYING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_SNEAK) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.START_SNEAKING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SNEAK) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.STOP_SNEAKING);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_STOP_SLEEPING) {
        ClientPlayerStatePacket stat = new ClientPlayerStatePacket((int) session.getDataCache().get(CacheKey.PLAYER_EID), PlayerState.LEAVE_BED);
        return new Packet[] { stat };
    }
    if (packet.action == PlayerActionPacket.ACTION_DROP_ITEM) {
        ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.DROP_ITEM, new Position(0, 0, 0), BlockFace.UP);
        return new Packet[] { act };
    }
    if (packet.action == PlayerActionPacket.ACTION_START_BREAK) {
        ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.START_DIGGING, new Position(packet.position.x, packet.position.y, packet.position.z), MagicValues.key(BlockFace.class, packet.face));
        session.getDataCache().put(CacheKey.BLOCK_BREAKING_POSITION, act.getPosition());
        return new Packet[] { act };
    }
    if (session.getDataCache().containsKey(CacheKey.BLOCK_BREAKING_POSITION)) {
        if (packet.action == PlayerActionPacket.ACTION_STOP_BREAK) {
            ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.FINISH_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
            return new Packet[] { act };
        }
        if (packet.action == PlayerActionPacket.ACTION_ABORT_BREAK) {
            ClientPlayerActionPacket act = new ClientPlayerActionPacket(com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction.CANCEL_DIGGING, (Position) session.getDataCache().remove(CacheKey.BLOCK_BREAKING_POSITION), MagicValues.key(BlockFace.class, packet.face));
            return new Packet[] { act };
        }
    }
    return null;
}
Also used : ClientPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ClientPlayerStatePacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket) PlayerActionPacket(org.dragonet.protocol.packets.PlayerActionPacket) Packet(com.github.steveice10.packetlib.packet.Packet) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) BlockFace(com.github.steveice10.mc.protocol.data.game.world.block.BlockFace) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ClientPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket) ClientPlayerStatePacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket)

Aggregations

Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)2 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)2 Packet (com.github.steveice10.packetlib.packet.Packet)2 BlockFace (com.github.steveice10.mc.protocol.data.game.world.block.BlockFace)1 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)1 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)1 ClientPlayerStatePacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket)1 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)1 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)1 ServerPlayerHealthPacket (com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket)1 ServerPlayerPositionRotationPacket (com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket)1 Block (me.xjcyan1de.cyanbot.world.Block)1 Location (me.xjcyan1de.cyanbot.world.Location)1 PlayerActionPacket (org.dragonet.protocol.packets.PlayerActionPacket)1