mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-04 23:32:55 +08:00
refactor: simplify map operations
we can use computeIfAbsent here
This commit is contained in:
parent
3119e0fffc
commit
c7119aae68
@ -218,11 +218,7 @@ public class SotSManager extends BasePlayerManager {
|
||||
|
||||
public CityInfoData getCityInfo(int cityId) {
|
||||
if (player.getCityInfoData() == null) player.setCityInfoData(new HashMap<>());
|
||||
var cityInfo = player.getCityInfoData().get(cityId);
|
||||
if (cityInfo == null) {
|
||||
cityInfo = new CityInfoData(cityId);
|
||||
player.getCityInfoData().put(cityId, cityInfo);
|
||||
}
|
||||
var cityInfo = player.getCityInfoData().computeIfAbsent(cityId, CityInfoData::new);
|
||||
return cityInfo;
|
||||
}
|
||||
|
||||
|
@ -599,9 +599,7 @@ public class Player implements PlayerHook, FieldFetch {
|
||||
GameData.getSceneTagDataMap().values().stream()
|
||||
.filter(SceneTagData::isDefaultValid)
|
||||
.forEach(sceneTag -> {
|
||||
if (this.getSceneTags().get(sceneTag.getSceneId()) == null) {
|
||||
this.getSceneTags().put(sceneTag.getSceneId(), new HashSet<>());
|
||||
}
|
||||
this.getSceneTags().computeIfAbsent(sceneTag.getSceneId(), k -> new HashSet<>());
|
||||
this.getSceneTags().get(sceneTag.getSceneId()).add(sceneTag.getId());
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user