diff --git a/src/main/java/noppes/npcs/client/ProfileClientConfig.java b/src/main/java/noppes/npcs/client/ProfileClientConfig.java index 66c85a3d7..8a23cc5ca 100644 --- a/src/main/java/noppes/npcs/client/ProfileClientConfig.java +++ b/src/main/java/noppes/npcs/client/ProfileClientConfig.java @@ -1,7 +1,11 @@ package noppes.npcs.client; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.profile.Profile; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.config.ConfigMain; import java.util.HashMap; import java.util.Map; @@ -27,15 +31,34 @@ public class ProfileClientConfig { sharedQuestTimestamps = new HashMap<>(); } - public static Map getSharedQuestTimestamps() { - return sharedQuestTimestamps; + /** + * Whether profiles are enabled, checking the correct source for each side. + */ + public static boolean isProfilesEnabled() { + if (ProfileController.Instance != null) + return ConfigMain.ProfilesEnabled; + return ClientCacheHandler.allowProfiles; } - public static boolean hasSharedQuest(int questId) { + /** + * Check if a quest has a shared timestamp, resolving from server or client cache. + */ + public static boolean hasSharedQuest(EntityPlayer player, int questId) { + if (ProfileController.Instance != null) { + Profile profile = ProfileController.Instance.getProfile(player); + return profile != null && profile.sharedQuestTimestamps.containsKey(questId); + } return sharedQuestTimestamps.containsKey(questId); } - public static Long getSharedQuestTimestamp(int questId) { + /** + * Get the shared quest timestamp, resolving from server or client cache. + */ + public static Long getSharedQuestTimestamp(EntityPlayer player, int questId) { + if (ProfileController.Instance != null) { + Profile profile = ProfileController.Instance.getProfile(player); + return profile != null ? profile.sharedQuestTimestamps.get(questId) : null; + } return sharedQuestTimestamps.get(questId); } } diff --git a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java index a02808c33..cb3fce39f 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java @@ -1,8 +1,6 @@ package noppes.npcs.controllers; import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.profile.Profile; -import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.ProfileClientConfig; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; @@ -133,22 +131,12 @@ public class PlayerQuestController { boolean finishedLocally = data.finishedQuests.containsKey(quest.id); boolean completedShared = false; boolean hasCooldownShared = false; - if (quest.profileOptions.enableOptions) { - boolean hasSharedTimestamp = false; - if (ProfileController.Instance != null) { - if (ConfigMain.ProfilesEnabled) { - Profile profile = ProfileController.Instance.getProfile(player); - hasSharedTimestamp = profile != null && profile.sharedQuestTimestamps.containsKey(quest.id); - } - } else if (ClientCacheHandler.allowProfiles) { - hasSharedTimestamp = ProfileClientConfig.hasSharedQuest(quest.id); - } - if (hasSharedTimestamp) { - if (quest.profileOptions.completeControl == EnumProfileSync.Shared) - completedShared = true; - if (quest.profileOptions.cooldownControl == EnumProfileSync.Shared) - hasCooldownShared = true; - } + if (ProfileClientConfig.isProfilesEnabled() && quest.profileOptions.enableOptions + && ProfileClientConfig.hasSharedQuest(player, quest.id)) { + if (quest.profileOptions.completeControl == EnumProfileSync.Shared) + completedShared = true; + if (quest.profileOptions.cooldownControl == EnumProfileSync.Shared) + hasCooldownShared = true; } boolean isFinished = finishedLocally || completedShared; diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index a547743e4..c7e63ec1f 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -1,8 +1,5 @@ package noppes.npcs.controllers.data; -import kamkeel.npcs.controllers.ProfileController; -import kamkeel.npcs.controllers.data.profile.Profile; -import noppes.npcs.client.ClientCacheHandler; import noppes.npcs.client.ProfileClientConfig; import kamkeel.npcs.network.packets.data.QuestCompletionPacket; import net.minecraft.entity.player.EntityPlayer; @@ -24,7 +21,6 @@ import noppes.npcs.api.handler.data.IQuestCategory; import noppes.npcs.api.handler.data.IQuestInterface; import noppes.npcs.api.handler.data.IQuestObjective; import noppes.npcs.api.handler.data.ISlot; -import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestCompletion; import noppes.npcs.constants.EnumQuestRepeat; @@ -178,18 +174,9 @@ public class Quest implements ICompatibilty, IQuest { } public long getTimeUntilRepeat(EntityPlayer player) { - if (profileOptions.enableOptions && profileOptions.cooldownControl == EnumProfileSync.Shared) { - Long questTime = null; - if (ProfileController.Instance != null) { - if (ConfigMain.ProfilesEnabled) { - Profile profile = ProfileController.Instance.getProfile(player); - if (profile != null) { - questTime = profile.sharedQuestTimestamps.get(this.id); - } - } - } else if (ClientCacheHandler.allowProfiles) { - questTime = ProfileClientConfig.getSharedQuestTimestamp(this.id); - } + if (ProfileClientConfig.isProfilesEnabled() && profileOptions.enableOptions + && profileOptions.cooldownControl == EnumProfileSync.Shared) { + Long questTime = ProfileClientConfig.getSharedQuestTimestamp(player, this.id); if (questTime != null) { return calculateRemainingCooldown(player, questTime); }