浏览代码

Merge pull request #342 from Glitchfinder/fixes

Fixing a few issues.
Glitchfinder 12 年之前
父节点
当前提交
894a78c0f9
共有 1 个文件被更改,包括 16 次插入1 次删除
  1. 16 1
      src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java

+ 16 - 1
src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java

@@ -44,6 +44,7 @@ public class PlayerProfile {
     /* Timestamps */
     /* Timestamps */
     private long recentlyHurt;
     private long recentlyHurt;
     private int respawnATS;
     private int respawnATS;
+    private long lastSave = 0L;
 
 
     /* mySQL STUFF */
     /* mySQL STUFF */
     private int userId;
     private int userId;
@@ -292,7 +293,13 @@ public class PlayerProfile {
     }
     }
 
 
     public void save() {
     public void save() {
-        Long timestamp = System.currentTimeMillis() / 1000;
+        save(true);
+    }
+
+    public void save(boolean override) {
+        Long timestamp = System.currentTimeMillis();
+        if(timestamp < (lastSave + ((long) Config.getInstance().getSaveInterval() * 60000)) && !override)
+            return;
 
 
         // if we are using mysql save to database
         // if we are using mysql save to database
         if (Config.getInstance().getUseMySQL()) {
         if (Config.getInstance().getUseMySQL()) {
@@ -909,10 +916,12 @@ public class PlayerProfile {
 
 
     public void setSkillXPLevel(SkillType skillType, int newValue) {
     public void setSkillXPLevel(SkillType skillType, int newValue) {
         skillsXp.put(skillType, newValue);
         skillsXp.put(skillType, newValue);
+        save(false);
     }
     }
 
 
     public void skillUp(SkillType skillType, int newValue) {
     public void skillUp(SkillType skillType, int newValue) {
         skills.put(skillType, skills.get(skillType) + newValue);
         skills.put(skillType, skills.get(skillType) + newValue);
+        save(false);
     }
     }
     
     
     public void resetSkill(SkillType skillType)
     public void resetSkill(SkillType skillType)
@@ -928,6 +937,7 @@ public class PlayerProfile {
     				skills.put(skill,  0);
     				skills.put(skill,  0);
     		}
     		}
     	}
     	}
+        save(false);
     }
     }
 
 
 //    /**
 //    /**
@@ -1043,6 +1053,7 @@ public class PlayerProfile {
         else {
         else {
             skillsXp.put(skillType, skillsXp.get(skillType) - xp);
             skillsXp.put(skillType, skillsXp.get(skillType) - xp);
         }
         }
+        save(false);
     }
     }
 
 
     /**
     /**
@@ -1066,6 +1077,7 @@ public class PlayerProfile {
             skills.put(skillType, newValue);
             skills.put(skillType, newValue);
             skillsXp.put(skillType, 0);
             skillsXp.put(skillType, 0);
         }
         }
+        save(false);
     }
     }
 
 
     /**
     /**
@@ -1089,6 +1101,7 @@ public class PlayerProfile {
             skills.put(skillType, skills.get(skillType) + levels);
             skills.put(skillType, skills.get(skillType) + levels);
             skillsXp.put(skillType, 0);
             skillsXp.put(skillType, 0);
         }
         }
+        save(false);
     }
     }
 
 
     /**
     /**
@@ -1168,6 +1181,7 @@ public class PlayerProfile {
 
 
     public void setParty(Party party) {
     public void setParty(Party party) {
         this.party = party;
         this.party = party;
+        save(false);
     }
     }
 
 
     public Party getParty() {
     public Party getParty() {
@@ -1185,6 +1199,7 @@ public class PlayerProfile {
 
 
     public void removeParty() {
     public void removeParty() {
         party = null;
         party = null;
+        save(false);
     }
     }
 
 
     public void removeInvite() {
     public void removeInvite() {