Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * * Copyright 2019-2020 github.com/ReflxctionDev
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- import com.github.steveice10.mc.auth.exception.request.RequestException;
- import com.github.steveice10.mc.protocol.MinecraftConstants;
- import com.github.steveice10.mc.protocol.MinecraftProtocol;
- import com.github.steveice10.mc.protocol.data.message.Message;
- import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionPacket;
- import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
- import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
- import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
- import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
- import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
- import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerSpawnPositionPacket;
- import com.github.steveice10.packetlib.Client;
- import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
- import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
- import com.github.steveice10.packetlib.event.session.SessionAdapter;
- import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
- import org.bukkit.ChatColor;
- import java.net.Proxy;
- public class BotTest {
- private static final Proxy PROXY = Proxy.NO_PROXY;
- private static final Proxy AUTH_PROXY = Proxy.NO_PROXY;
- private static final String IP_ADDRESS = "P4c11j.mymcserver.org";
- private static final int PORT = 25565;
- private static double x;
- private static double y;
- private static double z;
- public static void main(String[] args) {
- Client client = login();
- connect(client);
- }
- private static void connect(Client client) {
- client.getSession().addListener(new SessionAdapter() {
- @Override
- public void packetReceived(PacketReceivedEvent event) {
- // System.out.println(event.getPacket().getClass().getSimpleName());
- if (event.getPacket() instanceof ServerJoinGamePacket) {
- System.out.println("Successfully connected to server");
- event.getSession().getPacketProtocol().registerOutgoing(0x0D, ClientPlayerPositionPacket.class);
- } else if (event.getPacket() instanceof ServerChatPacket) {
- Message m = event.<ServerChatPacket>getPacket().getMessage();
- String text = ChatColor.stripColor(m.getFullText());
- System.out.println("Received chat message: " + text);
- } else if (event.getPacket() instanceof ServerSpawnPositionPacket) {
- ServerSpawnPositionPacket sspp = event.getPacket();
- System.out.println("Received position packet: " + sspp);
- x = sspp.getPosition().getX();
- y = sspp.getPosition().getY();
- z = sspp.getPosition().getZ();
- move(client);
- } else if (event.getPacket() instanceof ServerPlayerPositionRotationPacket) {
- client.getSession().send(new ClientTeleportConfirmPacket(((ServerPlayerPositionRotationPacket) event.getPacket()).getTeleportId()));
- }
- }
- @Override
- public void disconnected(DisconnectedEvent event) {
- System.out.println("Disconnected: " + Message.fromString(event.getReason()).getFullText());
- if (event.getCause() != null) {
- event.getCause().printStackTrace();
- }
- }
- });
- client.getSession().connect();
- }
- private static Client login() {
- MinecraftProtocol protocol;
- try {
- protocol = new MinecraftProtocol("username", "pass");
- System.out.println("Successfully authenticated user.");
- } catch (RequestException e) {
- throw new RuntimeException(e);
- }
- Client client = new Client(IP_ADDRESS, PORT, protocol, new TcpSessionFactory(PROXY));
- client.getSession().setFlag(MinecraftConstants.AUTH_PROXY_KEY, AUTH_PROXY);
- return client;
- }
- protected static void move(Client client) {
- Thread t = new Thread(() -> {
- try {
- Thread.sleep(700);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- z += 0.215;
- ClientPlayerPositionRotationPacket packet = new ClientPlayerPositionRotationPacket(true, x, y, z, 0, -90);
- client.getSession().send(packet);
- move(client);
- });
- t.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement