Advertisement
Guest User

Source Code

a guest
Aug 17th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.65 KB | None | 0 0
  1. package javagui;
  2.  
  3. import com.github.steveice10.mc.auth.data.GameProfile;
  4. import com.github.steveice10.mc.auth.exception.request.RequestException;
  5. import com.github.steveice10.mc.protocol.MinecraftConstants;
  6. import com.github.steveice10.mc.protocol.MinecraftProtocol;
  7. import com.github.steveice10.mc.protocol.ServerLoginHandler;
  8. import com.github.steveice10.mc.protocol.data.SubProtocol;
  9. import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
  10. import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
  11. import com.github.steveice10.mc.protocol.data.game.world.WorldType;
  12. import com.github.steveice10.mc.protocol.data.message.ChatColor;
  13. import com.github.steveice10.mc.protocol.data.message.ChatFormat;
  14. import com.github.steveice10.mc.protocol.data.message.Message;
  15. import com.github.steveice10.mc.protocol.data.message.MessageStyle;
  16. import com.github.steveice10.mc.protocol.data.message.TextMessage;
  17. import com.github.steveice10.mc.protocol.data.message.TranslationMessage;
  18. import com.github.steveice10.mc.protocol.data.status.PlayerInfo;
  19. import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
  20. import com.github.steveice10.mc.protocol.data.status.VersionInfo;
  21. import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoBuilder;
  22. import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
  23. import com.github.steveice10.mc.protocol.data.status.handler.ServerPingTimeHandler;
  24. import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
  25. import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
  26. import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
  27. import com.github.steveice10.packetlib.Client;
  28. import com.github.steveice10.packetlib.Server;
  29. import com.github.steveice10.packetlib.Session;
  30. import com.github.steveice10.packetlib.event.server.ServerAdapter;
  31. import com.github.steveice10.packetlib.event.server.ServerClosedEvent;
  32. import com.github.steveice10.packetlib.event.server.SessionAddedEvent;
  33. import com.github.steveice10.packetlib.event.server.SessionRemovedEvent;
  34. import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
  35. import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
  36. import com.github.steveice10.packetlib.event.session.SessionAdapter;
  37. import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
  38.  
  39. import java.net.Proxy;
  40. import java.util.Arrays;
  41.  
  42.  
  43. import java.awt.EventQueue;
  44.  
  45. import javax.swing.JFrame;
  46. import javax.swing.JButton;
  47. import javax.swing.JOptionPane;
  48. import java.awt.BorderLayout;
  49. import java.awt.event.ActionListener;
  50. import java.awt.event.ActionEvent;
  51. import javax.swing.JTextField;
  52. import javax.swing.JLabel;
  53. import java.awt.Font;
  54.  
  55. public class App {
  56.  
  57.     private JFrame frame;
  58.     private JTextField textField;
  59.     Session session = null;
  60.     private String USERNAME = "Strietzl";
  61.     private String PASSWORD = "pascal13";
  62.     private String SERVER_HOST = "spela.granskogen.nu";
  63.     private int SERVER_PORT = 25565;
  64.     private Proxy PROXY = Proxy.NO_PROXY;
  65.     private Proxy AUTH_PROXY = Proxy.NO_PROXY;
  66.     private JLabel lblStatus;
  67.    
  68.  
  69.     /**
  70.      * Launch the application.
  71.      */
  72.     public static void main(String[] args) {
  73.         EventQueue.invokeLater(new Runnable() {
  74.             public void run() {
  75.                 try {
  76.                     App window = new App();
  77.                     window.frame.setVisible(true);
  78.                 } catch (Exception e) {
  79.                     e.printStackTrace();
  80.                 }
  81.             }
  82.         });
  83.     }
  84.  
  85.     /**
  86.      * Create the application.
  87.      */
  88.     public App() {
  89.         initialize();
  90.     }
  91.  
  92.     /**
  93.      * Initialize the contents of the frame.
  94.      */
  95.     private void initialize() {
  96.         frame = new JFrame();
  97.         frame.setBounds(100, 100, 556, 372);
  98.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  99.         frame.getContentPane().setLayout(null);
  100.        
  101.         lblStatus = new JLabel("Status: clicc a button plz");
  102.         lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 15));
  103.         lblStatus.setBounds(231, 265, 299, 32);
  104.         frame.getContentPane().add(lblStatus);
  105.        
  106.         JButton btnMakeBotJoin = new JButton("make bot join eks dee");
  107.         btnMakeBotJoin.addActionListener(new ActionListener() {
  108.             public void actionPerformed(ActionEvent arg0) {
  109.                 MinecraftProtocol protocol = null;
  110.                 try {
  111.                     protocol = new MinecraftProtocol(USERNAME, PASSWORD);
  112.                     lblStatus.setText("Status: Authenticated");
  113.                 } catch(RequestException e) {
  114.                     lblStatus.setText("Status: Failed to authenticate");
  115.                     e.printStackTrace();
  116.                 }
  117.                 Client client = new Client(SERVER_HOST, SERVER_PORT, protocol, new TcpSessionFactory(PROXY));
  118.                 client.getSession().setFlag(MinecraftConstants.AUTH_PROXY_KEY, AUTH_PROXY);
  119.                 client.getSession().addListener(new SessionAdapter() {
  120.                     @Override
  121.                     public void packetReceived(PacketReceivedEvent event) {
  122.                         if(event.getPacket() instanceof ServerJoinGamePacket) {
  123.                             event.getSession().send(new ClientChatPacket("hello humans"));
  124.                             session = event.getSession();
  125.                             lblStatus.setText("Joined game!");
  126.                         }
  127.                     }
  128.                 });
  129.                
  130.             }
  131.         });
  132.         btnMakeBotJoin.setBounds(10, 11, 182, 71);
  133.         frame.getContentPane().add(btnMakeBotJoin);
  134.        
  135.         textField = new JTextField();
  136.         textField.setBounds(20, 200, 250, 32);
  137.         frame.getContentPane().add(textField);
  138.         textField.setColumns(10);
  139.        
  140.         JButton btnMakeBotTalk = new JButton("make bot talk eks dee");
  141.         btnMakeBotTalk.addActionListener(new ActionListener() {
  142.             public void actionPerformed(ActionEvent e) {
  143.                 session.send(new ClientChatPacket(textField.getText()));
  144.             }
  145.         });
  146.         btnMakeBotTalk.setBounds(30, 243, 191, 51);
  147.         frame.getContentPane().add(btnMakeBotTalk);
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement