· 5 years ago · May 20, 2020, 05:10 PM
1import request from "request/index";
2import PDObject from "PersistentData";
3
4var data = new PDObject("SBInvSee", {
5 key: "im-not-fucking-stupid"
6})
7
8const baseMojangURL = "https://api.mojang.com/";
9const mojangUUIDEndpoint = "users/profiles/minecraft/";
10const mojangUUIDURL = baseMojangURL + mojangUUIDEndpoint;
11
12const baseHypixelURL = "https://api.hypixel.net/";
13const hypixelProfilesEndpoint = "skyblock/profiles";
14const hypixelPlayerEndpoint = "player"
15const hypixelPlayerURL = baseHypixelURL + hypixelPlayerEndpoint;
16const hypixelProfilesURL = baseHypixelURL + hypixelProfilesEndpoint;
17
18const ItemClass = Java.type("net.minecraft.item.Item");
19const ItemStack = Java.type("net.minecraft.item.ItemStack");
20const InventoryBasic = Java.type("net.minecraft.inventory.InventoryBasic");
21
22const getrequest = function(url) {
23 return request({
24 url: url,
25 headers: {
26 'User-Agent': 'Mozilla/5.0 (ChatTriggers)'
27 },
28 json: true
29 });
30}
31
32register("command", function(...args) {
33 if(JSON.stringify(args) === "[null]" || args === undefined || args[0] === "help") {
34 ChatLib.chat("help");
35 } else if(args[0].length > 16) {
36 ChatLib.chat("too long");
37 } else {
38 var inputusername = args[0];
39 getrequest(mojangUUIDURL + inputusername).then(response => {
40 var username = response["name"];
41 var uuid = response["id"];
42
43 getrequest(hypixelPlayerURL + "?key=" + data.key + "&uuid=" + uuid).then(response => {
44 var player = response["player"]
45 if(player == null) {
46 ChatLib.chat("Player not found.")
47 } else {
48 getrequest(hypixelProfilesURL + "?key=" + data.key + "&uuid=" + uuid).then(response => {
49 var profiles = response["profiles"]
50 var profiletimes = {}
51 if(profiles == null) {
52 ChatLib.chat("No profiles found for " + username)
53 } else {
54 profiles.forEach(profile => {
55 lastsave = profile["members"][uuid]["last_save"].toString()
56 profiletimes[lastsave] = profile;
57 profiletimes[lastsave]["cute_name"] = player["stats"]["SkyBlock"]["profiles"][profile["profile_id"]]["cute_name"]
58 })
59
60 var profile = profiletimes[Math.max.apply(null, Object.keys(profiletimes).map(lastsave => parseInt(lastsave)))]
61
62 if(profile["members"][uuid]["inv_contents"] == null) {
63 ChatLib.chat(username + " has inventory API disabled.")
64 } else {
65 var invContents = profile["members"][uuid]["inv_contents"]["data"]
66 var bytearray = java.util.Base64.getDecoder().decode(invContents);
67 var inputstream = new java.io.ByteArrayInputStream(bytearray);
68 var nbt = net.minecraft.nbt.CompressedStreamTools.func_74796_a(inputstream);
69 var items = nbt.func_150295_c("i", 10);
70 var length = items.func_74745_c();
71
72 var inv = new InventoryBasic(username + "'s Skyblock Inventory", true, 36);
73
74 for(var i = 0; i < length; i++){
75 item = items.func_150305_b(i);
76 if(!item.func_82582_d()) {
77 itemstack = new ItemStack(net.minecraft.init.Blocks.field_150350_a);
78 itemstack.func_77963_c(item);
79
80 inv.func_70299_a(i, itemstack);
81 }
82 }
83
84 Player.getPlayer().func_71007_a(inv)
85 }
86 }
87 }).catch(error => {
88 print(error)
89 ChatLib.chat("An unknown error occured while fetching profile")
90 })
91 }
92 }).catch(error => {
93 print(error)
94 ChatLib.chat("An unknown error occured while fetching profile")
95 });
96 }).catch(error => {
97 ChatLib.chat("Username was not found or an other unknown error occured")
98 });
99 }
100}).setName("sbseeinv");