Add reset scene tag subcommand (#2403)

* Add reset scene tag subcommand

* Fix Control Flow
This commit is contained in:
jie65535 2023-10-15 00:10:16 +08:00 committed by GitHub
parent fd75ba7b9b
commit cfc8a4866f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ import lombok.val;
@Command( @Command(
label = "setSceneTag", label = "setSceneTag",
aliases = {"tag"}, aliases = {"tag"},
usage = {"<add|remove|unlockall> <sceneTagId>"}, usage = {"<add|remove|unlockall|reset> <sceneTagId>"},
permission = "player.setscenetag", permission = "player.setscenetag",
permissionTargeted = "player.setscenetag.others") permissionTargeted = "player.setscenetag.others")
public final class SetSceneTagCommand implements CommandHandler { public final class SetSceneTagCommand implements CommandHandler {
@ -20,7 +20,7 @@ public final class SetSceneTagCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() == 0) { if (args.isEmpty()) {
sendUsageMessage(sender); sendUsageMessage(sender);
return; return;
} }
@ -39,6 +39,9 @@ public final class SetSceneTagCommand implements CommandHandler {
if (actionStr.equals("unlockall")) { if (actionStr.equals("unlockall")) {
unlockAllSceneTags(targetPlayer); unlockAllSceneTags(targetPlayer);
return; return;
} else if (actionStr.equals("reset") || actionStr.equals("restore")) {
resetAllSceneTags(targetPlayer);
return;
} else { } else {
CommandHandler.sendTranslatedMessage(sender, "commands.execution.argument_error"); CommandHandler.sendTranslatedMessage(sender, "commands.execution.argument_error");
return; return;
@ -49,7 +52,7 @@ public final class SetSceneTagCommand implements CommandHandler {
var sceneData = var sceneData =
sceneTagData.values().stream().filter(sceneTag -> sceneTag.getId() == userVal).findFirst(); sceneTagData.values().stream().filter(sceneTag -> sceneTag.getId() == userVal).findFirst();
if (sceneData == null) { if (sceneData.isEmpty()) {
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id"); CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id");
return; return;
} }
@ -80,15 +83,13 @@ public final class SetSceneTagCommand implements CommandHandler {
.toList() .toList()
.forEach( .forEach(
sceneTag -> { sceneTag -> {
if (targetPlayer.getSceneTags().get(sceneTag.getSceneId()) == null) { targetPlayer.getSceneTags().computeIfAbsent(sceneTag.getSceneId(), k -> new HashSet<>());
targetPlayer.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>());
}
targetPlayer.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId()); targetPlayer.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId());
}); });
// Remove default SceneTags, as most are "before" or "locked" states // Remove default SceneTags, as most are "before" or "locked" states
allData.stream() allData.stream()
.filter(sceneTag -> sceneTag.isDefaultValid()) .filter(SceneTagData::isDefaultValid)
// Only remove for big world as some other scenes only have defaults // Only remove for big world as some other scenes only have defaults
.filter(sceneTag -> sceneTag.getSceneId() == 3) .filter(sceneTag -> sceneTag.getSceneId() == 3)
.forEach( .forEach(
@ -99,6 +100,17 @@ public final class SetSceneTagCommand implements CommandHandler {
this.setSceneTags(targetPlayer); 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) { private void setSceneTags(Player targetPlayer) {
targetPlayer.sendPacket(new PacketPlayerWorldSceneInfoListNotify(targetPlayer)); targetPlayer.sendPacket(new PacketPlayerWorldSceneInfoListNotify(targetPlayer));
} }