From 103a8b8614f27e8381c01599ca9d35ad68451193 Mon Sep 17 00:00:00 2001 From: Ryan <57310593+DonkeyBlaster@users.noreply.github.com> Date: Mon, 24 Jul 2023 05:40:40 -0700 Subject: [PATCH] feat: Export favorites via command (#681) * chore: Remove broken quest book * fix: Allow access to guides and lootruns * feat: Export favorites via command --------- Co-authored-by: Magnus Ihse Bursie --- .../modules/questbook/QuestBookModule.java | 3 +- .../commands/CommandExportFavorites.java | 60 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/wynntils/modules/questbook/commands/CommandExportFavorites.java diff --git a/src/main/java/com/wynntils/modules/questbook/QuestBookModule.java b/src/main/java/com/wynntils/modules/questbook/QuestBookModule.java index 7ddb50dba..e9b134c3d 100644 --- a/src/main/java/com/wynntils/modules/questbook/QuestBookModule.java +++ b/src/main/java/com/wynntils/modules/questbook/QuestBookModule.java @@ -8,11 +8,11 @@ import com.wynntils.core.framework.instances.Module; import com.wynntils.core.framework.interfaces.annotations.ModuleInfo; import com.wynntils.modules.questbook.commands.CommandExportDiscoveries; +import com.wynntils.modules.questbook.commands.CommandExportFavorites; import com.wynntils.modules.questbook.configs.QuestBookConfig; import com.wynntils.modules.questbook.enums.Guides; import com.wynntils.modules.questbook.enums.QuestBookPages; import com.wynntils.modules.questbook.events.ClientEvents; -import com.wynntils.modules.questbook.managers.QuestManager; import com.wynntils.modules.questbook.overlays.hud.TrackedQuestOverlay; import net.minecraftforge.client.settings.KeyConflictContext; import org.lwjgl.input.Keyboard; @@ -31,6 +31,7 @@ public void onEnable() { registerOverlay(new TrackedQuestOverlay(), Priority.HIGHEST); registerCommand(new CommandExportDiscoveries()); + registerCommand(new CommandExportFavorites()); registerKeyBinding("Open Quest Book", Keyboard.KEY_K, "Wynntils", KeyConflictContext.IN_GAME, true, () -> QuestBookPages.QUESTS.getPage().open(true)); registerKeyBinding("Open Discoveries", Keyboard.KEY_U, "Wynntils", KeyConflictContext.IN_GAME, true, () -> QuestBookPages.DISCOVERIES.getPage().open(true)); diff --git a/src/main/java/com/wynntils/modules/questbook/commands/CommandExportFavorites.java b/src/main/java/com/wynntils/modules/questbook/commands/CommandExportFavorites.java new file mode 100644 index 000000000..79670cfc1 --- /dev/null +++ b/src/main/java/com/wynntils/modules/questbook/commands/CommandExportFavorites.java @@ -0,0 +1,60 @@ +/* + * * Copyright © Wynntils - 2022. + */ + +package com.wynntils.modules.questbook.commands; + +import com.wynntils.McIf; +import com.wynntils.core.utils.Utils; +import com.wynntils.modules.utilities.configs.UtilitiesConfig; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraftforge.client.IClientCommand; + +import java.util.ArrayList; +import java.util.List; + +public class CommandExportFavorites extends CommandBase implements IClientCommand { + + + @Override + public String getName() { + return "exportfavorites"; + } + + @Override + public boolean allowUsageWithoutPrefix(ICommandSender sender, String message) { + return false; + } + + @Override + public String getUsage(ICommandSender sender) { + return "exportfavorites"; + } + + @Override + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + ITextComponent command = new TextComponentString("/exportfavorites"); + command.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/exportfavorites")); + + List combinedList = new ArrayList<>(); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoriteItems); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoriteIngredients); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoritePowders); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoriteEmeraldPouches); + + Utils.copyToClipboard("wynntilsFavorites," + String.join(",", combinedList)); + McIf.player().sendMessage(new TextComponentString(TextFormatting.GREEN + "Copied favorites to clipboard! Open the guide list and click the + button on Artemis to import them.")); + } + + @Override + public int getRequiredPermissionLevel() { + return 0; + } +}