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,20 +136,18 @@ public final class AchievementCommand implements CommandHandler {
parseInt(args.remove(0))
.ifPresentOrElse(
integer -> {
parseInt(args.remove(0))
.ifPresentOrElse(
progress -> {
var ret = achievements.progress(integer, progress);
switch (ret.getRet()) {
case SUCCESS -> sendSuccessMessage(
sender, "progress", targetPlayer.getNickname(), integer, progress);
case ACHIEVEMENT_NOT_FOUND -> CommandHandler.sendTranslatedMessage(
sender, ret.getRet().getKey());
}
},
() -> this.sendUsageMessage(sender));
},
integer -> parseInt(args.remove(0))
.ifPresentOrElse(
progress -> {
var ret = achievements.progress(integer, progress);
switch (ret.getRet()) {
case SUCCESS -> sendSuccessMessage(
sender, "progress", targetPlayer.getNickname(), integer, progress);
case ACHIEVEMENT_NOT_FOUND -> CommandHandler.sendTranslatedMessage(
sender, ret.getRet().getKey());
}
},
() -> 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
.filter(sceneTag -> sceneTag.getSceneId() == 3)
.forEach(
sceneTag -> {
targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId());
});
sceneTag -> targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId()));
this.setSceneTags(targetPlayer);
}

View File

@ -140,25 +140,23 @@ public final class ResourceLoader {
getResourceDefClassesPrioritySets()
.forEach(
classes -> {
classes.stream()
.parallel()
.unordered()
.forEach(
c -> {
val type = c.getAnnotation(ResourceType.class);
if (type == null) return;
classes -> classes.stream()
.parallel()
.unordered()
.forEach(
c -> {
val type = c.getAnnotation(ResourceType.class);
if (type == null) return;
val map = GameData.getMapByResourceDef(c);
if (map == null) return;
val map = GameData.getMapByResourceDef(c);
if (map == null) return;
try {
loadFromResource(c, type, map, doReload);
} catch (Exception e) {
errors.add(Pair.of(Arrays.toString(type.name()), e));
}
});
});
try {
loadFromResource(c, type, map, doReload);
} catch (Exception e) {
errors.add(Pair.of(Arrays.toString(type.name()), e));
}
}));
errors.forEach(
pair ->
Grasscutter.getLogger()

View File

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

View File

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

View File

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

View File

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

View File

@ -93,26 +93,24 @@ public class HomeModuleManager {
.map(HomeBlockItem::getDeployNPCList)
.flatMap(Collection::stream)
.forEach(
avatar -> {
suites.forEach(
suite -> {
var data =
SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom(
avatar.getAvatarId(), suite.getSuiteId());
if (data == null || this.home.isRewardEventFinished(data.getId())) {
return;
}
avatar -> suites.forEach(
suite -> {
var data =
SuiteEventType.HOME_AVATAR_REWARD_EVENT.getEventDataFrom(
avatar.getAvatarId(), suite.getSuiteId());
if (data == null || this.home.isRewardEventFinished(data.getId())) {
return;
}
this.rewardEvents.add(
new HomeAvatarRewardEvent(
homeOwner,
data.getId(),
data.getRewardID(),
data.getAvatarID(),
data.getSuiteId(),
suite.getGuid()));
});
});
this.rewardEvents.add(
new HomeAvatarRewardEvent(
homeOwner,
data.getId(),
data.getRewardID(),
data.getAvatarID(),
data.getSuiteId(),
suite.getGuid()));
}));
if (this.summonEvents != null) {
var suiteIdList = this.rewardEvents.stream().map(HomeAvatarRewardEvent::getSuiteId).toList();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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