refactor: replace lambda with method reference

This commit is contained in:
Breno A. 2024-06-09 09:11:58 -03:00
parent 870085fc91
commit 3119e0fffc
13 changed files with 22 additions and 20 deletions

View File

@ -630,15 +630,15 @@ public final class GameData {
// Non-nullable value getters // Non-nullable value getters
public static int getAvatarLevelExpRequired(int level) { 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) { 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) { 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 // Generic getter

View File

@ -67,7 +67,7 @@ public class AvatarSkillDepotData extends GameResource {
Optional.ofNullable(this.talents) Optional.ofNullable(this.talents)
.map(talents -> talents.get(0)) .map(talents -> talents.get(0))
.map(i -> GameData.getAvatarTalentDataMap().get((int) i)) .map(i -> GameData.getAvatarTalentDataMap().get((int) i))
.map(talentData -> talentData.getMainCostItemId()) .map(AvatarTalentData::getMainCostItemId)
.ifPresent(itemId -> this.talentCostItemId = itemId); .ifPresent(itemId -> this.talentCostItemId = itemId);
} }

View File

@ -18,7 +18,7 @@ public class TrialAvatarActivityChallengeTrigger extends ActivityWatcher {
if (paramList.isEmpty()) return false; if (paramList.isEmpty()) return false;
val paramCond = Stream.of(paramList.get(0).split(",")).toList(); 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 @Override

View File

@ -103,7 +103,7 @@ public class BattlePassManager extends BasePlayerDataManager {
// Will return a new empty mission if the mission id is not found // Will return a new empty mission if the mission id is not found
public BattlePassMission loadMissionById(int id) { public BattlePassMission loadMissionById(int id) {
return getMissions().computeIfAbsent(id, i -> new BattlePassMission(i)); return getMissions().computeIfAbsent(id, BattlePassMission::new);
} }
public boolean hasMission(int id) { public boolean hasMission(int id) {

View File

@ -8,6 +8,7 @@ import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.avatar.*; import emu.grasscutter.game.avatar.*;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.*; import emu.grasscutter.game.player.*;
import emu.grasscutter.game.props.*; import emu.grasscutter.game.props.*;
import emu.grasscutter.game.props.ItemUseAction.UseItemParams; import emu.grasscutter.game.props.ItemUseAction.UseItemParams;
@ -370,7 +371,7 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
switch (itemId) { switch (itemId) {
case 101 -> // Character exp case 101 -> // Character exp
this.player.getTeamManager().getActiveTeam().stream() this.player.getTeamManager().getActiveTeam().stream()
.map(e -> e.getAvatar()) .map(EntityAvatar::getAvatar)
.forEach( .forEach(
avatar -> avatar ->
this.player this.player
@ -381,7 +382,7 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
this.player.addExpDirectly(count); this.player.addExpDirectly(count);
case 105 -> // Companionship exp case 105 -> // Companionship exp
this.player.getTeamManager().getActiveTeam().stream() this.player.getTeamManager().getActiveTeam().stream()
.map(e -> e.getAvatar()) .map(EntityAvatar::getAvatar)
.forEach( .forEach(
avatar -> avatar ->
this.player this.player

View File

@ -11,7 +11,7 @@ public enum BlossomType {
private static final Int2ObjectMap<BlossomType> map = private static final Int2ObjectMap<BlossomType> map =
new Int2ObjectOpenHashMap<>( 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 gadgetId;
@Getter private final int circleCampId; @Getter private final int circleCampId;
@Getter private final int blossomChestId; @Getter private final int blossomChestId;

View File

@ -4,6 +4,7 @@ import dev.morphia.annotations.*;
import emu.grasscutter.*; import emu.grasscutter.*;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.PlayerLevelData; import emu.grasscutter.data.excels.PlayerLevelData;
import emu.grasscutter.data.excels.scene.SceneTagData;
import emu.grasscutter.data.excels.world.WeatherData; import emu.grasscutter.data.excels.world.WeatherData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.*; import emu.grasscutter.game.*;
@ -596,7 +597,7 @@ public class Player implements PlayerHook, FieldFetch {
*/ */
private void applyStartingSceneTags() { private void applyStartingSceneTags() {
GameData.getSceneTagDataMap().values().stream() GameData.getSceneTagDataMap().values().stream()
.filter(sceneTag -> sceneTag.isDefaultValid()) .filter(SceneTagData::isDefaultValid)
.forEach(sceneTag -> { .forEach(sceneTag -> {
if (this.getSceneTags().get(sceneTag.getSceneId()) == null) { if (this.getSceneTags().get(sceneTag.getSceneId()) == null) {
this.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>()); this.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>());
@ -1551,7 +1552,7 @@ public class Player implements PlayerHook, FieldFetch {
} }
public void unfreezeUnlockedScenePoints() { public void unfreezeUnlockedScenePoints() {
unlockedScenePoints.keySet().forEach(sceneId -> unfreezeUnlockedScenePoints(sceneId)); unlockedScenePoints.keySet().forEach(this::unfreezeUnlockedScenePoints);
} }
public int getLegendaryKey() { public int getLegendaryKey() {

View File

@ -257,7 +257,7 @@ public final class TeamManager extends BasePlayerDataManager {
} }
// Convert avatars into a collection of avatar IDs, then add // 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 // Update team
if (this.getPlayer().isInMultiplayer()) { if (this.getPlayer().isInMultiplayer()) {
@ -332,7 +332,7 @@ public final class TeamManager extends BasePlayerDataManager {
// Dual element resonances // Dual element resonances
elementCounts.object2IntEntrySet().stream() elementCounts.object2IntEntrySet().stream()
.filter(e -> e.getIntValue() >= 2) .filter(e -> e.getIntValue() >= 2)
.map(e -> e.getKey()) .map(Map.Entry::getKey)
.filter(elementType -> elementType.getTeamResonanceId() != 0) .filter(elementType -> elementType.getTeamResonanceId() != 0)
.forEach( .forEach(
elementType -> { elementType -> {

View File

@ -71,7 +71,7 @@ public class ShopInfo {
} }
public void removeVirtualCosts() { 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 { public enum ShopRefreshType {

View File

@ -22,7 +22,7 @@ public class PacketAvatarExpeditionAllDataRsp extends BasePacket {
.setExpeditionCountLimit(expeditionCountLimit) .setExpeditionCountLimit(expeditionCountLimit)
.putAllExpeditionInfoMap( .putAllExpeditionInfoMap(
expeditionInfo.entrySet().stream() expeditionInfo.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toProto())))
.build()); .build());
} }
} }

View File

@ -14,7 +14,7 @@ public class PacketAvatarExpeditionDataNotify extends BasePacket {
AvatarExpeditionDataNotify.newBuilder() AvatarExpeditionDataNotify.newBuilder()
.putAllExpeditionInfoMap( .putAllExpeditionInfoMap(
expeditionInfo.entrySet().stream() expeditionInfo.entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toProto()))) .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toProto())))
.build()); .build());
} }
} }

View File

@ -54,7 +54,7 @@ public final class Tools {
GameData.getMainQuestDataMap().int2ObjectEntrySet().stream() GameData.getMainQuestDataMap().int2ObjectEntrySet().stream()
.collect( .collect(
Collectors.toMap( Collectors.toMap(
e -> e.getIntKey(), e -> (int) e.getValue().getTitleTextMapHash()))); Int2ObjectMap.Entry::getIntKey, e -> (int) e.getValue().getTitleTextMapHash())));
// val questDescs = new // val questDescs = new
// Int2IntRBTreeMap(GameData.getQuestDataMap().int2ObjectEntrySet().stream().collect(Collectors.toMap(e -> (int) e.getIntKey(), e -> (int) e.getValue().getDescTextMapHash()))); // 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( newTranslatedLine(
template, template,
LongStream.of(hashes) LongStream.of(hashes)
.mapToObj(hash -> getTextMapKey(hash)) .mapToObj(Language::getTextMapKey)
.toArray(TextStrings[]::new)); .toArray(TextStrings[]::new));
} }
}; };

View File

@ -253,11 +253,11 @@ public final class Language {
TextStrings.LIST_LANGUAGES.parallelStream() TextStrings.LIST_LANGUAGES.parallelStream()
.collect( .collect(
Collectors.toConcurrentMap( Collectors.toConcurrentMap(
s -> TextStrings.MAP_LANGUAGES.getInt(s), TextStrings.MAP_LANGUAGES::getInt,
s -> loadTextMapFile(s, nameHashes))); s -> loadTextMapFile(s, nameHashes)));
List<Int2ObjectMap<String>> languageMaps = List<Int2ObjectMap<String>> languageMaps =
IntStream.range(0, TextStrings.NUM_LANGUAGES) IntStream.range(0, TextStrings.NUM_LANGUAGES)
.mapToObj(i -> mapLanguageMaps.get(i)) .mapToObj(mapLanguageMaps::get)
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<TextStrings, TextStrings> canonicalTextStrings = new HashMap<>(); Map<TextStrings, TextStrings> canonicalTextStrings = new HashMap<>();