Fix NullPointerException with Player#playerProgress

This commit is contained in:
KingRainbow44 2023-05-01 22:54:00 -04:00
parent d2f9f6f05b
commit 864298f3b1
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
3 changed files with 14 additions and 9 deletions

View File

@ -255,7 +255,7 @@ public class Player {
this.unlockedSceneAreas = new HashMap<>(); this.unlockedSceneAreas = new HashMap<>();
this.unlockedScenePoints = new HashMap<>(); this.unlockedScenePoints = new HashMap<>();
this.chatEmojiIdList = new ArrayList<>(); this.chatEmojiIdList = new ArrayList<>();
this.playerProgress = new PlayerProgress(this); this.playerProgress = new PlayerProgress();
this.activeQuestTimers = new HashSet<>(); this.activeQuestTimers = new HashSet<>();
this.attackResults = new LinkedBlockingQueue<>(); this.attackResults = new LinkedBlockingQueue<>();
@ -1296,6 +1296,8 @@ public class Player {
this.loadBattlePassManager(); this.loadBattlePassManager();
this.getAvatars().postLoad(); // Needs to be called after inventory is handled this.getAvatars().postLoad(); // Needs to be called after inventory is handled
this.getPlayerProgress().setPlayer(this); // Add reference to the player.
} }
public void onPlayerBorn() { public void onPlayerBorn() {

View File

@ -17,7 +17,7 @@ import lombok.val;
/** Tracks progress the player made in the world, like obtained items, seen characters and more */ /** Tracks progress the player made in the world, like obtained items, seen characters and more */
@Entity @Entity
public class PlayerProgress { public class PlayerProgress {
@Getter @Transient private final Player player; @Getter @Setter @Transient private Player player;
@Getter private Map<Integer, ItemEntry> itemHistory; @Getter private Map<Integer, ItemEntry> itemHistory;
@ -32,9 +32,7 @@ public class PlayerProgress {
// it will be hard to loop and compare // it will be hard to loop and compare
private Map<Integer, Integer> questProgressCountMap; private Map<Integer, Integer> questProgressCountMap;
public PlayerProgress(Player player) { public PlayerProgress() {
this.player = player;
this.questProgressCountMap = new Int2IntOpenHashMap(); this.questProgressCountMap = new Int2IntOpenHashMap();
this.completedDungeons = new IntArrayList(); this.completedDungeons = new IntArrayList();
this.itemHistory = new Int2ObjectOpenHashMap<>(); this.itemHistory = new Int2ObjectOpenHashMap<>();
@ -53,9 +51,13 @@ public class PlayerProgress {
// Mark the dungeon as completed. // Mark the dungeon as completed.
this.getCompletedDungeons().add(dungeonId); this.getCompletedDungeons().add(dungeonId);
// Trigger the completion event. // Trigger the completion event.
this.getPlayer().getQuestManager().queueEvent( if (this.getPlayer() != null) {
QuestContent.QUEST_CONTENT_FINISH_DUNGEON, dungeonId 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 {}.", Grasscutter.getLogger().debug("Dungeon {} has been marked complete for {}.",
dungeonId, this.getPlayer().getUid()); dungeonId, this.getPlayer().getUid());

View File

@ -475,7 +475,8 @@ public final class TeamManager extends BasePlayerDataManager {
this.setCurrentCharacterIndex(Math.min(newCharacterIndex, this.getActiveTeam().size() - 1)); this.setCurrentCharacterIndex(Math.min(newCharacterIndex, this.getActiveTeam().size() - 1));
this.updateTeamProperties(); this.updateTeamProperties();
this.getPlayer().getScene().addEntity(this.getCurrentAvatarEntity()); if (this.getPlayer().getScene() != null)
this.getPlayer().getScene().addEntity(this.getCurrentAvatarEntity());
} }
/** /**