use of com.github.steveice10.packetlib.event.session.PacketReceivedEvent 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.packetlib.event.session.PacketReceivedEvent in project CyanBot by XjCyan1de.
the class ChatToGuiListener method onReceived.
@Override
public void onReceived(PacketReceivedEvent event) {
final ServerChatPacket packet = event.getPacket();
if (packet.getType() == MessageType.CHAT || packet.getType() == MessageType.SYSTEM) {
final String message = packet.getMessage().getFullText();
if (!chatMessageChache.contains(message)) {
chatMessageChache.add(message);
mainFrame.getChat().append(message + "\n");
mainFrame.getChat().setCaretPosition(mainFrame.getChat().getDocument().getLength());
Schedule.later(() -> chatMessageChache.remove(message), 3000);
}
}
}
use of com.github.steveice10.packetlib.event.session.PacketReceivedEvent in project DragonProxy by DragonetMC.
the class PCDownstreamSession method connect.
public void connect(String addr, int port) {
if (this.protocol == null) {
// Clear the flags
upstream.onConnected();
upstream.disconnect("ERROR! ");
return;
}
remoteClient = new Client(addr, port, protocol, new TcpSessionFactory());
remoteClient.getSession().setConnectTimeout(5);
remoteClient.getSession().setReadTimeout(5);
remoteClient.getSession().setWriteTimeout(5);
remoteClient.getSession().addListener(new SessionAdapter() {
@Override
public void connected(ConnectedEvent event) {
proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_REMOTE_CONNECTED, upstream.getUsername(), upstream.getRemoteAddress()));
upstream.onConnected();
}
@Override
public void packetSending(PacketSendingEvent event) {
if (proxy.getAuthMode().equalsIgnoreCase("hybrid")) {
if (protocol.getSubProtocol() == SubProtocol.HANDSHAKE && event.getPacket() instanceof HandshakePacket) {
HandshakePacket packet = event.getPacket();
String host = remoteClient.getSession().getHost() + "\0" + upstream.getProfile().getChainJWT();
packet = new HandshakePacket(packet.getProtocolVersion(), host, packet.getPort(), packet.getIntent());
event.setPacket(packet);
}
}
}
@Override
public void disconnected(DisconnectedEvent event) {
System.out.println("DisconnectedEvent " + event.getCause() + " " + event.getReason());
upstream.disconnect(proxy.getLang().get(event.getReason()));
}
@Override
public void disconnecting(DisconnectingEvent event) {
System.out.println("DisconnectingEvent " + event.getCause() + " " + event.getReason());
upstream.disconnect(proxy.getLang().get(event.getReason()));
}
@Override
public void packetReceived(PacketReceivedEvent event) {
// Handle the packet
try {
PEPacket[] packets = PacketTranslatorRegister.translateToPE(upstream, event.getPacket());
if (packets == null) {
return;
}
if (packets.length <= 0) {
return;
}
if (packets.length == 1) {
upstream.sendPacket(packets[0]);
} else {
upstream.sendAllPackets(packets, false);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
});
remoteClient.getSession().connect();
}
Aggregations