refactor: replace statement with expression lambda

This commit is contained in:
Breno A. 2024-06-09 09:15:22 -03:00
parent c7119aae68
commit fcd409320d
22 changed files with 118 additions and 176 deletions

View File

@ -136,8 +136,7 @@ public final class AchievementCommand implements CommandHandler {
parseInt(args.remove(0)) parseInt(args.remove(0))
.ifPresentOrElse( .ifPresentOrElse(
integer -> { integer -> parseInt(args.remove(0))
parseInt(args.remove(0))
.ifPresentOrElse( .ifPresentOrElse(
progress -> { progress -> {
var ret = achievements.progress(integer, progress); var ret = achievements.progress(integer, progress);
@ -148,8 +147,7 @@ public final class AchievementCommand implements CommandHandler {
sender, ret.getRet().getKey()); sender, ret.getRet().getKey());
} }
}, },
() -> this.sendUsageMessage(sender)); () -> this.sendUsageMessage(sender)),
},
() -> this.sendUsageMessage(sender)); () -> this.sendUsageMessage(sender));
} }
} }

View File

@ -95,9 +95,7 @@ public final class SetSceneTagCommand implements CommandHandler {
// 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(
sceneTag -> { sceneTag -> targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId()));
targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId());
});
this.setSceneTags(targetPlayer); this.setSceneTags(targetPlayer);
} }

View File

@ -140,8 +140,7 @@ public final class ResourceLoader {
getResourceDefClassesPrioritySets() getResourceDefClassesPrioritySets()
.forEach( .forEach(
classes -> { classes -> classes.stream()
classes.stream()
.parallel() .parallel()
.unordered() .unordered()
.forEach( .forEach(
@ -157,8 +156,7 @@ public final class ResourceLoader {
} catch (Exception e) { } catch (Exception e) {
errors.add(Pair.of(Arrays.toString(type.name()), e)); errors.add(Pair.of(Arrays.toString(type.name()), e));
} }
}); }));
});
errors.forEach( errors.forEach(
pair -> pair ->
Grasscutter.getLogger() Grasscutter.getLogger()

View File

@ -61,11 +61,9 @@ public class Achievements {
GameData.getAchievementDataMap().values().stream() GameData.getAchievementDataMap().values().stream()
.filter(AchievementData::isUsed) .filter(AchievementData::isUsed)
.forEach( .forEach(
a -> { a -> map.put(
map.put(
a.getId(), a.getId(),
new Achievement(Status.STATUS_UNFINISHED, a.getId(), a.getProgress(), 0, 0)); new Achievement(Status.STATUS_UNFINISHED, a.getId(), a.getProgress(), 0, 0)));
});
return map; return map;
} }
@ -177,14 +175,12 @@ public class Achievements {
return this.getAchievementList() return this.getAchievementList()
.computeIfAbsent( .computeIfAbsent(
achievementId, achievementId,
id -> { id -> new Achievement(
return new Achievement(
Status.STATUS_UNFINISHED, Status.STATUS_UNFINISHED,
id, id,
GameData.getAchievementDataMap().get(id.intValue()).getProgress(), GameData.getAchievementDataMap().get(id.intValue()).getProgress(),
0, 0,
0); 0));
});
} }
public boolean isInvalid(int achievementId) { public boolean isInvalid(int achievementId) {

View File

@ -776,12 +776,10 @@ public class Avatar {
Stream.of(entry.getSkillPointModifiers()) Stream.of(entry.getSkillPointModifiers())
.mapToInt(SkillPointModifier::getSkillId) .mapToInt(SkillPointModifier::getSkillId)
.forEach( .forEach(
skillId -> { skillId -> this.getPlayer()
this.getPlayer()
.sendPacket( .sendPacket(
new PacketAvatarSkillMaxChargeCountNotify( new PacketAvatarSkillMaxChargeCountNotify(
this, skillId, this.getSkillExtraChargeMap().getOrDefault(skillId, 0))); this, skillId, this.getSkillExtraChargeMap().getOrDefault(skillId, 0))));
});
} }
} }

View File

@ -28,9 +28,7 @@ public class CombineManger extends BaseGameSystem {
try { try {
DataLoader.loadList("ReliquaryDecompose.json", ReliquaryDecomposeEntry.class) DataLoader.loadList("ReliquaryDecompose.json", ReliquaryDecomposeEntry.class)
.forEach( .forEach(
entry -> { entry -> reliquaryDecomposeData.put(entry.getConfigId(), entry.getItems()));
reliquaryDecomposeData.put(entry.getConfigId(), entry.getItems());
});
Grasscutter.getLogger() Grasscutter.getLogger()
.debug("Loaded {} reliquary decompose entries.", reliquaryDecomposeData.size()); .debug("Loaded {} reliquary decompose entries.", reliquaryDecomposeData.size());
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -281,12 +281,10 @@ public class GameHome {
return this.finishedTalkIdMap.entrySet().stream() return this.finishedTalkIdMap.entrySet().stream()
.map( .map(
e -> { e -> HomeAvatarTalkFinishInfo.newBuilder()
return HomeAvatarTalkFinishInfo.newBuilder()
.setAvatarId(e.getKey()) .setAvatarId(e.getKey())
.addAllFinishTalkIdList(e.getValue()) .addAllFinishTalkIdList(e.getValue())
.build(); .build())
})
.toList(); .toList();
} }
@ -395,13 +393,9 @@ public class GameHome {
.get(player.getCurrentRealmId() + 2000) .get(player.getCurrentRealmId() + 2000)
.getBlockItems() .getBlockItems()
.forEach( .forEach(
(i, e) -> { (i, e) -> e.getDeployNPCList()
e.getDeployNPCList()
.forEach( .forEach(
id -> { id -> invitedAvatars.add(id.getAvatarId())));
invitedAvatars.add(id.getAvatarId());
});
});
// Check as realm 5 inside is not in defaults and will be null // Check as realm 5 inside is not in defaults and will be null
if (Objects.nonNull(mainHouseMap.get(player.getCurrentRealmId() + 2000))) { if (Objects.nonNull(mainHouseMap.get(player.getCurrentRealmId() + 2000))) {
@ -410,13 +404,9 @@ public class GameHome {
.get(player.getCurrentRealmId() + 2000) .get(player.getCurrentRealmId() + 2000)
.getBlockItems() .getBlockItems()
.forEach( .forEach(
(i, e) -> { (i, e) -> e.getDeployNPCList()
e.getDeployNPCList()
.forEach( .forEach(
id -> { id -> invitedAvatars.add(id.getAvatarId())));
invitedAvatars.add(id.getAvatarId());
});
});
} }
// Add exp to all avatars // Add exp to all avatars

View File

@ -93,8 +93,7 @@ public class HomeModuleManager {
.map(HomeBlockItem::getDeployNPCList) .map(HomeBlockItem::getDeployNPCList)
.flatMap(Collection::stream) .flatMap(Collection::stream)
.forEach( .forEach(
avatar -> { avatar -> suites.forEach(
suites.forEach(
suite -> { suite -> {
var data = var data =
SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom( SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom(
@ -111,8 +110,7 @@ public class HomeModuleManager {
data.getAvatarID(), data.getAvatarID(),
data.getSuiteId(), data.getSuiteId(),
suite.getGuid())); suite.getGuid()));
}); }));
});
if (this.summonEvents != null) { if (this.summonEvents != null) {
var suiteIdList = this.rewardEvents.stream().map(HomeAvatarRewardEvent::getSuiteId).toList(); var suiteIdList = this.rewardEvents.stream().map(HomeAvatarRewardEvent::getSuiteId).toList();

View File

@ -103,13 +103,11 @@ public class HomeSceneItem {
homeAnimalItem -> homeAnimalItem ->
GameData.getHomeWorldAnimalDataMap().containsKey(homeAnimalItem.getFurnitureId())) GameData.getHomeWorldAnimalDataMap().containsKey(homeAnimalItem.getFurnitureId()))
.map( .map(
homeAnimalItem -> { homeAnimalItem -> new EntityHomeAnimal(
return new EntityHomeAnimal(
scene, scene,
GameData.getHomeWorldAnimalDataMap().get(homeAnimalItem.getFurnitureId()), GameData.getHomeWorldAnimalDataMap().get(homeAnimalItem.getFurnitureId()),
homeAnimalItem.getSpawnPos(), homeAnimalItem.getSpawnPos(),
homeAnimalItem.getSpawnRot()); homeAnimalItem.getSpawnRot()))
})
.toList(); .toList();
} }

View File

@ -46,9 +46,7 @@ public class EnergyManager extends BasePlayerManager {
try { try {
DataLoader.loadList("EnergyDrop.json", EnergyDropEntry.class) DataLoader.loadList("EnergyDrop.json", EnergyDropEntry.class)
.forEach( .forEach(
entry -> { entry -> energyDropData.put(entry.getDropId(), entry.getDropList()));
energyDropData.put(entry.getDropId(), entry.getDropList());
});
Grasscutter.getLogger().debug("Energy drop data successfully loaded."); Grasscutter.getLogger().debug("Energy drop data successfully loaded.");
} catch (Exception ex) { } catch (Exception ex) {
@ -59,9 +57,7 @@ public class EnergyManager extends BasePlayerManager {
try { try {
DataLoader.loadList("SkillParticleGeneration.json", SkillParticleGenerationEntry.class) DataLoader.loadList("SkillParticleGeneration.json", SkillParticleGenerationEntry.class)
.forEach( .forEach(
entry -> { entry -> skillParticleGenerationData.put(entry.getAvatarId(), entry.getAmountList()));
skillParticleGenerationData.put(entry.getAvatarId(), entry.getAmountList());
});
Grasscutter.getLogger().debug("Skill particle generation data successfully loaded."); Grasscutter.getLogger().debug("Skill particle generation data successfully loaded.");
} catch (Exception ex) { } catch (Exception ex) {

View File

@ -52,9 +52,7 @@ public enum ItemUseOp {
static { static {
Stream.of(values()) Stream.of(values())
.forEach( .forEach(
e -> { e -> map.put(e.getValue(), e));
map.put(e.getValue(), e);
});
} }
private final int value; private final int value;

View File

@ -16,9 +16,7 @@ public enum ItemUseTarget {
static { static {
Stream.of(values()) Stream.of(values())
.forEach( .forEach(
e -> { e -> map.put(e.getValue(), e));
map.put(e.getValue(), e);
});
} }
private final int value; private final int value;

View File

@ -14,9 +14,7 @@ public enum ServerBuffType {
static { static {
Stream.of(values()) Stream.of(values())
.forEach( .forEach(
e -> { e -> map.put(e.getValue(), e));
map.put(e.getValue(), e);
});
} }
private final int value; private final int value;

View File

@ -295,9 +295,7 @@ public class GameQuest {
getMainQuest().getChildQuests().values().stream() getMainQuest().getChildQuests().values().stream()
.filter(p -> p.getQuestData().getOrder() > this.getQuestData().getOrder()) .filter(p -> p.getQuestData().getOrder() > this.getQuestData().getOrder())
.forEach( .forEach(
q -> { q -> q.clearProgress(notifyDelete));
q.clearProgress(notifyDelete);
});
clearProgress(notifyDelete); clearProgress(notifyDelete);
this.start(); this.start();
return true; return true;

View File

@ -632,9 +632,7 @@ public class ScriptLib {
worktop.removeWorktopOption(callParams.param2); worktop.removeWorktopOption(callParams.param2);
var scene = getSceneScriptManager().getScene(); var scene = getSceneScriptManager().getScene();
Grasscutter.getGameServer().getScheduler().scheduleDelayedTask(() -> { Grasscutter.getGameServer().getScheduler().scheduleDelayedTask(() -> scene.broadcastPacket(new PacketWorktopOptionNotify(gadget)), 1);
scene.broadcastPacket(new PacketWorktopOptionNotify(gadget));
}, 1);
return 0; return 0;
} }

View File

@ -17,13 +17,11 @@ public class HandlerHomeKickPlayerReq extends PacketHandler {
.filter(player -> player.getUid() == req.getTargetUid()) .filter(player -> player.getUid() == req.getTargetUid())
.findFirst() .findFirst()
.ifPresent( .ifPresent(
player -> { player -> success.set(
success.set(
session session
.getServer() .getServer()
.getHomeWorldMPSystem() .getHomeWorldMPSystem()
.kickPlayerFromHome(session.getPlayer(), player.getUid())); .kickPlayerFromHome(session.getPlayer(), player.getUid())));
});
session.send( session.send(
new PacketHomeKickPlayerRsp( new PacketHomeKickPlayerRsp(

View File

@ -14,16 +14,14 @@ public class PacketActivityScheduleInfoNotify extends BasePacket {
var proto = ActivityScheduleInfoNotifyOuterClass.ActivityScheduleInfoNotify.newBuilder(); var proto = ActivityScheduleInfoNotifyOuterClass.ActivityScheduleInfoNotify.newBuilder();
activityConfigItemList.forEach( activityConfigItemList.forEach(
item -> { item -> proto.addActivityScheduleList(
proto.addActivityScheduleList(
ActivityScheduleInfoOuterClass.ActivityScheduleInfo.newBuilder() ActivityScheduleInfoOuterClass.ActivityScheduleInfo.newBuilder()
.setActivityId(item.getActivityId()) .setActivityId(item.getActivityId())
.setScheduleId(item.getScheduleId()) .setScheduleId(item.getScheduleId())
.setIsOpen(true) .setIsOpen(true)
.setBeginTime(DateHelper.getUnixTime(item.getBeginTime())) .setBeginTime(DateHelper.getUnixTime(item.getBeginTime()))
.setEndTime(DateHelper.getUnixTime(item.getEndTime())) .setEndTime(DateHelper.getUnixTime(item.getEndTime()))
.build()); .build()));
});
this.setData(proto); this.setData(proto);
} }

View File

@ -22,9 +22,7 @@ public class PacketBattlePassMissionUpdateNotify extends BasePacket {
var proto = BattlePassMissionUpdateNotify.newBuilder(); var proto = BattlePassMissionUpdateNotify.newBuilder();
missions.forEach( missions.forEach(
mission -> { mission -> proto.addMissionList(mission.toProto()));
proto.addMissionList(mission.toProto());
});
this.setData(proto.build()); this.setData(proto.build());
} }

View File

@ -93,11 +93,9 @@ public class PacketCodexDataFullNotify extends BasePacket {
.getCodex() .getCodex()
.getUnlockedReliquarySuitCodex() .getUnlockedReliquarySuitCodex()
.forEach( .forEach(
reliquarySuit -> { reliquarySuit -> reliquaryData
reliquaryData
.addCodexIdList(reliquarySuit) .addCodexIdList(reliquarySuit)
.addAllHaveViewedList(Collections.singleton(true)); .addAllHaveViewedList(Collections.singleton(true)));
});
CodexDataFullNotify.Builder proto = CodexDataFullNotify.Builder proto =
CodexDataFullNotify.newBuilder() CodexDataFullNotify.newBuilder()

View File

@ -34,16 +34,14 @@ public class PacketCreateVehicleRsp extends BasePacket {
vehicleMembers.stream() vehicleMembers.stream()
.forEach( .forEach(
vehicleMember -> { vehicleMember -> player
player
.getScene() .getScene()
.broadcastPacket( .broadcastPacket(
new PacketVehicleInteractRsp( new PacketVehicleInteractRsp(
((EntityVehicle) entity), ((EntityVehicle) entity),
vehicleMember, vehicleMember,
VehicleInteractTypeOuterClass.VehicleInteractType VehicleInteractTypeOuterClass.VehicleInteractType
.VEHICLE_INTERACT_TYPE_OUT)); .VEHICLE_INTERACT_TYPE_OUT)));
});
player.getScene().killEntity(entity, 0); player.getScene().killEntity(entity, 0);
}); });

View File

@ -20,10 +20,8 @@ public class PacketPlayerDataNotify extends BasePacket {
player player
.getProperties() .getProperties()
.forEach( .forEach(
(key, value) -> { (key, value) -> p.putPropMap(
p.putPropMap( key, PropValue.newBuilder().setType(key).setIval(value).setVal(value).build()));
key, PropValue.newBuilder().setType(key).setIval(value).setVal(value).build());
});
this.setData(p.build()); this.setData(p.build());
} }

View File

@ -189,12 +189,10 @@ public final class Tools {
achievementDataMap.values().stream() achievementDataMap.values().stream()
.filter(AchievementData::isUsed) .filter(AchievementData::isUsed)
.forEach( .forEach(
data -> { data -> h.newTranslatedLine(
h.newTranslatedLine(
padAchievementId.formatted(data.getId()) + "{0} - {1}", padAchievementId.formatted(data.getId()) + "{0} - {1}",
data.getTitleTextMapHash(), data.getTitleTextMapHash(),
data.getDescTextMapHash()); data.getDescTextMapHash()));
});
// Write txt files // Write txt files
for (int i = 0; i < TextStrings.NUM_LANGUAGES; i++) { for (int i = 0; i < TextStrings.NUM_LANGUAGES; i++) {
@ -352,14 +350,12 @@ public final class Tools {
try { try {
Files.newDirectoryStream(getResourcePath("TextMap"), "TextMap*.json") Files.newDirectoryStream(getResourcePath("TextMap"), "TextMap*.json")
.forEach( .forEach(
path -> { path -> availableLangList.add(
availableLangList.add(
path.getFileName() path.getFileName()
.toString() .toString()
.replace("TextMap", "") .replace("TextMap", "")
.replace(".json", "") .replace(".json", "")
.toLowerCase()); .toLowerCase()));
});
} catch (IOException e) { } catch (IOException e) {
Grasscutter.getLogger().error("Failed to get available languages:", e); Grasscutter.getLogger().error("Failed to get available languages:", e);
} }