From 97f93d2615eb05df8981eb641c7c52da664e9bd1 Mon Sep 17 00:00:00 2001
From: TacoMonkey <75862693+TacoMonkey11@users.noreply.github.com>
Date: Fri, 25 Feb 2022 21:12:43 -0500
Subject: Added API inventor converter

---
 .../skyblocker/skyblock/api/ProfileUtils.java      | 84 ++++++++++++++++++++++
 .../skyblocker/skyblock/api/StatsCommand.java      |  4 +-
 .../skyblock/api/records/PlayerProfiles.java       | 13 ++--
 3 files changed, 94 insertions(+), 7 deletions(-)

(limited to 'src/main/java/me')

diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/ProfileUtils.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/ProfileUtils.java
index 5c74bdf8..e6efc26c 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/ProfileUtils.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/ProfileUtils.java
@@ -2,12 +2,25 @@ package me.xmrvizzy.skyblocker.skyblock.api;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
 import marcono1234.gson.recordadapter.RecordTypeAdapterFactory;
 import me.xmrvizzy.skyblocker.skyblock.api.records.PlayerProfiles;
+import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemFixerUpper;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
+import net.minecraft.nbt.*;
+import net.minecraft.text.Text;
 
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
 
 public class ProfileUtils {
     public static PlayerProfiles getProfiles(String name){
@@ -24,4 +37,75 @@ public class ProfileUtils {
         }
         return null;
     }
+
+    public static List<ItemStack> itemsFromApiInventory(PlayerProfiles.PlayerProfile.Items.Item[] items){
+        List<ItemStack> inventory = new ArrayList<>();
+        for (PlayerProfiles.PlayerProfile.Items.Item item : items){
+            try{
+                if (item.tag() != null){
+                    JsonObject obj = new Gson().fromJson(Files.readString(Path.of("./config/skyblocker/items-repo/items/" + item.tag().extraAttributes().id() + ".json")), JsonObject.class);
+
+                    NbtCompound root = new NbtCompound();
+                    root.put("Count", NbtByte.of(item.count()));
+                    root.put("id", NbtString.of(ItemFixerUpper.convertItemId(obj.get("itemid").getAsString(), obj.get("damage").getAsInt())));
+                    NbtCompound tag = new NbtCompound();
+                    root.put("tag", tag);
+
+                    if (item.tag().ench() != null){
+                        NbtList enchantments = new NbtList();
+                        enchantments.add(new NbtCompound());
+                        tag.put("Enchantments", enchantments);
+                    }
+
+                    NbtCompound extraAttributes = new NbtCompound();
+                    tag.put("ExtraAttributes", extraAttributes);
+                    extraAttributes.put("id", NbtString.of(item.tag().extraAttributes().id()));
+                    if (item.tag().extraAttributes().enchantments() != null){
+                        NbtCompound enchantments = new NbtCompound();
+                        extraAttributes.put("enchantments", enchantments);
+                        for (String enchant : item.tag().extraAttributes().enchantments().keySet()){
+                            enchantments.put(enchant, NbtInt.of(item.tag().extraAttributes().enchantments().get(enchant)));
+                        }
+                    }
+
+                    NbtCompound display = new NbtCompound();
+                    tag.put("display", display);
+                    display.put("Name", NbtString.of(Text.Serializer.toJson(Text.of(item.tag().display().name()))));
+                    if (item.tag().display().lore() != null){
+                        NbtList lore = new NbtList();
+                        display.put("Lore", lore);
+                        for (int i = 0; i < item.tag().display().lore().length; i++) {
+                            if (i < item.tag().display().lore().length - 1)
+                                lore.add(i, NbtString.of(Text.Serializer.toJson(Text.of(Arrays.stream(item.tag().display().lore()).toArray()[i].toString()))));
+                        }
+                    }
+                    if (item.tag().display().color() != null){
+                        display.put("color", NbtInt.of(item.tag().display().color()));
+                    }
+
+                    if (item.tag().skullOwner() != null){
+                        NbtCompound skullOwner = new NbtCompound();
+                        tag.put("SkullOwner", skullOwner);
+                        UUID uuid = UUID.fromString(item.tag().skullOwner().id());
+                        skullOwner.put("Id", NbtHelper.fromUuid(uuid));
+                        skullOwner.put("Name", NbtString.of(item.tag().extraAttributes().id()));
+
+                        NbtCompound properties = new NbtCompound();
+                        skullOwner.put("Properties", properties);
+                        NbtList textures = new NbtList();
+                        properties.put("textures", textures);
+                        NbtCompound texture = new NbtCompound();
+                        textures.add(texture);
+                        texture.put("Value", NbtString.of(item.tag().skullOwner().properties().textures()[0].get("Value")));
+                    }
+                    inventory.add(ItemStack.fromNbt(root));
+                } else {
+                    inventory.add(Items.AIR.getDefaultStack());
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return inventory;
+    }
 }
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/StatsCommand.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/StatsCommand.java
index 292abe7a..67e3260b 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/StatsCommand.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/StatsCommand.java
@@ -15,9 +15,7 @@ public class StatsCommand {
                                     new Thread(() -> {
                                         PlayerProfiles playerProfiles = ProfileUtils.getProfiles(StringArgumentType.getString(context, "username"));
                                         for (String profileId : playerProfiles.profiles().keySet()){
-                                            if (playerProfiles.profiles().get(profileId).cuteName().equalsIgnoreCase(StringArgumentType.getString(context, "cute name"))){
-                                                System.out.println(playerProfiles);
-                                            }
+                                            System.out.println("Just imagine it did something");
                                         }
                                     }).start();
                                     return 1;
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/records/PlayerProfiles.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/records/PlayerProfiles.java
index 94d95000..1fd6579b 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/records/PlayerProfiles.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/records/PlayerProfiles.java
@@ -41,21 +41,26 @@ public record PlayerProfiles(HashMap<String, PlayerProfile> profiles) {
             public record Item(
                     @SerializedName("Count") byte count,
                     int damage,
-                    Tag tag
+                    Tag tag,
+                    boolean isInactive,
+                    boolean inBackpack,
+                    Item[] containsItems
             ){
                 public record Tag(
                         @SerializedName("ExtraAttributes") ExtraAttributes extraAttributes,
                         Display display,
-                        @SerializedName("SkullOwner") SkullOwner skullOwner
+                        @SerializedName("SkullOwner") SkullOwner skullOwner,
+                        Enchant[] ench
                 ){
-                    public record ExtraAttributes(String id){}
-                    public record Display(@SerializedName("Name") String name, @SerializedName("lore") String[] lore, int color){}
+                    public record ExtraAttributes(String id, HashMap<String, Integer> enchantments){}
+                    public record Display(@SerializedName("Name") String name, @SerializedName("Lore") String[] lore, Integer color){}
                     public record SkullOwner(
                             @SerializedName("Id") String id,
                             @SerializedName("Properties") Properties properties
                     ){
                         public record Properties(HashMap<String, String>[] textures){}
                     }
+                    public record Enchant(int lvl, int id){}
                 }
             }
         }
-- 
cgit