From 864298f3b1aa2c75ed17cdaff73935e675e7cbb3 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Mon, 1 May 2023 22:54:00 -0400 Subject: [PATCH] Fix `NullPointerException` with `Player#playerProgress` --- .../java/emu/grasscutter/game/player/Player.java | 4 +++- .../grasscutter/game/player/PlayerProgress.java | 16 +++++++++------- .../emu/grasscutter/game/player/TeamManager.java | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 524a6e78b..fb1e79759 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -255,7 +255,7 @@ public class Player { this.unlockedSceneAreas = new HashMap<>(); this.unlockedScenePoints = new HashMap<>(); this.chatEmojiIdList = new ArrayList<>(); - this.playerProgress = new PlayerProgress(this); + this.playerProgress = new PlayerProgress(); this.activeQuestTimers = new HashSet<>(); this.attackResults = new LinkedBlockingQueue<>(); @@ -1296,6 +1296,8 @@ public class Player { this.loadBattlePassManager(); this.getAvatars().postLoad(); // Needs to be called after inventory is handled + + this.getPlayerProgress().setPlayer(this); // Add reference to the player. } public void onPlayerBorn() { diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java index eb0d558e8..3aa765e92 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgress.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgress.java @@ -17,7 +17,7 @@ import lombok.val; /** Tracks progress the player made in the world, like obtained items, seen characters and more */ @Entity public class PlayerProgress { - @Getter @Transient private final Player player; + @Getter @Setter @Transient private Player player; @Getter private Map itemHistory; @@ -32,9 +32,7 @@ public class PlayerProgress { // it will be hard to loop and compare private Map questProgressCountMap; - public PlayerProgress(Player player) { - this.player = player; - + public PlayerProgress() { this.questProgressCountMap = new Int2IntOpenHashMap(); this.completedDungeons = new IntArrayList(); this.itemHistory = new Int2ObjectOpenHashMap<>(); @@ -53,9 +51,13 @@ public class PlayerProgress { // Mark the dungeon as completed. this.getCompletedDungeons().add(dungeonId); // Trigger the completion event. - this.getPlayer().getQuestManager().queueEvent( - QuestContent.QUEST_CONTENT_FINISH_DUNGEON, dungeonId - ); + if (this.getPlayer() != null) { + this.getPlayer().getQuestManager().queueEvent( + QuestContent.QUEST_CONTENT_FINISH_DUNGEON, dungeonId + ); + } else { + Grasscutter.getLogger().warn("Unable to execute 'QUEST_CONTENT_FINISH_DUNGEON'. The player is null."); + } Grasscutter.getLogger().debug("Dungeon {} has been marked complete for {}.", dungeonId, this.getPlayer().getUid()); diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index bb238747f..ea5ef7934 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -475,7 +475,8 @@ public final class TeamManager extends BasePlayerDataManager { this.setCurrentCharacterIndex(Math.min(newCharacterIndex, this.getActiveTeam().size() - 1)); this.updateTeamProperties(); - this.getPlayer().getScene().addEntity(this.getCurrentAvatarEntity()); + if (this.getPlayer().getScene() != null) + this.getPlayer().getScene().addEntity(this.getCurrentAvatarEntity()); } /**