Fix NPEs when player leaves world

This commit is contained in:
KingRainbow44 2023-04-29 14:04:26 -04:00
parent 02653620d4
commit 5f4f220eab
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE

View File

@ -127,18 +127,18 @@ public class QuestManager extends BasePlayerManager {
this.player.getActivityManager().triggerActivityConditions();
}
public void onTick(){
checkTimeVars();
public void onTick() {
var world = this.getPlayer().getWorld();
if (world == null) return;
checkTimeVars();
// trigger game time tick for quests
queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK,
player.getWorld().getGameTimeHours() , // hours
world.getGameTimeHours() , // hours
0);
}
private void checkTimeVars() {
if (this.player.getWorld() == null) return;
val currentDays = player.getWorld().getTotalGameTimeDays();
val currentHours = player.getWorld().getTotalGameTimeHours();
boolean checkDays = currentDays != lastDayCheck;
@ -385,7 +385,7 @@ public class QuestManager extends BasePlayerManager {
*/
public void checkQuestAlreadyFullfilled(GameQuest quest){
Grasscutter.getGameServer().getScheduler().scheduleDelayedTask(() -> {
for(var condition : quest.getQuestData().getFinishCond()){
for (var condition : quest.getQuestData().getFinishCond()){
switch (condition.getType()) {
case QUEST_CONTENT_OBTAIN_ITEM, QUEST_CONTENT_ITEM_LESS_THAN -> {
//check if we already own enough of the item