mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2024-11-23 04:19:43 +00:00
Add reset scene tag subcommand (#2403)
* Add reset scene tag subcommand * Fix Control Flow
This commit is contained in:
parent
fd75ba7b9b
commit
cfc8a4866f
@ -12,7 +12,7 @@ import lombok.val;
|
||||
@Command(
|
||||
label = "setSceneTag",
|
||||
aliases = {"tag"},
|
||||
usage = {"<add|remove|unlockall> <sceneTagId>"},
|
||||
usage = {"<add|remove|unlockall|reset> <sceneTagId>"},
|
||||
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<String> 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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user