From 606f421a376493b7de65291d6cebda90bed4a5f8 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Mon, 12 Dec 2022 18:09:13 +0100 Subject: Optimize debug logging a little more More improvements (https://github.com/LMBishop/Quests/issues/452) --- .../questcontroller/NormalQuestController.java | 12 +++--------- .../quests/common/enums/QuestStartResult.java | 21 ++++++++++++++++++--- .../player/questprogressfile/QuestProgressFile.java | 16 +++++++++++++--- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java index 71e0af67..f150f682 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/questcontroller/NormalQuestController.java @@ -247,15 +247,9 @@ public class NormalQuestController implements QuestController { @Override public boolean hasPlayerStartedQuest(QPlayer qPlayer, Quest quest) { - if (config.getBoolean("options.quest-autostart")) { - QuestStartResult response = canPlayerStartQuest(qPlayer, quest); - return response == QuestStartResult.QUEST_SUCCESS || response == QuestStartResult.QUEST_ALREADY_STARTED; - } else { - if (quest.isAutoStartEnabled()) { - QuestStartResult response = canPlayerStartQuest(qPlayer, quest); - return response == QuestStartResult.QUEST_SUCCESS || response == QuestStartResult.QUEST_ALREADY_STARTED; - } else return qPlayer.getQuestProgressFile().hasQuestProgress(quest) && qPlayer.getQuestProgressFile().getQuestProgress(quest).isStarted(); - } + return config.getBoolean("options.quest-autostart") || quest.isAutoStartEnabled() + ? canPlayerStartQuest(qPlayer, quest).hasPlayerStartedQuest() + : qPlayer.getQuestProgressFile().hasQuestStarted(quest); } private void resetQuest(QuestProgress questProgress) { diff --git a/common/src/main/java/com/leonardobishop/quests/common/enums/QuestStartResult.java b/common/src/main/java/com/leonardobishop/quests/common/enums/QuestStartResult.java index 28d8a43c..4c493bf3 100644 --- a/common/src/main/java/com/leonardobishop/quests/common/enums/QuestStartResult.java +++ b/common/src/main/java/com/leonardobishop/quests/common/enums/QuestStartResult.java @@ -1,13 +1,28 @@ package com.leonardobishop.quests.common.enums; public enum QuestStartResult { - QUEST_SUCCESS, //0 + QUEST_SUCCESS(true), //0 QUEST_LIMIT_REACHED, //1 QUEST_ALREADY_COMPLETED, //2 QUEST_COOLDOWN, //3 QUEST_LOCKED, //4 - QUEST_ALREADY_STARTED, //5 + QUEST_ALREADY_STARTED(true), //5 QUEST_NO_PERMISSION, //6 NO_PERMISSION_FOR_CATEGORY, //7 - OTHER //8 + OTHER; //8 + + private final boolean playerStartedQuest; + + QuestStartResult() { + this(false); + } + + QuestStartResult(boolean playerStartedQuest) { + this.playerStartedQuest = playerStartedQuest; + } + + public boolean hasPlayerStartedQuest() { + return playerStartedQuest; + } + } diff --git a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java index 7b91903c..6a6d71d0 100644 --- a/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java +++ b/common/src/main/java/com/leonardobishop/quests/common/player/questprogressfile/QuestProgressFile.java @@ -92,7 +92,7 @@ public class QuestProgressFile { COMPLETED_BEFORE("completedBefore"), STARTED("started"); - private String legacy; + private final String legacy; QuestsProgressFilter(String legacy) { this.legacy = legacy; @@ -197,10 +197,10 @@ public class QuestProgressFile { } /** - * Get the {@link QuestProgress} for a specified {@link Quest}, and generates a new one if it does not exist. + * Get the {@link QuestProgress} for a specified {@link Quest}. Generates a new one if it does not exist. * * @param quest the quest to get progress for - * @return {@link QuestProgress} or null if the quest does not exist + * @return {@link QuestProgress} or a blank generated one if the quest does not exist */ public QuestProgress getQuestProgress(Quest quest) { if (questProgress.containsKey(quest.getId())) { @@ -210,6 +210,16 @@ public class QuestProgressFile { return getQuestProgress(quest); } + /** + * Tests whether or not the player has a specified {@link Quest} started. + * + * @param quest the quest to check for + * @return true if player has the quest started + */ + public boolean hasQuestStarted(Quest quest) { + return questProgress.containsKey(quest.getId()) && questProgress.get(quest.getId()).isStarted(); + } + /** * Generate a new blank {@link QuestProgress} for a specified {@code quest}. * -- cgit v1.2.3-70-g09d2