From 665263d9bad60fbda55b53021ababf6a03e5302a Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 31 Jul 2023 17:26:30 -0400 Subject: [PATCH 1/4] Fix `account list` subcommand --- .../command/commands/AccountCommand.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index b9edb9d32..4670b25e9 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -1,19 +1,18 @@ package emu.grasscutter.command.commands; -import static emu.grasscutter.utils.lang.Language.translate; - import at.favre.lib.crypto.bcrypt.BCrypt; import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.command.*; import emu.grasscutter.config.Configuration; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.database.DatabaseManager; +import emu.grasscutter.database.*; import emu.grasscutter.game.Account; import emu.grasscutter.game.player.Player; + import java.util.List; import java.util.stream.Collectors; +import static emu.grasscutter.utils.lang.Language.translate; + @Command( label = "account", usage = { @@ -31,17 +30,17 @@ public final class AccountCommand implements CommandHandler { return; } - if (args.size() < 2) { - sendUsageMessage(sender); - return; - } - String action = args.get(0); - String username = args.get(1); switch (action) { default -> this.sendUsageMessage(sender); case "create" -> { + if (args.size() < 2) { + this.sendUsageMessage(sender); + return; + } + var username = args.get(1); + int uid = 0; String password = ""; if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) { @@ -94,6 +93,12 @@ public final class AccountCommand implements CommandHandler { } } case "delete" -> { + if (args.size() < 2) { + this.sendUsageMessage(sender); + return; + } + var username = args.get(1); + // Get the account we want to delete. Account toDelete = DatabaseHelper.getAccountByName(username); if (toDelete == null) { @@ -104,6 +109,12 @@ public final class AccountCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(sender, "commands.account.delete")); } case "resetpass" -> { + if (args.size() < 2) { + this.sendUsageMessage(sender); + return; + } + var username = args.get(1); + if (!Configuration.ACCOUNT.EXPERIMENTAL_RealPassword) { CommandHandler.sendMessage( sender, "resetpass requires EXPERIMENTAL_RealPassword to be true."); From 175e7f5f09a57f95c054a85ea5bbf3c015b2d073 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Aug 2023 04:23:23 +0000 Subject: [PATCH 2/4] Format code [skip actions] --- .../emu/grasscutter/command/commands/AccountCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index 4670b25e9..5efab34c3 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -1,5 +1,7 @@ package emu.grasscutter.command.commands; +import static emu.grasscutter.utils.lang.Language.translate; + import at.favre.lib.crypto.bcrypt.BCrypt; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.*; @@ -7,12 +9,9 @@ import emu.grasscutter.config.Configuration; import emu.grasscutter.database.*; import emu.grasscutter.game.Account; import emu.grasscutter.game.player.Player; - import java.util.List; import java.util.stream.Collectors; -import static emu.grasscutter.utils.lang.Language.translate; - @Command( label = "account", usage = { From 8291e366b9f392171fccf42b436598042e0d6c47 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Tue, 1 Aug 2023 00:27:30 -0400 Subject: [PATCH 3/4] Bump to version `1.6.3` --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4a6ee47b5..36acaba0f 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,7 @@ sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 group = 'io.grasscutter' -version = '1.6.2' +version = '1.6.3' java { withJavadocJar() From 10c1db2fe1ca5d01d8cdb4f0c27300e8fb4b8ef7 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 12 Aug 2023 19:20:34 -0400 Subject: [PATCH 4/4] Add command for listing quests --- .../command/commands/QuestCommand.java | 50 +++++++++++++------ .../grasscutter/game/quest/QuestManager.java | 5 +- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/QuestCommand.java b/src/main/java/emu/grasscutter/command/commands/QuestCommand.java index f4be5738c..cb4c981b0 100644 --- a/src/main/java/emu/grasscutter/command/commands/QuestCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/QuestCommand.java @@ -1,13 +1,15 @@ package emu.grasscutter.command.commands; -import static emu.grasscutter.utils.lang.Language.translate; - import emu.grasscutter.command.*; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.quest.GameQuest; -import java.util.List; +import emu.grasscutter.game.quest.enums.*; + +import java.util.*; import java.util.stream.Collectors; +import static emu.grasscutter.utils.lang.Language.translate; + @Command( label = "quest", aliases = {"q"}, @@ -15,27 +17,30 @@ import java.util.stream.Collectors; permission = "player.quest", permissionTargeted = "player.quest.others") public final class QuestCommand implements CommandHandler { + private static final List SINGLE_ARG = List.of("dungeons", "list"); @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() != 2 || (args.size() == 1 && !args.get(0).toLowerCase().equals("dungeons"))) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } - String cmd = args.get(0).toLowerCase(); - int questId; + var cmd = args.get(0).toLowerCase(); + int questId = -1; - try { - questId = Integer.parseInt(args.get(1)); - } catch (Exception e) { - CommandHandler.sendMessage(sender, translate(sender, "commands.quest.invalid_id")); - return; + if (!SINGLE_ARG.contains(cmd)) { + try { + questId = Integer.parseInt(args.get(1)); + } catch (Exception e) { + CommandHandler.sendMessage(sender, translate(sender, "commands.quest.invalid_id")); + return; + } } switch (cmd) { case "add" -> { - GameQuest quest = targetPlayer.getQuestManager().addQuest(questId); + var quest = targetPlayer.getQuestManager().addQuest(questId); if (quest != null) { CommandHandler.sendMessage(sender, translate(sender, "commands.quest.added", questId)); @@ -45,7 +50,7 @@ public final class QuestCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found")); } case "finish" -> { - GameQuest quest = targetPlayer.getQuestManager().getQuestById(questId); + var quest = targetPlayer.getQuestManager().getQuestById(questId); if (quest == null) { CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found")); @@ -112,7 +117,7 @@ public final class QuestCommand implements CommandHandler { var shouldAdd = !loggedQuests.contains(questId); if (shouldAdd) loggedQuests.add(questId); - else loggedQuests.remove(loggedQuests.indexOf(questId)); + else loggedQuests.remove(questId); CommandHandler.sendMessage( sender, @@ -147,6 +152,23 @@ public final class QuestCommand implements CommandHandler { .map(entry -> "%s: %s".formatted(entry.getKey(), entry.getValue())) .collect(Collectors.joining(", "))); } + case "list" -> { + var questManager = targetPlayer.getQuestManager(); + var mainQuests = questManager.getActiveMainQuests(); + var allQuestIds = mainQuests.stream() + .filter(quest -> questManager.getLoggedQuests().contains(quest.getParentQuestId())) + .filter(quest -> quest.getState() != ParentQuestState.PARENT_QUEST_STATE_FINISHED) + .map(quest -> quest.getChildQuests().values()) + .flatMap(Collection::stream) + .filter(quest -> quest.getState() == QuestState.QUEST_STATE_UNFINISHED) + .map(GameQuest::getSubQuestId) + .map(String::valueOf) + .toList(); + + CommandHandler.sendMessage(sender, "Quests: " + + (allQuestIds.isEmpty() ? "(no active quests)" : + String.join(", ", allQuestIds))); + } default -> this.sendUsageMessage(sender); } } diff --git a/src/main/java/emu/grasscutter/game/quest/QuestManager.java b/src/main/java/emu/grasscutter/game/quest/QuestManager.java index 572731edb..563d2d7b8 100644 --- a/src/main/java/emu/grasscutter/game/quest/QuestManager.java +++ b/src/main/java/emu/grasscutter/game/quest/QuestManager.java @@ -113,7 +113,10 @@ public class QuestManager extends BasePlayerManager { 47001, 47002, 47003, 47004, - 2010103, 2010144 // Prologue Act 2: Chasing Shadows + 2010103, 2010144, // Prologue Act 2: Chasing Shadows, + + 2012 // This is the main quest ID for Chapter 2 Act 1. + // Used for debugging giving items. )); } }