From 0092f31569c1629e45898d7e2e95b65b07414441 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Sat, 4 May 2013 03:50:26 -0400 Subject: [PATCH] Remember to remove the xp from rollingSkillsXp when we clean. Additionally it may be possible, although unlikely for rollingSkillsXp to be a small negative value, due to the use of float values. This will need to be watched for, but otherwise can be left alone as if it occurs it should be insignificant. --- .../gmail/nossr50/datatypes/player/PlayerProfile.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java index 8ab1f1a49..4cb2f11d5 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/PlayerProfile.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.bukkit.scoreboard.Scoreboard; @@ -300,21 +301,25 @@ public class PlayerProfile { public void removeXpGainsOlderThan(long age) { long now = System.currentTimeMillis(); - Iterator> iterator = gainedSkillsXp.values().iterator(); + Iterator>> iterator = gainedSkillsXp.entrySet().iterator(); while(iterator.hasNext()) { - LinkedList skillGains = iterator.next(); + Entry> skillGains = iterator.next(); + float xp = 0; // Because we are using a LinkedList and addLast ordering is guaranteed, so we loop through and remove things that are too old, and stop immediately once we find a young'n - Iterator gainsIterator = skillGains.iterator(); + Iterator gainsIterator = skillGains.getValue().iterator(); while(gainsIterator.hasNext()) { SkillXpGain gain = gainsIterator.next(); if(now - gain.getTime() >= age) { gainsIterator.remove(); + // Because gainedSkillsXp conatins this SkillType, we assume that rollingSkillsXp must also have this SkillType + xp += rollingSkillsXp.get(skillGains.getKey()); } else { break; } } + rollingSkillsXp.put(skillGains.getKey(), rollingSkillsXp.get(skillGains.getKey()) - xp); } }