Optimized how mcMMO saves player information.

This commit is contained in:
nossr50 2012-02-09 03:11:18 -08:00
parent 716e6296e5
commit ca80a7d463
3 changed files with 44 additions and 14 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}
}