Pārlūkot izejas kodu

Only save on changes

T00thpick1 12 gadi atpakaļ
vecāks
revīzija
79346d92d7

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

@@ -30,6 +30,7 @@ public class PlayerProfile {
     private final Map<SkillType, Integer>   skills     = new HashMap<SkillType, Integer>();   // Skill & Level
     private final Map<SkillType, Float>     skillsXp   = new HashMap<SkillType, Float>();     // Skill & XP
     private final Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
+    private boolean changed = false;
 
     public PlayerProfile(String playerName) {
         this.playerName = playerName;
@@ -69,7 +70,10 @@ public class PlayerProfile {
     }
 
     public void save() {
-        mcMMO.getDatabaseManager().saveUser(this);
+        if (changed) {
+            mcMMO.getDatabaseManager().saveUser(this);
+            changed = false;
+        }
     }
 
     public String getPlayerName() {
@@ -147,6 +151,8 @@ public class PlayerProfile {
     public void setSkillDATS(AbilityType abilityType, long DATS) {
         int wearsOff = (int) (DATS * .001D);
 
+        changed = true;
+
         skillsDATS.put(abilityType, wearsOff);
     }
 
@@ -154,6 +160,8 @@ public class PlayerProfile {
      * Reset all skill cooldowns.
      */
     public void resetCooldowns() {
+        changed = true;
+
         for (AbilityType ability : skillsDATS.keySet()) {
             skillsDATS.put(ability, 0);
         }
@@ -202,6 +210,8 @@ public class PlayerProfile {
             return;
         }
 
+        changed = true;
+
         skillsXp.put(skillType, skillsXp.get(skillType) - xp);
     }
 
@@ -216,6 +226,8 @@ public class PlayerProfile {
             return;
         }
 
+        changed = true;
+
         skills.put(skillType, newValue);
         skillsXp.put(skillType, 0F);
     }
@@ -231,6 +243,8 @@ public class PlayerProfile {
             return;
         }
 
+        changed = true;
+
         skills.put(skillType, skills.get(skillType) + levels);
         skillsXp.put(skillType, 0F);
     }
@@ -246,6 +260,8 @@ public class PlayerProfile {
             return;
         }
 
+        changed = true;
+
         skillsXp.put(skillType, skillsXp.get(skillType) + experience);
     }