This commit is contained in:
TfT_02 2013-05-26 15:02:08 +02:00
parent 3525dc82b0
commit ed1c072fd7
3 changed files with 9 additions and 9 deletions

View File

@ -521,6 +521,7 @@ public class McMMOPlayer {
} }
profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + event.getRawXpGained()); profile.setSkillXpLevel(skillType, profile.getSkillXpLevelRaw(skillType) + event.getRawXpGained());
profile.registeredXpGain(skillType, event.getRawXpGained());
McMMOHud spoutHud = profile.getSpoutHud(); McMMOHud spoutHud = profile.getSpoutHud();

View File

@ -262,7 +262,7 @@ public class PlayerProfile {
*/ */
public float getRegisteredXpGain(SkillType skillType) { public float getRegisteredXpGain(SkillType skillType) {
float xp; float xp;
if (rollingSkillsXp.get(skillType) == null) { if (rollingSkillsXp.get(skillType) == null) {
xp = 0F; xp = 0F;
} }
@ -283,7 +283,7 @@ public class PlayerProfile {
public void registeredXpGain(SkillType skillType, float xp) { public void registeredXpGain(SkillType skillType, float xp) {
LinkedList<SkillXpGain> gains = gainedSkillsXp.get(skillType); LinkedList<SkillXpGain> gains = gainedSkillsXp.get(skillType);
if(gains == null) { if (gains == null) {
gains = new LinkedList<SkillXpGain>(); // Maybe add an initial capacity? gains = new LinkedList<SkillXpGain>(); // Maybe add an initial capacity?
} }
gains.addLast(new SkillXpGain(System.currentTimeMillis(), xp)); gains.addLast(new SkillXpGain(System.currentTimeMillis(), xp));
@ -302,20 +302,21 @@ public class PlayerProfile {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
Iterator<Entry<SkillType, LinkedList<SkillXpGain>>> iterator = gainedSkillsXp.entrySet().iterator(); Iterator<Entry<SkillType, LinkedList<SkillXpGain>>> iterator = gainedSkillsXp.entrySet().iterator();
while(iterator.hasNext()) { while (iterator.hasNext()) {
Entry<SkillType, LinkedList<SkillXpGain>> skillGains = iterator.next(); Entry<SkillType, LinkedList<SkillXpGain>> skillGains = iterator.next();
float xp = 0; 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.getValue().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 // Because gainedSkillsXp contains this SkillType, we assume that rollingSkillsXp must also have this SkillType
xp += rollingSkillsXp.get(skillGains.getKey()); xp += rollingSkillsXp.get(skillGains.getKey());
} else { }
else {
break; break;
} }
} }

View File

@ -67,7 +67,5 @@ public class SelfListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
mcMMOPlayer.getProfile().registeredXpGain(skillType, event.getRawXpGained());
} }
} }