mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Merge pull request #138 from nossr50/master
Optimizing how mcMMO saves player information
This commit is contained in:
commit
ee83e93269
@ -778,7 +778,6 @@ public class PlayerProfile
|
|||||||
public long getGreenTerraDeactivatedTimeStamp() {return greenTerraDATS;}
|
public long getGreenTerraDeactivatedTimeStamp() {return greenTerraDATS;}
|
||||||
public void setGreenTerraDeactivatedTimeStamp(Long newvalue){
|
public void setGreenTerraDeactivatedTimeStamp(Long newvalue){
|
||||||
greenTerraDATS = (int) (newvalue/1000);
|
greenTerraDATS = (int) (newvalue/1000);
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* BERSERK MODE
|
* BERSERK MODE
|
||||||
@ -800,7 +799,6 @@ public class PlayerProfile
|
|||||||
public long getBerserkDeactivatedTimeStamp() {return berserkDATS;}
|
public long getBerserkDeactivatedTimeStamp() {return berserkDATS;}
|
||||||
public void setBerserkDeactivatedTimeStamp(Long newvalue){
|
public void setBerserkDeactivatedTimeStamp(Long newvalue){
|
||||||
berserkDATS = (int) (newvalue/1000);
|
berserkDATS = (int) (newvalue/1000);
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* SKULL SPLITTER
|
* SKULL SPLITTER
|
||||||
@ -822,7 +820,6 @@ public class PlayerProfile
|
|||||||
public long getSkullSplitterDeactivatedTimeStamp() {return skullSplitterDATS;}
|
public long getSkullSplitterDeactivatedTimeStamp() {return skullSplitterDATS;}
|
||||||
public void setSkullSplitterDeactivatedTimeStamp(Long newvalue){
|
public void setSkullSplitterDeactivatedTimeStamp(Long newvalue){
|
||||||
skullSplitterDATS = (int) (newvalue/1000);
|
skullSplitterDATS = (int) (newvalue/1000);
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* SERRATED STRIKES
|
* SERRATED STRIKES
|
||||||
@ -844,7 +841,6 @@ public class PlayerProfile
|
|||||||
public long getSerratedStrikesDeactivatedTimeStamp() {return serratedStrikesDATS;}
|
public long getSerratedStrikesDeactivatedTimeStamp() {return serratedStrikesDATS;}
|
||||||
public void setSerratedStrikesDeactivatedTimeStamp(Long newvalue){
|
public void setSerratedStrikesDeactivatedTimeStamp(Long newvalue){
|
||||||
serratedStrikesDATS = (int) (newvalue/1000);
|
serratedStrikesDATS = (int) (newvalue/1000);
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* GIGA DRILL BREAKER
|
* GIGA DRILL BREAKER
|
||||||
@ -866,7 +862,6 @@ public class PlayerProfile
|
|||||||
public long getGigaDrillBreakerDeactivatedTimeStamp() {return gigaDrillBreakerDATS;}
|
public long getGigaDrillBreakerDeactivatedTimeStamp() {return gigaDrillBreakerDATS;}
|
||||||
public void setGigaDrillBreakerDeactivatedTimeStamp(Long newvalue){
|
public void setGigaDrillBreakerDeactivatedTimeStamp(Long newvalue){
|
||||||
gigaDrillBreakerDATS = (int) (newvalue/1000);
|
gigaDrillBreakerDATS = (int) (newvalue/1000);
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* TREE FELLER STUFF
|
* TREE FELLER STUFF
|
||||||
@ -888,7 +883,6 @@ public class PlayerProfile
|
|||||||
public long getTreeFellerDeactivatedTimeStamp() {return treeFellerDATS;}
|
public long getTreeFellerDeactivatedTimeStamp() {return treeFellerDATS;}
|
||||||
public void setTreeFellerDeactivatedTimeStamp(Long newvalue){
|
public void setTreeFellerDeactivatedTimeStamp(Long newvalue){
|
||||||
treeFellerDATS = (int) (newvalue/1000);
|
treeFellerDATS = (int) (newvalue/1000);
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* MINING
|
* MINING
|
||||||
@ -910,7 +904,6 @@ public class PlayerProfile
|
|||||||
public long getSuperBreakerDeactivatedTimeStamp() {return superBreakerDATS;}
|
public long getSuperBreakerDeactivatedTimeStamp() {return superBreakerDATS;}
|
||||||
public void setSuperBreakerDeactivatedTimeStamp(Long newvalue){
|
public void setSuperBreakerDeactivatedTimeStamp(Long newvalue){
|
||||||
superBreakerDATS = (int) (newvalue/1000);
|
superBreakerDATS = (int) (newvalue/1000);
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
public long getRecentlyHurt(){
|
public long getRecentlyHurt(){
|
||||||
return recentlyHurt;
|
return recentlyHurt;
|
||||||
@ -921,7 +914,6 @@ public class PlayerProfile
|
|||||||
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();
|
|
||||||
}
|
}
|
||||||
public Integer getSkillLevel(SkillType skillType)
|
public Integer getSkillLevel(SkillType skillType)
|
||||||
{
|
{
|
||||||
@ -1058,7 +1050,6 @@ public class PlayerProfile
|
|||||||
skillsXp.put(skillType, skillsXp.get(skillType)+xp);
|
skillsXp.put(skillType, skillsXp.get(skillType)+xp);
|
||||||
lastgained = skillType;
|
lastgained = skillType;
|
||||||
}
|
}
|
||||||
//save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeXP(SkillType skillType, int newvalue)
|
public void removeXP(SkillType skillType, int newvalue)
|
||||||
@ -1080,7 +1071,6 @@ public class PlayerProfile
|
|||||||
} else {
|
} else {
|
||||||
skillsXp.put(skillType, skillsXp.get(skillType)-newvalue);
|
skillsXp.put(skillType, skillsXp.get(skillType)-newvalue);
|
||||||
}
|
}
|
||||||
//save();
|
|
||||||
}
|
}
|
||||||
public void acceptInvite()
|
public void acceptInvite()
|
||||||
{
|
{
|
||||||
@ -1126,7 +1116,6 @@ public class PlayerProfile
|
|||||||
skills.put(skillType, newvalue);
|
skills.put(skillType, newvalue);
|
||||||
skillsXp.put(skillType, newvalue);
|
skillsXp.put(skillType, newvalue);
|
||||||
}
|
}
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
public Integer getXpToLevel(SkillType skillType)
|
public Integer getXpToLevel(SkillType skillType)
|
||||||
{
|
{
|
||||||
@ -1137,14 +1126,12 @@ public class PlayerProfile
|
|||||||
public void setParty(String newParty)
|
public void setParty(String newParty)
|
||||||
{
|
{
|
||||||
party = newParty;
|
party = newParty;
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
//Retrieve the player's party
|
//Retrieve the player's party
|
||||||
public String getParty() {return party;}
|
public String getParty() {return party;}
|
||||||
//Remove party
|
//Remove party
|
||||||
public void removeParty() {
|
public void removeParty() {
|
||||||
party = null;
|
party = null;
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
//Retrieve whether or not the player is in a party
|
//Retrieve whether or not the player is in a party
|
||||||
public boolean inParty()
|
public boolean inParty()
|
||||||
@ -1176,7 +1163,6 @@ public class PlayerProfile
|
|||||||
public void setMySpawn(double x, double y, double z, String myspawnworldlocation){
|
public void setMySpawn(double x, double y, double z, String myspawnworldlocation){
|
||||||
myspawn = x+","+y+","+z;
|
myspawn = x+","+y+","+z;
|
||||||
myspawnworld = myspawnworldlocation;
|
myspawnworld = myspawnworldlocation;
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
public String getX(){
|
public String getX(){
|
||||||
if(myspawn != null)
|
if(myspawn != null)
|
||||||
|
@ -155,6 +155,10 @@ public class mcPlayerListener implements Listener
|
|||||||
mmoHelper.containers.remove(player);
|
mmoHelper.containers.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Save PlayerData to MySQL/FlatFile on player quit
|
||||||
|
Users.getProfile(player).save();
|
||||||
|
|
||||||
|
//Remove PlayerProfile
|
||||||
Users.removeUser(event.getPlayer());
|
Users.removeUser(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ public class mcMMO extends JavaPlugin
|
|||||||
private final mcEntityListener entityListener = new mcEntityListener(this);
|
private final mcEntityListener entityListener = new mcEntityListener(this);
|
||||||
|
|
||||||
private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION
|
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 Runnable ChangeDataValueTimer = new ChangeDataValueTimer(this); //R2 block place workaround
|
||||||
//private Timer mcMMO_SpellTimer = new Timer(true);
|
//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
|
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!" );
|
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);
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20);
|
||||||
//R2+ block place fix
|
//R2+ block place fix
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10);
|
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10);
|
||||||
|
40
src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java
Normal file
40
src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user