|
| 1 | +package de.hysky.skyblocker.skyblock; |
| 2 | + |
| 3 | +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.argument; |
| 4 | +import static net.fabricmc.fabric.api.client.command.v2.ClientCommands.literal; |
| 5 | + |
| 6 | +import com.mojang.brigadier.arguments.StringArgumentType; |
| 7 | +import com.mojang.brigadier.tree.LiteralCommandNode; |
| 8 | +import de.hysky.skyblocker.annotations.Init; |
| 9 | +import de.hysky.skyblocker.skyblock.searchoverlay.SearchOverManager; |
| 10 | +import de.hysky.skyblocker.utils.NEURepoManager; |
| 11 | +import de.hysky.skyblocker.utils.Utils; |
| 12 | +import de.hysky.skyblocker.utils.command.CommandUtils; |
| 13 | +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; |
| 14 | +import net.minecraft.commands.SharedSuggestionProvider; |
| 15 | +import org.jspecify.annotations.Nullable; |
| 16 | + |
| 17 | +import java.util.function.Supplier; |
| 18 | + |
| 19 | +public class AuctionBazaarAutocomplete { |
| 20 | + public static @Nullable LiteralCommandNode<FabricClientCommandSource> ahsNode; |
| 21 | + public static @Nullable LiteralCommandNode<FabricClientCommandSource> ahsearchNode; |
| 22 | + public static @Nullable LiteralCommandNode<FabricClientCommandSource> bzsNode; |
| 23 | + public static @Nullable LiteralCommandNode<FabricClientCommandSource> bzNode; |
| 24 | + public static @Nullable LiteralCommandNode<FabricClientCommandSource> bazaarNode; |
| 25 | + |
| 26 | + @Init(priority = 100) // Load after SearchOverManager |
| 27 | + public static void init() { |
| 28 | + NEURepoManager.runAsyncAfterLoad(AuctionBazaarAutocomplete::createNodes); |
| 29 | + } |
| 30 | + |
| 31 | + private static void createNodes() { |
| 32 | + ahsNode = createNode("ahs", SearchOverManager::getAuctionItems); |
| 33 | + ahsearchNode = createNode("ahsearch", SearchOverManager::getAuctionItems); |
| 34 | + bzsNode = createNode("bzs", SearchOverManager::getBazaarItems); |
| 35 | + bzNode = createNode("bz", SearchOverManager::getBazaarItems); |
| 36 | + bazaarNode = createNode("bazaar", SearchOverManager::getBazaarItems); |
| 37 | + } |
| 38 | + |
| 39 | + private static LiteralCommandNode<FabricClientCommandSource> createNode(String command, Supplier<Iterable<String>> suggester) { |
| 40 | + return literal(command) |
| 41 | + .requires(_ -> Utils.isOnSkyblock()) |
| 42 | + .executes(CommandUtils.noOp) |
| 43 | + .then(argument("item", StringArgumentType.greedyString()) |
| 44 | + .suggests((_, builder) -> SharedSuggestionProvider.suggest(suggester.get(), builder)) |
| 45 | + .executes(CommandUtils.noOp)) |
| 46 | + .build(); |
| 47 | + } |
| 48 | +} |
0 commit comments