diff options
author | nea <nea@nea.moe> | 2023-01-16 16:38:01 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-01-16 16:38:01 +0100 |
commit | 02b1db43c537e9d317565b3bb32c4ba1a14ecd62 (patch) | |
tree | eda94d4d7e01a1093d353d73628cff4afa5211f2 | |
parent | 428de736484aee87253efb12590dddc3c8a08591 (diff) | |
download | NotEnoughUpdates-02b1db43c537e9d317565b3bb32c4ba1a14ecd62.tar.gz NotEnoughUpdates-02b1db43c537e9d317565b3bb32c4ba1a14ecd62.tar.bz2 NotEnoughUpdates-02b1db43c537e9d317565b3bb32c4ba1a14ecd62.zip |
ughidontwannafigureouthowtousethis
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java | 36 | ||||
-rw-r--r-- | src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt | 146 |
2 files changed, 180 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index cf266dca..5787c075 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -19,6 +19,9 @@ package io.github.moulberry.notenoughupdates.commands.dev; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.BuildFlags; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; @@ -34,6 +37,7 @@ import io.github.moulberry.notenoughupdates.util.PronounDB; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.TabListUtils; import io.github.moulberry.notenoughupdates.util.Utils; +import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.command.CommandException; @@ -122,6 +126,32 @@ public class DevTestCommand extends ClientCommandBase { Utils.addChatMessage(EnumChatFormatting.RED + DEV_FAIL_STRINGS[devFailIndex++]); return; } + if (args.length == 1 && args[0].equalsIgnoreCase("testprofile")) { + NotEnoughUpdates.INSTANCE.manager.apiUtils.newHypixelApiRequest("skyblock/profiles") + .queryArgument( + "uuid", + "" + Minecraft.getMinecraft().thePlayer.getUniqueID() + ) + .requestJson() + .thenApply(jsonObject -> { + JsonArray profiles = jsonObject.get("profiles").getAsJsonArray(); + JsonObject cp = null; + for (JsonElement profile : profiles) { + JsonObject asJsonObject = profile.getAsJsonObject(); + if ((asJsonObject.has("selected") && + asJsonObject.get("selected").getAsBoolean()) || cp == null) { + cp = asJsonObject; + } + } + return cp; + }) + .thenCompose(obj -> ProfileCollectionInfo.getCollectionData( + obj, + Minecraft.getMinecraft().thePlayer.getUniqueID() + )) + .thenAccept(it -> + Utils.addChatMessage("Response: " + it)); + } if (args.length >= 1 && args[0].equalsIgnoreCase("profileinfo")) { String currentProfile = SBInfo.getInstance().currentProfile; SBInfo.Gamemode gamemode = SBInfo.getInstance().getGamemodeForProfile(currentProfile); @@ -146,7 +176,8 @@ public class DevTestCommand extends ClientCommandBase { Arrays.copyOfRange(args, 1, args.length) ); } - Utils.addChatMessage("§e[NEU] §fYour external editor is: §Z" + NotEnoughUpdates.INSTANCE.config.hidden.externalEditor); + Utils.addChatMessage( + "§e[NEU] §fYour external editor is: §Z" + NotEnoughUpdates.INSTANCE.config.hidden.externalEditor); return; } if (args.length >= 1 && args[0].equalsIgnoreCase("pricetest")) { @@ -181,7 +212,8 @@ public class DevTestCommand extends ClientCommandBase { } if (args.length == 1 && args[0].equalsIgnoreCase("dev")) { NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev; - Utils.addChatMessage("§e[NEU] Dev mode " + (NotEnoughUpdates.INSTANCE.config.hidden.dev ? "§aenabled": "§cdisabled")); + Utils.addChatMessage( + "§e[NEU] Dev mode " + (NotEnoughUpdates.INSTANCE.config.hidden.dev ? "§aenabled" : "§cdisabled")); return; } if (args.length == 1 && args[0].equalsIgnoreCase("saveconfig")) { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt new file mode 100644 index 00000000..51361bd3 --- /dev/null +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/hypixelapi/Collection.kt @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.util.hypixelapi + +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import java.math.BigInteger +import java.util.* +import java.util.concurrent.CompletableFuture + +data class ProfileCollectionInfo( + val collections: Map<String, CollectionInfo>, + val craftedGenerators: Map<String, Int>, +) { + data class CollectionInfo( + val collection: Collection, + val totalCollectionCount: BigInteger, + val personalCollectionCount: BigInteger, + val unlockedTiers: List<CollectionTier>, + ) + + class CollectionMetadata internal constructor() { + lateinit var collections: Map<String, CollectionCategory> + private set + val allCollections by lazy { collections.values.flatMap { it.items.toList() }.toMap() } + } + + class CollectionCategory internal constructor() { + lateinit var items: Map<String, Collection> + private set + } + + class Collection internal constructor() { + lateinit var name: String + private set + var maxTiers: Int = -1 + private set + lateinit var tiers: List<CollectionTier> + private set + + override fun toString(): String { + return "Collection(name=$name, maxTiers=$maxTiers, tiers=$tiers)" + } + } + + class CollectionTier internal constructor() { + var tier: Int = -1 + private set + var amountRequired: Int = -1 + private set + lateinit var unlocks: List<String> + private set + + override fun toString(): String { + return "CollectionTier(tier=$tier, amountRequired=$amountRequired, unlocks=$unlocks)" + } + } + + + companion object { + + + val generatorPattern = "^([^0-9]+)_([0-9]+)$".toRegex() + + val hypixelCollectionInfo: CompletableFuture<CollectionMetadata> by lazy { + NotEnoughUpdates.INSTANCE.manager.apiUtils + .newHypixelApiRequest("resources/skyblock/collections") + .requestJson() + .thenApply { + NotEnoughUpdates.INSTANCE.manager.gson.fromJson(it, CollectionMetadata::class.java) + } + } + + fun getCollectionData( + profileData: JsonObject, + mainPlayer: UUID, + collectionData: CollectionMetadata + ): ProfileCollectionInfo? { + val mainPlayerUUID = mainPlayer.toString().replace("-", "") + val members = profileData["members"] as? JsonObject ?: return null + val mainPlayerData = + (members[mainPlayerUUID] as? JsonObject ?: return null) + val mainPlayerCollection = mainPlayerData["collection"] as? JsonObject ?: return null + val memberCollections = members.entrySet().mapNotNull { (uuid, data) -> + if (data !is JsonObject) return null + data["collection"] as? JsonObject + } + val generators = members.entrySet().mapNotNull { (uuid, data) -> + if (data !is JsonObject) return null + data["crafted_generators"] as? JsonArray + }.flatMap { it.toList() } + return ProfileCollectionInfo( + collectionData.allCollections.mapValues { (name, collection) -> + val totalCollection = memberCollections.sumOf { it[name]?.asBigInteger ?: BigInteger.ZERO } + val personalCollection = mainPlayerCollection[name]?.asBigInteger ?: BigInteger.ZERO + CollectionInfo( + collection, + totalCollection, + personalCollection, + collection.tiers.filter { BigInteger.valueOf(it.amountRequired.toLong()) <= totalCollection } + ) + }, + generators.toSet() + .mapNotNull { + val pattern = generatorPattern.matchEntire(it.asString) ?: return@mapNotNull null + pattern.groupValues[1] to pattern.groupValues[2].toInt() + } + .groupBy { it.first } + .mapValues { + it.value.maxOf { it.second } + } + .toMap() + ) + } + + /** + * This should be the json object returned by /skyblock/profiles at profiles.<somenumber>. (aka the root tag + * should contain profile_id, members, cute_name, etc.) + */ + @JvmStatic + fun getCollectionData(profileData: JsonObject, mainPlayer: UUID): CompletableFuture<ProfileCollectionInfo?> { + return hypixelCollectionInfo.thenApply { + getCollectionData(profileData, mainPlayer, it) + } + } + } + +} |