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();
}
}
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;
}
Aggregations