From ca80a7d463c4f9d5201c809aa6efab373466ca7d Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 9 Feb 2012 03:11:18 -0800 Subject: [PATCH 1/4] 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 From a419c4d4fe77f3026c40fd4f61068bb8088099f1 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 9 Feb 2012 03:16:55 -0800 Subject: [PATCH 2/4] Forgot to commit this file. --- .../java/com/gmail/nossr50/listeners/mcPlayerListener.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index ac81f5b9f..db3a5b9dd 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -155,6 +155,10 @@ public class mcPlayerListener implements Listener mmoHelper.containers.remove(player); } + //Save PlayerData to MySQL/FlatFile on player quit + Users.getProfile(player).save(); + + //Remove PlayerProfile Users.removeUser(event.getPlayer()); } From e99b5a4abfc6d559176f5a24b024750b9cf4cc15 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 9 Feb 2012 03:31:44 -0800 Subject: [PATCH 3/4] Changed tab to 4 spaces. --- src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java index e4bb109db..808d27fa0 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java @@ -34,7 +34,7 @@ public class mcSaveTimer implements Runnable { //All player data will be saved periodically through this for(Player player : plugin.getServer().getOnlinePlayers()) { - Users.getProfile(player).save(); + Users.getProfile(player).save(); } } } \ No newline at end of file From 0b4692e3032764429cd7d561d1001c252a90855f Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 9 Feb 2012 03:42:08 -0800 Subject: [PATCH 4/4] Hopefully the remaining tabs are now spaces... eclipse is being odd. --- .../com/gmail/nossr50/runnables/mcSaveTimer.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java index 808d27fa0..1ab5e4ddf 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java @@ -22,7 +22,7 @@ import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; public class mcSaveTimer implements Runnable { - private final mcMMO plugin; + private final mcMMO plugin; public mcSaveTimer(final mcMMO plugin) { @@ -31,10 +31,10 @@ public class mcSaveTimer implements Runnable { public void run() { - //All player data will be saved periodically through this - for(Player player : plugin.getServer().getOnlinePlayers()) - { - Users.getProfile(player).save(); - } + //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