Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. /*
  2. * * Copyright 2019-2020 github.com/ReflxctionDev
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. import com.github.steveice10.mc.auth.exception.request.RequestException;
  18. import com.github.steveice10.mc.protocol.MinecraftConstants;
  19. import com.github.steveice10.mc.protocol.MinecraftProtocol;
  20. import com.github.steveice10.mc.protocol.data.message.Message;
  21. import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionPacket;
  22. import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
  23. import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
  24. import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
  25. import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
  26. import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
  27. import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerSpawnPositionPacket;
  28. import com.github.steveice10.packetlib.Client;
  29. import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
  30. import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
  31. import com.github.steveice10.packetlib.event.session.SessionAdapter;
  32. import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
  33. import org.bukkit.ChatColor;
  34.  
  35. import java.net.Proxy;
  36.  
  37. public class BotTest {
  38.  
  39. private static final Proxy PROXY = Proxy.NO_PROXY;
  40. private static final Proxy AUTH_PROXY = Proxy.NO_PROXY;
  41.  
  42. private static final String IP_ADDRESS = "P4c11j.mymcserver.org";
  43. private static final int PORT = 25565;
  44.  
  45. private static double x;
  46. private static double y;
  47. private static double z;
  48.  
  49. public static void main(String[] args) {
  50. Client client = login();
  51. connect(client);
  52. }
  53.  
  54. private static void connect(Client client) {
  55. client.getSession().addListener(new SessionAdapter() {
  56. @Override
  57. public void packetReceived(PacketReceivedEvent event) {
  58. // System.out.println(event.getPacket().getClass().getSimpleName());
  59. if (event.getPacket() instanceof ServerJoinGamePacket) {
  60. System.out.println("Successfully connected to server");
  61. event.getSession().getPacketProtocol().registerOutgoing(0x0D, ClientPlayerPositionPacket.class);
  62.  
  63. } else if (event.getPacket() instanceof ServerChatPacket) {
  64. Message m = event.<ServerChatPacket>getPacket().getMessage();
  65. String text = ChatColor.stripColor(m.getFullText());
  66. System.out.println("Received chat message: " + text);
  67. } else if (event.getPacket() instanceof ServerSpawnPositionPacket) {
  68. ServerSpawnPositionPacket sspp = event.getPacket();
  69. System.out.println("Received position packet: " + sspp);
  70. x = sspp.getPosition().getX();
  71. y = sspp.getPosition().getY();
  72. z = sspp.getPosition().getZ();
  73. move(client);
  74. } else if (event.getPacket() instanceof ServerPlayerPositionRotationPacket) {
  75. client.getSession().send(new ClientTeleportConfirmPacket(((ServerPlayerPositionRotationPacket) event.getPacket()).getTeleportId()));
  76. }
  77. }
  78.  
  79. @Override
  80. public void disconnected(DisconnectedEvent event) {
  81. System.out.println("Disconnected: " + Message.fromString(event.getReason()).getFullText());
  82. if (event.getCause() != null) {
  83. event.getCause().printStackTrace();
  84. }
  85. }
  86. });
  87. client.getSession().connect();
  88. }
  89.  
  90. private static Client login() {
  91. MinecraftProtocol protocol;
  92. try {
  93. protocol = new MinecraftProtocol("username", "pass");
  94. System.out.println("Successfully authenticated user.");
  95. } catch (RequestException e) {
  96. throw new RuntimeException(e);
  97. }
  98.  
  99. Client client = new Client(IP_ADDRESS, PORT, protocol, new TcpSessionFactory(PROXY));
  100. client.getSession().setFlag(MinecraftConstants.AUTH_PROXY_KEY, AUTH_PROXY);
  101. return client;
  102. }
  103.  
  104. protected static void move(Client client) {
  105. Thread t = new Thread(() -> {
  106. try {
  107. Thread.sleep(700);
  108. } catch (InterruptedException e) {
  109. e.printStackTrace();
  110. }
  111. z += 0.215;
  112. ClientPlayerPositionRotationPacket packet = new ClientPlayerPositionRotationPacket(true, x, y, z, 0, -90);
  113. client.getSession().send(packet);
  114. move(client);
  115. });
  116.  
  117. t.start();
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement