Format code [skip actions]

This commit is contained in:
github-actions 2023-09-16 21:33:36 +00:00
parent cf8092e8ba
commit b8f7aea168
3 changed files with 53 additions and 52 deletions

View File

@ -6,12 +6,15 @@ import emu.grasscutter.data.excels.scene.SceneTagData;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import java.util.*;
import lombok.val; import lombok.val;
import java.util.*; @Command(
label = "setSceneTag",
@Command(label = "setSceneTag", aliases = { "tag" }, usage = { aliases = {"tag"},
"<add|remove|unlockall> <sceneTagId>" }, permission = "player.setscenetag", permissionTargeted = "player.setscenetag.others") usage = {"<add|remove|unlockall> <sceneTagId>"},
permission = "player.setscenetag",
permissionTargeted = "player.setscenetag.others")
public final class SetSceneTagCommand implements CommandHandler { public final class SetSceneTagCommand implements CommandHandler {
private final Int2ObjectMap<SceneTagData> sceneTagData = GameData.getSceneTagDataMap(); private final Int2ObjectMap<SceneTagData> sceneTagData = GameData.getSceneTagDataMap();
@ -44,7 +47,8 @@ public final class SetSceneTagCommand implements CommandHandler {
val userVal = value; val userVal = value;
var sceneData = sceneTagData.values().stream().filter(sceneTag -> sceneTag.getId() == userVal).findFirst(); var sceneData =
sceneTagData.values().stream().filter(sceneTag -> sceneTag.getId() == userVal).findFirst();
if (sceneData == null) { if (sceneData == null) {
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id"); CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id");
return; return;
@ -58,7 +62,6 @@ public final class SetSceneTagCommand implements CommandHandler {
} }
CommandHandler.sendTranslatedMessage(sender, "commands.generic.set_to", value, actionStr); CommandHandler.sendTranslatedMessage(sender, "commands.generic.set_to", value, actionStr);
} }
private void addSceneTag(Player targetPlayer, int scene, int value) { private void addSceneTag(Player targetPlayer, int scene, int value) {
@ -73,20 +76,25 @@ public final class SetSceneTagCommand implements CommandHandler {
var allData = sceneTagData.values(); var allData = sceneTagData.values();
// Add all SceneTags // Add all SceneTags
allData.stream().toList().forEach(sceneTag -> { allData.stream()
if (targetPlayer.getSceneTags().get(sceneTag.getSceneId()) == null) { .toList()
targetPlayer.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>()); .forEach(
} sceneTag -> {
targetPlayer.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId()); if (targetPlayer.getSceneTags().get(sceneTag.getSceneId()) == null) {
}); targetPlayer.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>());
}
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().filter(sceneTag -> sceneTag.isDefaultValid()) allData.stream()
.filter(sceneTag -> sceneTag.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(sceneTag -> { .forEach(
targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId()); sceneTag -> {
}); targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId());
});
this.setSceneTags(targetPlayer); this.setSceneTags(targetPlayer);
} }
@ -94,5 +102,4 @@ public final class SetSceneTagCommand implements CommandHandler {
private void setSceneTags(Player targetPlayer) { private void setSceneTags(Player targetPlayer) {
targetPlayer.sendPacket(new PacketPlayerWorldSceneInfoListNotify(targetPlayer)); targetPlayer.sendPacket(new PacketPlayerWorldSceneInfoListNotify(targetPlayer));
} }
} }

View File

@ -12,7 +12,6 @@ import emu.grasscutter.game.quest.enums.*;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode; import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
import emu.grasscutter.scripts.data.ScriptArgs; import emu.grasscutter.scripts.data.ScriptArgs;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -6,7 +6,6 @@ import emu.grasscutter.net.packet.*;
import emu.grasscutter.net.proto.MapLayerInfoOuterClass; import emu.grasscutter.net.proto.MapLayerInfoOuterClass;
import emu.grasscutter.net.proto.PlayerWorldSceneInfoListNotifyOuterClass.PlayerWorldSceneInfoListNotify; import emu.grasscutter.net.proto.PlayerWorldSceneInfoListNotifyOuterClass.PlayerWorldSceneInfoListNotify;
import emu.grasscutter.net.proto.PlayerWorldSceneInfoOuterClass.PlayerWorldSceneInfo; import emu.grasscutter.net.proto.PlayerWorldSceneInfoOuterClass.PlayerWorldSceneInfo;
import java.util.Map; import java.util.Map;
public class PacketPlayerWorldSceneInfoListNotify extends BasePacket { public class PacketPlayerWorldSceneInfoListNotify extends BasePacket {
@ -18,44 +17,40 @@ public class PacketPlayerWorldSceneInfoListNotify extends BasePacket {
PlayerWorldSceneInfoListNotify.Builder proto = PlayerWorldSceneInfoListNotify.Builder proto =
PlayerWorldSceneInfoListNotify.newBuilder() PlayerWorldSceneInfoListNotify.newBuilder()
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(1).setIsLocked(false).build()); .addInfoList(
PlayerWorldSceneInfo.newBuilder().setSceneId(1).setIsLocked(false).build());
// Iterate over all scenes // Iterate over all scenes
for (int scene : GameData.getSceneDataMap().keySet()) { for (int scene : GameData.getSceneDataMap().keySet()) {
var worldInfoBuilder = PlayerWorldSceneInfo.newBuilder() var worldInfoBuilder = PlayerWorldSceneInfo.newBuilder().setSceneId(scene).setIsLocked(false);
.setSceneId(scene)
.setIsLocked(false);
/** Add scene-specific data */ /** Add scene-specific data */
// Scenetags // Scenetags
if (sceneTags.keySet().contains(scene)) { if (sceneTags.keySet().contains(scene)) {
worldInfoBuilder worldInfoBuilder.addAllSceneTagIdList(
.addAllSceneTagIdList( sceneTags.entrySet().stream()
sceneTags.entrySet().stream() .filter(e -> e.getKey().equals(scene))
.filter(e -> e.getKey().equals(scene)) .map(Map.Entry::getValue)
.map(Map.Entry::getValue) .toList()
.toList() .get(0));
.get(0) }
);
}
// Map layer information (Big world) // Map layer information (Big world)
if (scene == 3) { if (scene == 3) {
worldInfoBuilder.setMapLayerInfo( worldInfoBuilder.setMapLayerInfo(
MapLayerInfoOuterClass.MapLayerInfo.newBuilder() MapLayerInfoOuterClass.MapLayerInfo.newBuilder()
.addAllUnlockedMapLayerIdList( .addAllUnlockedMapLayerIdList(
GameData.getMapLayerDataMap().keySet()) // MapLayer Ids GameData.getMapLayerDataMap().keySet()) // MapLayer Ids
.addAllUnlockedMapLayerFloorIdList( .addAllUnlockedMapLayerFloorIdList(GameData.getMapLayerFloorDataMap().keySet())
GameData.getMapLayerFloorDataMap().keySet()) .addAllUnlockedMapLayerGroupIdList(
.addAllUnlockedMapLayerGroupIdList( GameData.getMapLayerGroupDataMap()
GameData.getMapLayerGroupDataMap() .keySet()) // will show MapLayer options when hovered over
.keySet()) // will show MapLayer options when hovered over .build()); // map layer test
.build()); // map layer test }
}
proto.addInfoList(worldInfoBuilder.build()); proto.addInfoList(worldInfoBuilder.build());
} }
this.setData(proto); this.setData(proto);
} }