Basmal22/minecron-automated-miner
0
1```java2import org.json.JSONObject;3import java.io.BufferedReader;4import java.io.InputStreamReader;5import java.io.OutputStream;6import java.net.HttpURLConnection;7import java.net.URL;8import java.util.Timer;9import java.util.TimerTask;10 11public class MineCron {12 private static Bot bot;13 private static Timer actionTimer;14 private static Timer sessionTimer;15 private static String discordWebhook;16 private static String currentServer;17 private static String lastAction;18 19 public static void main(String[] args) {20 // Example configuration - replace with your actual values21 String email = "your@email.com";22 String password = "yourpassword";23 String server = "mc.hypixel.net";24 discordWebhook = "https://discord.com/api/webhooks/...";25 int durationHours = 20;26 int actionIntervalSec = 20;27 boolean lobbyRotation = true;28 boolean stayInLobby = false;29 30 startBot(email, password, server, durationHours, actionIntervalSec, lobbyRotation, stayInLobby);31 }32 33 private static void startBot(String email, String password, String server, int durationHours, 34 int actionIntervalSec, boolean lobbyRotation, boolean stayInLobby) {35 try {36 System.out.println("Connecting to Minecraft...");37 bot = new Bot(email, password, server);38 currentServer = server;39 40 sendDiscordNotification("MineCron has successfully logged in" + 41 (server != null ? " and joined " + server : "") + "!");42 43 // Schedule session timeout44 sessionTimer = new Timer();45 sessionTimer.schedule(new TimerTask() {46 @Override47 public void run() {48 stopBot("Session completed after " + durationHours + " hours");49 }50 }, durationHours * 3600 * 1000);51 52 // Schedule human-like actions53 actionTimer = new Timer();54 actionTimer.scheduleAtFixedRate(new TimerTask() {55 @Override56 public void run() {57 performHumanAction();58 }59 }, 0, actionIntervalSec * 1000);60 61 System.out.println("Bot started successfully");62 63 } catch (Exception e) {64 System.err.println("Error starting bot: " + e.getMessage());65 sendDiscordNotification("MineCron failed to start: " + e.getMessage());66 }67 }68 69 private static void performHumanAction() {70 String[] actions = {"Moving", "Jumping", "Looking around", "Switching items", "Swinging arm"};71 String action = actions[(int)(Math.random() * actions.length)];72 lastAction = action;73 74 try {75 switch(action) {76 case "Moving":77 bot.setControlState("forward", true);78 Thread.sleep(1000);79 bot.setControlState("forward", false);80 break;81 case "Jumping":82 bot.setControlState("jump", true);83 Thread.sleep(500);84 bot.setControlState("jump", false);85 break;86 case "Looking around":87 bot.look(Math.random() * Math.PI * 2, Math.random() * Math.PI - Math.PI/2);88 break;89 case "Switching items":90 bot.setQuickBarSlot((int)(Math.random() * 9));91 break;92 case "Swinging arm":93 bot.swingArm();94 break;95 }96 System.out.println("Performed action: " + action);97 } catch (Exception e) {98 System.err.println("Error performing action: " + e.getMessage());99 }100 }101 102 public static void stopBot(String reason) {103 try {104 if (actionTimer != null) actionTimer.cancel();105 if (sessionTimer != null) sessionTimer.cancel();106 if (bot != null) bot.quit();107 108 System.out.println("Bot stopped: " + reason);109 sendDiscordNotification("MineCron stopped: " + reason);110 } catch (Exception e) {111 System.err.println("Error stopping bot: " + e.getMessage());112 }113 }114 115 private static void sendDiscordNotification(String message) {116 if (discordWebhook == null || discordWebhook.isEmpty()) return;117 118 try {119 URL url = new URL(discordWebhook);120 HttpURLConnection con = (HttpURLConnection) url.openConnection();121 con.setRequestMethod("POST");122 con.setRequestProperty("Content-Type", "application/json");123 con.setDoOutput(true);124 125 JSONObject json = new JSONObject();126 json.put("content", message);127 128 try(OutputStream os = con.getOutputStream()) {129 byte[] input = json.toString().getBytes("utf-8");130 os.write(input, 0, input.length);131 }132 133 try(BufferedReader br = new BufferedReader(134 new InputStreamReader(con.getInputStream(), "utf-8"))) {135 StringBuilder response = new StringBuilder();136 String responseLine;137 while ((responseLine = br.readLine()) != null) {138 response.append(responseLine.trim());139 }140 }141 } catch (Exception e) {142 System.err.println("Error sending Discord notification: " + e.getMessage());143 }144 }145}146 147class Bot {148 // Simplified Bot class implementation149 private String username;150 private String password;151 private String server;152 153 public Bot(String username, String password, String server) {154 this.username = username;155 this.password = password;156 this.server = server;157 // Actual connection logic would go here158 }159 160 public void setControlState(String control, boolean state) {161 // Implementation for movement controls162 }163 164 public void look(double yaw, double pitch) {165 // Implementation for looking around166 }167 168 public void setQuickBarSlot(int slot) {169 // Implementation for switching items170 }171 172 public void swingArm() {173 // Implementation for arm swinging174 }175 176 public void quit() {177 // Implementation for disconnecting178 }179}180```