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.
This commit is contained in:
NuclearW 2013-05-04 03:50:26 -04:00 committed by TfT_02
parent 324a68949a
commit 0092f31569

View File

@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
@ -300,21 +301,25 @@ public class PlayerProfile {
public void removeXpGainsOlderThan(long age) { public void removeXpGainsOlderThan(long age) {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Iterator<LinkedList<SkillXpGain>> iterator = gainedSkillsXp.values().iterator(); Iterator<Entry<SkillType, LinkedList<SkillXpGain>>> iterator = gainedSkillsXp.entrySet().iterator();
while(iterator.hasNext()) { while(iterator.hasNext()) {
LinkedList<SkillXpGain> skillGains = iterator.next(); Entry<SkillType, LinkedList<SkillXpGain>> 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 // 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<SkillXpGain> gainsIterator = skillGains.iterator(); Iterator<SkillXpGain> gainsIterator = skillGains.getValue().iterator();
while(gainsIterator.hasNext()) { while(gainsIterator.hasNext()) {
SkillXpGain gain = gainsIterator.next(); SkillXpGain gain = gainsIterator.next();
if(now - gain.getTime() >= age) { if(now - gain.getTime() >= age) {
gainsIterator.remove(); gainsIterator.remove();
// Because gainedSkillsXp conatins this SkillType, we assume that rollingSkillsXp must also have this SkillType
xp += rollingSkillsXp.get(skillGains.getKey());
} else { } else {
break; break;
} }
} }
rollingSkillsXp.put(skillGains.getKey(), rollingSkillsXp.get(skillGains.getKey()) - xp);
} }
} }