From ca80a7d463c4f9d5201c809aa6efab373466ca7d Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 9 Feb 2012 03:11:18 -0800 Subject: [PATCH] Optimized how mcMMO saves player information. --- .../nossr50/datatypes/PlayerProfile.java | 14 ------- src/main/java/com/gmail/nossr50/mcMMO.java | 4 ++ .../gmail/nossr50/runnables/mcSaveTimer.java | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 234c80c9d..01d760a84 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -778,7 +778,6 @@ public class PlayerProfile public long getGreenTerraDeactivatedTimeStamp() {return greenTerraDATS;} public void setGreenTerraDeactivatedTimeStamp(Long newvalue){ greenTerraDATS = (int) (newvalue/1000); - save(); } /* * BERSERK MODE @@ -800,7 +799,6 @@ public class PlayerProfile public long getBerserkDeactivatedTimeStamp() {return berserkDATS;} public void setBerserkDeactivatedTimeStamp(Long newvalue){ berserkDATS = (int) (newvalue/1000); - save(); } /* * SKULL SPLITTER @@ -822,7 +820,6 @@ public class PlayerProfile public long getSkullSplitterDeactivatedTimeStamp() {return skullSplitterDATS;} public void setSkullSplitterDeactivatedTimeStamp(Long newvalue){ skullSplitterDATS = (int) (newvalue/1000); - save(); } /* * SERRATED STRIKES @@ -844,7 +841,6 @@ public class PlayerProfile public long getSerratedStrikesDeactivatedTimeStamp() {return serratedStrikesDATS;} public void setSerratedStrikesDeactivatedTimeStamp(Long newvalue){ serratedStrikesDATS = (int) (newvalue/1000); - save(); } /* * GIGA DRILL BREAKER @@ -866,7 +862,6 @@ public class PlayerProfile public long getGigaDrillBreakerDeactivatedTimeStamp() {return gigaDrillBreakerDATS;} public void setGigaDrillBreakerDeactivatedTimeStamp(Long newvalue){ gigaDrillBreakerDATS = (int) (newvalue/1000); - save(); } /* * TREE FELLER STUFF @@ -888,7 +883,6 @@ public class PlayerProfile public long getTreeFellerDeactivatedTimeStamp() {return treeFellerDATS;} public void setTreeFellerDeactivatedTimeStamp(Long newvalue){ treeFellerDATS = (int) (newvalue/1000); - save(); } /* * MINING @@ -910,7 +904,6 @@ public class PlayerProfile public long getSuperBreakerDeactivatedTimeStamp() {return superBreakerDATS;} public void setSuperBreakerDeactivatedTimeStamp(Long newvalue){ superBreakerDATS = (int) (newvalue/1000); - save(); } public long getRecentlyHurt(){ return recentlyHurt; @@ -921,7 +914,6 @@ public class PlayerProfile public void skillUp(SkillType skillType, int newvalue) { skills.put(skillType, skills.get(skillType)+newvalue); - save(); } public Integer getSkillLevel(SkillType skillType) { @@ -1058,7 +1050,6 @@ public class PlayerProfile skillsXp.put(skillType, skillsXp.get(skillType)+xp); lastgained = skillType; } - //save(); } public void removeXP(SkillType skillType, int newvalue) @@ -1080,7 +1071,6 @@ public class PlayerProfile } else { skillsXp.put(skillType, skillsXp.get(skillType)-newvalue); } - //save(); } public void acceptInvite() { @@ -1126,7 +1116,6 @@ public class PlayerProfile skills.put(skillType, newvalue); skillsXp.put(skillType, newvalue); } - save(); } public Integer getXpToLevel(SkillType skillType) { @@ -1137,14 +1126,12 @@ public class PlayerProfile public void setParty(String newParty) { party = newParty; - save(); } //Retrieve the player's party public String getParty() {return party;} //Remove party public void removeParty() { party = null; - save(); } //Retrieve whether or not the player is in a party public boolean inParty() @@ -1176,7 +1163,6 @@ public class PlayerProfile public void setMySpawn(double x, double y, double z, String myspawnworldlocation){ myspawn = x+","+y+","+z; myspawnworld = myspawnworldlocation; - save(); } public String getX(){ if(myspawn != null) diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index a53b2d3ec..e14ce1d60 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -83,6 +83,7 @@ public class mcMMO extends JavaPlugin private final mcEntityListener entityListener = new mcEntityListener(this); private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION + private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(this); //R2 block place workaround //private Timer mcMMO_SpellTimer = new Timer(true); @@ -157,6 +158,9 @@ public class mcMMO extends JavaPlugin for(Player player : getServer().getOnlinePlayers()){Users.addUser(player);} //In case of reload add all users back into PlayerProfile System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" ); + //Periodic save timer (Saves every 10 minutes) + Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_SaveTimer, 0, 12000); + Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20); //R2+ block place fix Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10); diff --git a/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java new file mode 100644 index 000000000..e4bb109db --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java @@ -0,0 +1,40 @@ +/* + This file is part of mcMMO. + + mcMMO is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + mcMMO is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mcMMO. If not, see . +*/ +package com.gmail.nossr50.runnables; + +import org.bukkit.entity.Player; + +import com.gmail.nossr50.Users; +import com.gmail.nossr50.mcMMO; + +public class mcSaveTimer implements Runnable { + private final mcMMO plugin; + + public mcSaveTimer(final mcMMO plugin) + { + this.plugin = plugin; + } + + public void run() + { + //All player data will be saved periodically through this + for(Player player : plugin.getServer().getOnlinePlayers()) + { + Users.getProfile(player).save(); + } + } +} \ No newline at end of file