From cfc8a4866f58d8955aa99897b3a6f844fb506445 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Sun, 15 Oct 2023 00:10:16 +0800 Subject: [PATCH] Add reset scene tag subcommand (#2403) * Add reset scene tag subcommand * Fix Control Flow --- .../command/commands/SetSceneTagCommand.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java b/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java index 3406cce66..26da2b8f1 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetSceneTagCommand.java @@ -12,7 +12,7 @@ import lombok.val; @Command( label = "setSceneTag", aliases = {"tag"}, - usage = {" "}, + usage = {" "}, permission = "player.setscenetag", permissionTargeted = "player.setscenetag.others") public final class SetSceneTagCommand implements CommandHandler { @@ -20,7 +20,7 @@ public final class SetSceneTagCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() == 0) { + if (args.isEmpty()) { sendUsageMessage(sender); return; } @@ -39,6 +39,9 @@ public final class SetSceneTagCommand implements CommandHandler { if (actionStr.equals("unlockall")) { unlockAllSceneTags(targetPlayer); return; + } else if (actionStr.equals("reset") || actionStr.equals("restore")) { + resetAllSceneTags(targetPlayer); + return; } else { CommandHandler.sendTranslatedMessage(sender, "commands.execution.argument_error"); return; @@ -49,7 +52,7 @@ public final class SetSceneTagCommand implements CommandHandler { var sceneData = sceneTagData.values().stream().filter(sceneTag -> sceneTag.getId() == userVal).findFirst(); - if (sceneData == null) { + if (sceneData.isEmpty()) { CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id"); return; } @@ -80,15 +83,13 @@ public final class SetSceneTagCommand implements CommandHandler { .toList() .forEach( sceneTag -> { - if (targetPlayer.getSceneTags().get(sceneTag.getSceneId()) == null) { - targetPlayer.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>()); - } + targetPlayer.getSceneTags().computeIfAbsent(sceneTag.getSceneId(), k -> new HashSet<>()); targetPlayer.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId()); }); // Remove default SceneTags, as most are "before" or "locked" states allData.stream() - .filter(sceneTag -> sceneTag.isDefaultValid()) + .filter(SceneTagData::isDefaultValid) // Only remove for big world as some other scenes only have defaults .filter(sceneTag -> sceneTag.getSceneId() == 3) .forEach( @@ -99,6 +100,17 @@ public final class SetSceneTagCommand implements CommandHandler { this.setSceneTags(targetPlayer); } + private void resetAllSceneTags(Player targetPlayer) { + targetPlayer.getSceneTags().clear(); + // targetPlayer.applyStartingSceneTags(); // private + GameData.getSceneTagDataMap().values().stream() + .filter(SceneTagData::isDefaultValid) + .forEach(sceneTag -> { + targetPlayer.getSceneTags().computeIfAbsent(sceneTag.getSceneId(), k -> new HashSet<>()); + targetPlayer.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId()); + }); + } + private void setSceneTags(Player targetPlayer) { targetPlayer.sendPacket(new PacketPlayerWorldSceneInfoListNotify(targetPlayer)); }