mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 18:09:44 +00:00
Fix Some Quest Cooldown Behavior
This commit is contained in:
1 parent
38df157c40
commit
eaec10e529
7 files changed
+116
-40
No files matched your search
@@ -99,7 +99,9 @@ public class QuestCategoryCommand extends CommandKamkeelBase {
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if (ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
if (ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared))
|
||||
ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime);
|
||||
;
|
||||
|
||||
|
||||
@@ -115,7 +115,9 @@ public class QuestCommand extends CommandKamkeelBase {
|
||||
playerdata.questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if (ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
if (ConfigMain.ProfilesEnabled && playerdata.player != null && quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared))
|
||||
ProfileController.Instance.shareQuestCompletion(playerdata.player, quest.id, completeTime);
|
||||
|
||||
playerdata.save();
|
||||
|
||||
@@ -523,6 +523,7 @@ public class ProfileController implements IProfileHandler {
|
||||
// overwrite the destination slot with stale data.
|
||||
saveSlotData(profile.player, profile, prevSlot);
|
||||
loadSlotData(profile.player, profile, newSlotId);
|
||||
syncSharedQuestsToPlayer(profile.player);
|
||||
|
||||
EventHooks.onProfileChange(handler, scriptPlayer, profile, newSlotId, prevSlot, true);
|
||||
} else {
|
||||
@@ -860,6 +861,9 @@ public class ProfileController implements IProfileHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// Update the profile cache
|
||||
profile.sharedQuestTimestamps = universalFinished;
|
||||
|
||||
// Push the universal shared completion times into every slot.
|
||||
for (ISlot slot : profile.getSlots().values()) {
|
||||
IPlayerData data = getSlotPlayerData(player, slot.getId());
|
||||
@@ -872,21 +876,29 @@ public class ProfileController implements IProfileHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void syncSharedQuestsToPlayer(EntityPlayer player) {
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null || profile.sharedQuestTimestamps.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PlayerQuestData questData = PlayerData.get(player).questData;
|
||||
for (Map.Entry<Integer, Long> entry : profile.sharedQuestTimestamps.entrySet()) {
|
||||
Long existing = questData.finishedQuests.get(entry.getKey());
|
||||
if (existing == null || entry.getValue() > existing) {
|
||||
questData.finishedQuests.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shareQuestCompletion(EntityPlayer player, int questId, long completeTime) {
|
||||
Profile profile = getProfile(player);
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
for (ISlot slot : profile.getSlots().values()) {
|
||||
IPlayerData playerData = getSlotPlayerData(player, slot.getId());
|
||||
if (playerData != null) {
|
||||
PlayerQuestData questData = (PlayerQuestData) playerData.getQuestData();
|
||||
Long existing = questData.finishedQuests.get(questId);
|
||||
if (existing == null || completeTime > existing) {
|
||||
questData.finishedQuests.put(questId, completeTime);
|
||||
}
|
||||
playerData.save();
|
||||
}
|
||||
|
||||
Long existing = profile.sharedQuestTimestamps.get(questId);
|
||||
if (existing == null || completeTime > existing) {
|
||||
profile.sharedQuestTimestamps.put(questId, completeTime);
|
||||
}
|
||||
save(player, profile);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.IProfile;
|
||||
@@ -15,6 +16,7 @@ public class Profile implements IProfile {
|
||||
public EntityPlayer player;
|
||||
public int currentSlotId;
|
||||
private final Map<Integer, ISlot> slots = new HashMap<>();
|
||||
public Map<Integer, Long> sharedQuestTimestamps = new HashMap<>();
|
||||
private boolean locked = false;
|
||||
|
||||
public Profile(EntityPlayer player, NBTTagCompound compound) {
|
||||
@@ -39,6 +41,14 @@ public class Profile implements IProfile {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (compound.hasKey("SharedQuestTimestamps")) {
|
||||
NBTTagList list = compound.getTagList("SharedQuestTimestamps", 10);
|
||||
for (int i = 0; i < list.tagCount(); i++) {
|
||||
NBTTagCompound entry = list.getCompoundTagAt(i);
|
||||
sharedQuestTimestamps.put(entry.getInteger("Quest"), entry.getLong("Date"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Profile(EntityPlayer player) {
|
||||
@@ -88,6 +98,16 @@ public class Profile implements IProfile {
|
||||
slotsCompound.setTag(String.valueOf(entry.getKey()), entry.getValue().toNBT());
|
||||
}
|
||||
compound.setTag("Slots", slotsCompound);
|
||||
|
||||
NBTTagList questList = new NBTTagList();
|
||||
for (Map.Entry<Integer, Long> entry : sharedQuestTimestamps.entrySet()) {
|
||||
NBTTagCompound questEntry = new NBTTagCompound();
|
||||
questEntry.setInteger("Quest", entry.getKey());
|
||||
questEntry.setLong("Date", entry.getValue());
|
||||
questList.appendTag(questEntry);
|
||||
}
|
||||
compound.setTag("SharedQuestTimestamps", questList);
|
||||
|
||||
return compound;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user