Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package protocolconnect;
- import java.net.InetSocketAddress;
- import java.util.Collections;
- import com.nukkitx.protocol.bedrock.BedrockClient;
- import com.nukkitx.protocol.bedrock.packet.LoginPacket;
- import com.nukkitx.protocol.bedrock.v389.Bedrock_v389;
- import io.netty.util.AsciiString;
- import io.netty.util.internal.ThreadLocalRandom;
- import wode.PacketHandler;
- import wode.ProfileHelper;
- public class Connector {
- public static void connect(String displayname,String ip,int port) {
- InetSocketAddress bindAddress = new InetSocketAddress("0.0.0.0", ThreadLocalRandom.current().nextInt(10000 - 1025) + 1025);
- BedrockClient client = new BedrockClient(bindAddress);
- client.bind().join();
- InetSocketAddress addressToConnect = new InetSocketAddress(ip, port);
- client.connect(addressToConnect).whenComplete((session, throwable) -> {
- if (throwable != null) {
- // Unable to establish connection
- return;
- }
- // Connection established
- // Make sure to set the packet codec version you wish to use before sending out packets
- session.setPacketCodec(Bedrock_v389.V389_CODEC);
- // Add disconnect handler
- session.setPacketHandler(new PacketHandler(session));
- // Now send packets...
- LoginPacket login = new LoginPacket();
- login.setProtocolVersion(389);
- AsciiString[] auth = ProfileHelper.randomAuthData(displayname, ip, port);
- login.setChainData(new AsciiString(auth[0]));
- login.setSkinData(new AsciiString(auth[1]));
- session.setLogging(true);
- //session.sendPacket(login);
- session.sendWrapped(Collections.singleton(login), false);
- }).join(); // Join if you do not want this to be handled asynchronously.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment