forked from DFOnline/CodeClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandName.java
More file actions
84 lines (69 loc) · 4.09 KB
/
Copy pathCommandName.java
File metadata and controls
84 lines (69 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package dev.dfonline.codeclient.command.impl;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import dev.dfonline.codeclient.ChatType;
import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.command.Command;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.location.Dev;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
public class CommandName extends Command {
@Override
public String name() {
return "name";
}
@Override
public LiteralArgumentBuilder<FabricClientCommandSource> create(LiteralArgumentBuilder<FabricClientCommandSource> cmd, CommandRegistryAccess registryAccess) {
return cmd.then(argument("uuid", word())
.executes(context -> {
String uuid = context.getArgument("uuid", String.class);
MinecraftClient mc = CodeClient.MC;
if(mc.getNetworkHandler() == null) return -1;
String url = "https://sessionserver.mojang.com/session/minecraft/profile/" + uuid;
try {
String NameJson = IOUtils
.toString(new URL(url), StandardCharsets.UTF_8);
if (NameJson.isEmpty()) {
Utility.sendMessage(Text.translatable("codeclient.command.name.not_found", uuid), ChatType.FAIL);
return -1;
}
JsonObject json = JsonParser.parseString(NameJson).getAsJsonObject();
String fullName = json.get("name").getAsString();
String localUsername = Objects.requireNonNull(mc.player).getGameProfile().getName();
if(localUsername.equals(fullName)) {
Utility.sendMessage(Text.translatable("codeclient.command.name.own"), ChatType.SUCCESS);
return 0;
} else {
Text nameDisplay = Text.literal(fullName).formatted(Formatting.AQUA, Formatting.UNDERLINE);
Text message = Text.translatable("codeclient.command.name", uuid, nameDisplay)
.fillStyle(Style.EMPTY
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("codeclient.hover.click_to_copy")))
.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, fullName)));
Utility.sendMessage(message, ChatType.SUCCESS);
if (CodeClient.location instanceof Dev && Config.getConfig().GiveUuidNameStrings)
mc.getNetworkHandler().sendCommand("str " + fullName);
return 0;
}
} catch (IOException e) {
Utility.sendMessage(Text.translatable("codeclient.command.name.not_found", uuid), ChatType.FAIL);
return -1;
}
}));
}
}