From 3119e0fffc3b071b82500f88aa0d9a3f58496503 Mon Sep 17 00:00:00 2001 From: "Breno A." Date: Sun, 9 Jun 2024 09:11:58 -0300 Subject: [PATCH] refactor: replace lambda with method reference --- src/main/java/emu/grasscutter/data/GameData.java | 6 +++--- .../data/excels/avatar/AvatarSkillDepotData.java | 2 +- .../trialavatar/TrialAvatarActivityChallengeTrigger.java | 2 +- .../emu/grasscutter/game/battlepass/BattlePassManager.java | 2 +- src/main/java/emu/grasscutter/game/inventory/Inventory.java | 5 +++-- .../emu/grasscutter/game/managers/blossom/BlossomType.java | 2 +- src/main/java/emu/grasscutter/game/player/Player.java | 5 +++-- src/main/java/emu/grasscutter/game/player/TeamManager.java | 4 ++-- src/main/java/emu/grasscutter/game/shop/ShopInfo.java | 2 +- .../packet/send/PacketAvatarExpeditionAllDataRsp.java | 2 +- .../packet/send/PacketAvatarExpeditionDataNotify.java | 2 +- src/main/java/emu/grasscutter/tools/Tools.java | 4 ++-- src/main/java/emu/grasscutter/utils/lang/Language.java | 4 ++-- 13 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/GameData.java b/src/main/java/emu/grasscutter/data/GameData.java index 1a8597694..f6d9a48d7 100644 --- a/src/main/java/emu/grasscutter/data/GameData.java +++ b/src/main/java/emu/grasscutter/data/GameData.java @@ -630,15 +630,15 @@ public final class GameData { // Non-nullable value getters public static int getAvatarLevelExpRequired(int level) { - return Optional.ofNullable(avatarLevelDataMap.get(level)).map(d -> d.getExp()).orElse(0); + return Optional.ofNullable(avatarLevelDataMap.get(level)).map(AvatarLevelData::getExp).orElse(0); } public static int getAvatarFetterLevelExpRequired(int level) { - return Optional.ofNullable(avatarFetterLevelDataMap.get(level)).map(d -> d.getExp()).orElse(0); + return Optional.ofNullable(avatarFetterLevelDataMap.get(level)).map(AvatarFetterLevelData::getExp).orElse(0); } public static int getRelicExpRequired(int rankLevel, int level) { - return Optional.ofNullable(getRelicLevelData(rankLevel, level)).map(d -> d.getExp()).orElse(0); + return Optional.ofNullable(getRelicLevelData(rankLevel, level)).map(ReliquaryLevelData::getExp).orElse(0); } // Generic getter diff --git a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java index 1e055ec2e..474dca103 100644 --- a/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java +++ b/src/main/java/emu/grasscutter/data/excels/avatar/AvatarSkillDepotData.java @@ -67,7 +67,7 @@ public class AvatarSkillDepotData extends GameResource { Optional.ofNullable(this.talents) .map(talents -> talents.get(0)) .map(i -> GameData.getAvatarTalentDataMap().get((int) i)) - .map(talentData -> talentData.getMainCostItemId()) + .map(AvatarTalentData::getMainCostItemId) .ifPresent(itemId -> this.talentCostItemId = itemId); } diff --git a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java index 1778f4328..b9e7e8c43 100644 --- a/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java +++ b/src/main/java/emu/grasscutter/game/activity/trialavatar/TrialAvatarActivityChallengeTrigger.java @@ -18,7 +18,7 @@ public class TrialAvatarActivityChallengeTrigger extends ActivityWatcher { if (paramList.isEmpty()) return false; val paramCond = Stream.of(paramList.get(0).split(",")).toList(); - return Stream.of(param).allMatch(x -> paramCond.contains(x)); + return Stream.of(param).allMatch(paramCond::contains); } @Override diff --git a/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java b/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java index f72c00e64..6b2ca8a05 100644 --- a/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java +++ b/src/main/java/emu/grasscutter/game/battlepass/BattlePassManager.java @@ -103,7 +103,7 @@ public class BattlePassManager extends BasePlayerDataManager { // Will return a new empty mission if the mission id is not found public BattlePassMission loadMissionById(int id) { - return getMissions().computeIfAbsent(id, i -> new BattlePassMission(i)); + return getMissions().computeIfAbsent(id, BattlePassMission::new); } public boolean hasMission(int id) { diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index 0a5b99999..67dcd32ba 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -8,6 +8,7 @@ import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.avatar.*; +import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.player.*; import emu.grasscutter.game.props.*; import emu.grasscutter.game.props.ItemUseAction.UseItemParams; @@ -370,7 +371,7 @@ public class Inventory extends BasePlayerManager implements Iterable { switch (itemId) { case 101 -> // Character exp this.player.getTeamManager().getActiveTeam().stream() - .map(e -> e.getAvatar()) + .map(EntityAvatar::getAvatar) .forEach( avatar -> this.player @@ -381,7 +382,7 @@ public class Inventory extends BasePlayerManager implements Iterable { this.player.addExpDirectly(count); case 105 -> // Companionship exp this.player.getTeamManager().getActiveTeam().stream() - .map(e -> e.getAvatar()) + .map(EntityAvatar::getAvatar) .forEach( avatar -> this.player diff --git a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java index 925e05b0d..069e469c5 100644 --- a/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java +++ b/src/main/java/emu/grasscutter/game/managers/blossom/BlossomType.java @@ -11,7 +11,7 @@ public enum BlossomType { private static final Int2ObjectMap map = new Int2ObjectOpenHashMap<>( - Stream.of(values()).collect(Collectors.toMap(x -> x.getGadgetId(), x -> x))); + Stream.of(values()).collect(Collectors.toMap(BlossomType::getGadgetId, x -> x))); @Getter private final int gadgetId; @Getter private final int circleCampId; @Getter private final int blossomChestId; diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index c6735d82d..83cd2447d 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -4,6 +4,7 @@ import dev.morphia.annotations.*; import emu.grasscutter.*; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.PlayerLevelData; +import emu.grasscutter.data.excels.scene.SceneTagData; import emu.grasscutter.data.excels.world.WeatherData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.*; @@ -596,7 +597,7 @@ public class Player implements PlayerHook, FieldFetch { */ private void applyStartingSceneTags() { GameData.getSceneTagDataMap().values().stream() - .filter(sceneTag -> sceneTag.isDefaultValid()) + .filter(SceneTagData::isDefaultValid) .forEach(sceneTag -> { if (this.getSceneTags().get(sceneTag.getSceneId()) == null) { this.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>()); @@ -1551,7 +1552,7 @@ public class Player implements PlayerHook, FieldFetch { } public void unfreezeUnlockedScenePoints() { - unlockedScenePoints.keySet().forEach(sceneId -> unfreezeUnlockedScenePoints(sceneId)); + unlockedScenePoints.keySet().forEach(this::unfreezeUnlockedScenePoints); } public int getLegendaryKey() { diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index 0e19dfd90..d808fbf44 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -257,7 +257,7 @@ public final class TeamManager extends BasePlayerDataManager { } // Convert avatars into a collection of avatar IDs, then add - team.getAvatars().addAll(avatars.stream().map(a -> a.getAvatarId()).toList()); + team.getAvatars().addAll(avatars.stream().map(Avatar::getAvatarId).toList()); // Update team if (this.getPlayer().isInMultiplayer()) { @@ -332,7 +332,7 @@ public final class TeamManager extends BasePlayerDataManager { // Dual element resonances elementCounts.object2IntEntrySet().stream() .filter(e -> e.getIntValue() >= 2) - .map(e -> e.getKey()) + .map(Map.Entry::getKey) .filter(elementType -> elementType.getTeamResonanceId() != 0) .forEach( elementType -> { diff --git a/src/main/java/emu/grasscutter/game/shop/ShopInfo.java b/src/main/java/emu/grasscutter/game/shop/ShopInfo.java index 76119984e..f2418c4c3 100644 --- a/src/main/java/emu/grasscutter/game/shop/ShopInfo.java +++ b/src/main/java/emu/grasscutter/game/shop/ShopInfo.java @@ -71,7 +71,7 @@ public class ShopInfo { } public void removeVirtualCosts() { - if (this.costItemList != null) this.costItemList.removeIf(item -> evaluateVirtualCost(item)); + if (this.costItemList != null) this.costItemList.removeIf(this::evaluateVirtualCost); } public enum ShopRefreshType { diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java index 1ada85f16..b71c510a7 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionAllDataRsp.java @@ -22,7 +22,7 @@ public class PacketAvatarExpeditionAllDataRsp extends BasePacket { .setExpeditionCountLimit(expeditionCountLimit) .putAllExpeditionInfoMap( expeditionInfo.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toProto()))) .build()); } } diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java index 5067094ad..d2718f31d 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketAvatarExpeditionDataNotify.java @@ -14,7 +14,7 @@ public class PacketAvatarExpeditionDataNotify extends BasePacket { AvatarExpeditionDataNotify.newBuilder() .putAllExpeditionInfoMap( expeditionInfo.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) + .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toProto()))) .build()); } } diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index ea88a5296..ab382e59a 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -54,7 +54,7 @@ public final class Tools { GameData.getMainQuestDataMap().int2ObjectEntrySet().stream() .collect( Collectors.toMap( - e -> e.getIntKey(), e -> (int) e.getValue().getTitleTextMapHash()))); + Int2ObjectMap.Entry::getIntKey, e -> (int) e.getValue().getTitleTextMapHash()))); // val questDescs = new // Int2IntRBTreeMap(GameData.getQuestDataMap().int2ObjectEntrySet().stream().collect(Collectors.toMap(e -> (int) e.getIntKey(), e -> (int) e.getValue().getDescTextMapHash()))); @@ -99,7 +99,7 @@ public final class Tools { newTranslatedLine( template, LongStream.of(hashes) - .mapToObj(hash -> getTextMapKey(hash)) + .mapToObj(Language::getTextMapKey) .toArray(TextStrings[]::new)); } }; diff --git a/src/main/java/emu/grasscutter/utils/lang/Language.java b/src/main/java/emu/grasscutter/utils/lang/Language.java index 5cfd173c2..df141b7b8 100644 --- a/src/main/java/emu/grasscutter/utils/lang/Language.java +++ b/src/main/java/emu/grasscutter/utils/lang/Language.java @@ -253,11 +253,11 @@ public final class Language { TextStrings.LIST_LANGUAGES.parallelStream() .collect( Collectors.toConcurrentMap( - s -> TextStrings.MAP_LANGUAGES.getInt(s), + TextStrings.MAP_LANGUAGES::getInt, s -> loadTextMapFile(s, nameHashes))); List> languageMaps = IntStream.range(0, TextStrings.NUM_LANGUAGES) - .mapToObj(i -> mapLanguageMaps.get(i)) + .mapToObj(mapLanguageMaps::get) .collect(Collectors.toList()); Map canonicalTextStrings = new HashMap<>();