Search in sources :

Example 1 with ServerPlaySoundPacket

use of com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket 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 ServerPlaySoundPacket

use of com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket in project DragonProxy by DragonetMC.

the class PCPlaySoundPacketTranslator method translate.

public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) {
    try {
        String soundName;
        if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) {
            BuiltinSound sound = (BuiltinSound) packet.getSound();
            soundName = sound.name();
        } else {
            soundName = ((CustomSound) packet.getSound()).getName();
        }
        if (soundName == null) {
            return null;
        }
        PlaySoundPacket pk = new PlaySoundPacket();
        pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
        pk.name = soundName;
        pk.volume = packet.getVolume();
        pk.pitch = packet.getPitch();
        return new PEPacket[] { pk };
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : BlockPosition(org.dragonet.common.maths.BlockPosition) PEPacket(org.dragonet.protocol.PEPacket) BuiltinSound(com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound) PlaySoundPacket(org.dragonet.protocol.packets.PlaySoundPacket) ServerPlaySoundPacket(com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)

Aggregations

Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)1 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)1 BuiltinSound (com.github.steveice10.mc.protocol.data.game.world.sound.BuiltinSound)1 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)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 ServerPlaySoundPacket (com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket)1 Packet (com.github.steveice10.packetlib.packet.Packet)1 Block (me.xjcyan1de.cyanbot.world.Block)1 Location (me.xjcyan1de.cyanbot.world.Location)1 BlockPosition (org.dragonet.common.maths.BlockPosition)1 PEPacket (org.dragonet.protocol.PEPacket)1 PlaySoundPacket (org.dragonet.protocol.packets.PlaySoundPacket)1