Some optimizations

As suggested by @bm01 in issue #19:
- Pass PlayerProfile and current time to monitorSkills
- Pass PlayerProfile and current time to watchCooldowns

Testing with only one player seems to indicate a near-negligible increase in performance, but could be useful with more users online.
This commit is contained in:
NuclearW 2012-01-28 21:13:40 -05:00
parent fded7cad96
commit 3fef87923a
2 changed files with 99 additions and 103 deletions

View File

@ -37,6 +37,7 @@ public class mcTimer implements Runnable
public void run() public void run()
{ {
long curTime = System.currentTimeMillis();
for(Player player : plugin.getServer().getOnlinePlayers()) for(Player player : plugin.getServer().getOnlinePlayers())
{ {
if(player == null) if(player == null)
@ -49,12 +50,12 @@ public class mcTimer implements Runnable
/* /*
* MONITOR SKILLS * MONITOR SKILLS
*/ */
Skills.monitorSkills(player); Skills.monitorSkills(player, PP, curTime);
/* /*
* COOLDOWN MONITORING * COOLDOWN MONITORING
*/ */
Skills.watchCooldowns(player); Skills.watchCooldowns(player, PP, curTime);
/* /*
* PLAYER BLEED MONITORING * PLAYER BLEED MONITORING

View File

@ -77,33 +77,32 @@ public class Skills
return (int) (((deactivatedTimeStamp + (cooldown * 1000)) - System.currentTimeMillis())/1000); return (int) (((deactivatedTimeStamp + (cooldown * 1000)) - System.currentTimeMillis())/1000);
} }
public static void watchCooldowns(Player player){ public static void watchCooldowns(Player player, PlayerProfile PP, long curTime){
PlayerProfile PP = Users.getProfile(player); if(!PP.getGreenTerraInformed() && curTime - (PP.getGreenTerraDeactivatedTimeStamp()*1000) >= (LoadProperties.greenTerraCooldown * 1000)){
if(!PP.getGreenTerraInformed() && System.currentTimeMillis() - (PP.getGreenTerraDeactivatedTimeStamp()*1000) >= (LoadProperties.greenTerraCooldown * 1000)){
PP.setGreenTerraInformed(true); PP.setGreenTerraInformed(true);
player.sendMessage(mcLocale.getString("Skills.YourGreenTerra")); player.sendMessage(mcLocale.getString("Skills.YourGreenTerra"));
} }
if(!PP.getTreeFellerInformed() && System.currentTimeMillis() - (PP.getTreeFellerDeactivatedTimeStamp()*1000) >= (LoadProperties.greenTerraCooldown * 1000)){ if(!PP.getTreeFellerInformed() && curTime - (PP.getTreeFellerDeactivatedTimeStamp()*1000) >= (LoadProperties.greenTerraCooldown * 1000)){
PP.setTreeFellerInformed(true); PP.setTreeFellerInformed(true);
player.sendMessage(mcLocale.getString("Skills.YourTreeFeller")); player.sendMessage(mcLocale.getString("Skills.YourTreeFeller"));
} }
if(!PP.getSuperBreakerInformed() && System.currentTimeMillis() - (PP.getSuperBreakerDeactivatedTimeStamp()*1000) >= (LoadProperties.superBreakerCooldown * 1000)){ if(!PP.getSuperBreakerInformed() && curTime - (PP.getSuperBreakerDeactivatedTimeStamp()*1000) >= (LoadProperties.superBreakerCooldown * 1000)){
PP.setSuperBreakerInformed(true); PP.setSuperBreakerInformed(true);
player.sendMessage(mcLocale.getString("Skills.YourSuperBreaker")); player.sendMessage(mcLocale.getString("Skills.YourSuperBreaker"));
} }
if(!PP.getSerratedStrikesInformed() && System.currentTimeMillis() - (PP.getSerratedStrikesDeactivatedTimeStamp()*1000) >= (LoadProperties.serratedStrikeCooldown * 1000)){ if(!PP.getSerratedStrikesInformed() && curTime - (PP.getSerratedStrikesDeactivatedTimeStamp()*1000) >= (LoadProperties.serratedStrikeCooldown * 1000)){
PP.setSerratedStrikesInformed(true); PP.setSerratedStrikesInformed(true);
player.sendMessage(mcLocale.getString("Skills.YourSerratedStrikes")); player.sendMessage(mcLocale.getString("Skills.YourSerratedStrikes"));
} }
if(!PP.getBerserkInformed() && System.currentTimeMillis() - (PP.getBerserkDeactivatedTimeStamp()*1000) >= (LoadProperties.berserkCooldown * 1000)){ if(!PP.getBerserkInformed() && curTime - (PP.getBerserkDeactivatedTimeStamp()*1000) >= (LoadProperties.berserkCooldown * 1000)){
PP.setBerserkInformed(true); PP.setBerserkInformed(true);
player.sendMessage(mcLocale.getString("Skills.YourBerserk")); player.sendMessage(mcLocale.getString("Skills.YourBerserk"));
} }
if(!PP.getSkullSplitterInformed() && System.currentTimeMillis() - (PP.getSkullSplitterDeactivatedTimeStamp()*1000) >= (LoadProperties.skullSplitterCooldown * 1000)){ if(!PP.getSkullSplitterInformed() && curTime - (PP.getSkullSplitterDeactivatedTimeStamp()*1000) >= (LoadProperties.skullSplitterCooldown * 1000)){
PP.setSkullSplitterInformed(true); PP.setSkullSplitterInformed(true);
player.sendMessage(mcLocale.getString("Skills.YourSkullSplitter")); player.sendMessage(mcLocale.getString("Skills.YourSkullSplitter"));
} }
if(!PP.getGigaDrillBreakerInformed() && System.currentTimeMillis() - (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000) >= (LoadProperties.gigaDrillBreakerCooldown * 1000)){ if(!PP.getGigaDrillBreakerInformed() && curTime - (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000) >= (LoadProperties.gigaDrillBreakerCooldown * 1000)){
PP.setGigaDrillBreakerInformed(true); PP.setGigaDrillBreakerInformed(true);
player.sendMessage(mcLocale.getString("Skills.YourGigaDrillBreaker")); player.sendMessage(mcLocale.getString("Skills.YourGigaDrillBreaker"));
} }
@ -126,31 +125,28 @@ public class Skills
PP.setHoePreparationMode(true); PP.setHoePreparationMode(true);
} }
} }
public static void monitorSkills(Player player){ public static void monitorSkills(Player player, PlayerProfile PP, long curTime){
PlayerProfile PP = Users.getProfile(player); if(PP.getHoePreparationMode() && curTime - (PP.getHoePreparationATS()*1000) >= 4000){
if(PP != null)
{
if(PP.getHoePreparationMode() && System.currentTimeMillis() - (PP.getHoePreparationATS()*1000) >= 4000){
PP.setHoePreparationMode(false); PP.setHoePreparationMode(false);
player.sendMessage(mcLocale.getString("Skills.LowerHoe")); player.sendMessage(mcLocale.getString("Skills.LowerHoe"));
} }
if(PP.getAxePreparationMode() && System.currentTimeMillis() - (PP.getAxePreparationATS()*1000) >= 4000){ if(PP.getAxePreparationMode() && curTime - (PP.getAxePreparationATS()*1000) >= 4000){
PP.setAxePreparationMode(false); PP.setAxePreparationMode(false);
player.sendMessage(mcLocale.getString("Skills.LowerAxe")); player.sendMessage(mcLocale.getString("Skills.LowerAxe"));
} }
if(PP.getPickaxePreparationMode() && System.currentTimeMillis() - (PP.getPickaxePreparationATS()*1000) >= 4000){ if(PP.getPickaxePreparationMode() && curTime - (PP.getPickaxePreparationATS()*1000) >= 4000){
PP.setPickaxePreparationMode(false); PP.setPickaxePreparationMode(false);
player.sendMessage(mcLocale.getString("Skills.LowerPickAxe")); player.sendMessage(mcLocale.getString("Skills.LowerPickAxe"));
} }
if(PP.getSwordsPreparationMode() && System.currentTimeMillis() - (PP.getSwordsPreparationATS()*1000) >= 4000){ if(PP.getSwordsPreparationMode() && curTime - (PP.getSwordsPreparationATS()*1000) >= 4000){
PP.setSwordsPreparationMode(false); PP.setSwordsPreparationMode(false);
player.sendMessage(mcLocale.getString("Skills.LowerSword")); player.sendMessage(mcLocale.getString("Skills.LowerSword"));
} }
if(PP.getFistsPreparationMode() && System.currentTimeMillis() - (PP.getFistsPreparationATS()*1000) >= 4000){ if(PP.getFistsPreparationMode() && curTime - (PP.getFistsPreparationATS()*1000) >= 4000){
PP.setFistsPreparationMode(false); PP.setFistsPreparationMode(false);
player.sendMessage(mcLocale.getString("Skills.LowerFists")); player.sendMessage(mcLocale.getString("Skills.LowerFists"));
} }
if(PP.getShovelPreparationMode() && System.currentTimeMillis() - (PP.getShovelPreparationATS()*1000) >= 4000){ if(PP.getShovelPreparationMode() && curTime - (PP.getShovelPreparationATS()*1000) >= 4000){
PP.setShovelPreparationMode(false); PP.setShovelPreparationMode(false);
player.sendMessage(mcLocale.getString("Skills.LowerShovel")); player.sendMessage(mcLocale.getString("Skills.LowerShovel"));
} }
@ -159,7 +155,7 @@ public class Skills
* HERBALISM ABILITY * HERBALISM ABILITY
*/ */
if(mcPermissions.getInstance().herbalismAbility(player)){ if(mcPermissions.getInstance().herbalismAbility(player)){
if(PP.getGreenTerraMode() && (PP.getGreenTerraDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){ if(PP.getGreenTerraMode() && (PP.getGreenTerraDeactivatedTimeStamp()*1000) <= curTime){
PP.setGreenTerraMode(false); PP.setGreenTerraMode(false);
PP.setGreenTerraInformed(false); PP.setGreenTerraInformed(false);
player.sendMessage(mcLocale.getString("Skills.GreenTerraOff")); player.sendMessage(mcLocale.getString("Skills.GreenTerraOff"));
@ -169,7 +165,7 @@ public class Skills
* AXES ABILITY * AXES ABILITY
*/ */
if(mcPermissions.getInstance().axesAbility(player)){ if(mcPermissions.getInstance().axesAbility(player)){
if(PP.getSkullSplitterMode() && (PP.getSkullSplitterDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){ if(PP.getSkullSplitterMode() && (PP.getSkullSplitterDeactivatedTimeStamp()*1000) <= curTime){
PP.setSkullSplitterMode(false); PP.setSkullSplitterMode(false);
PP.setSkullSplitterInformed(false); PP.setSkullSplitterInformed(false);
player.sendMessage(mcLocale.getString("Skills.SkullSplitterOff")); player.sendMessage(mcLocale.getString("Skills.SkullSplitterOff"));
@ -179,7 +175,7 @@ public class Skills
* WOODCUTTING ABILITY * WOODCUTTING ABILITY
*/ */
if(mcPermissions.getInstance().woodCuttingAbility(player)){ if(mcPermissions.getInstance().woodCuttingAbility(player)){
if(PP.getTreeFellerMode() && (PP.getTreeFellerDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){ if(PP.getTreeFellerMode() && (PP.getTreeFellerDeactivatedTimeStamp()*1000) <= curTime){
PP.setTreeFellerMode(false); PP.setTreeFellerMode(false);
PP.setTreeFellerInformed(false); PP.setTreeFellerInformed(false);
player.sendMessage(mcLocale.getString("Skills.TreeFellerOff")); player.sendMessage(mcLocale.getString("Skills.TreeFellerOff"));
@ -189,7 +185,7 @@ public class Skills
* MINING ABILITY * MINING ABILITY
*/ */
if(mcPermissions.getInstance().miningAbility(player)){ if(mcPermissions.getInstance().miningAbility(player)){
if(PP.getSuperBreakerMode() && (PP.getSuperBreakerDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){ if(PP.getSuperBreakerMode() && (PP.getSuperBreakerDeactivatedTimeStamp()*1000) <= curTime){
PP.setSuperBreakerMode(false); PP.setSuperBreakerMode(false);
PP.setSuperBreakerInformed(false); PP.setSuperBreakerInformed(false);
player.sendMessage(mcLocale.getString("Skills.SuperBreakerOff")); player.sendMessage(mcLocale.getString("Skills.SuperBreakerOff"));
@ -199,7 +195,7 @@ public class Skills
* EXCAVATION ABILITY * EXCAVATION ABILITY
*/ */
if(mcPermissions.getInstance().excavationAbility(player)){ if(mcPermissions.getInstance().excavationAbility(player)){
if(PP.getGigaDrillBreakerMode() && (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){ if(PP.getGigaDrillBreakerMode() && (PP.getGigaDrillBreakerDeactivatedTimeStamp()*1000) <= curTime){
PP.setGigaDrillBreakerMode(false); PP.setGigaDrillBreakerMode(false);
PP.setGigaDrillBreakerInformed(false); PP.setGigaDrillBreakerInformed(false);
player.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerOff")); player.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerOff"));
@ -209,7 +205,7 @@ public class Skills
* SWORDS ABILITY * SWORDS ABILITY
*/ */
if(mcPermissions.getInstance().swordsAbility(player)){ if(mcPermissions.getInstance().swordsAbility(player)){
if(PP.getSerratedStrikesMode() && (PP.getSerratedStrikesDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){ if(PP.getSerratedStrikesMode() && (PP.getSerratedStrikesDeactivatedTimeStamp()*1000) <= curTime){
PP.setSerratedStrikesMode(false); PP.setSerratedStrikesMode(false);
PP.setSerratedStrikesInformed(false); PP.setSerratedStrikesInformed(false);
player.sendMessage(mcLocale.getString("Skills.SerratedStrikesOff")); player.sendMessage(mcLocale.getString("Skills.SerratedStrikesOff"));
@ -219,14 +215,13 @@ public class Skills
* UNARMED ABILITY * UNARMED ABILITY
*/ */
if(mcPermissions.getInstance().unarmedAbility(player)){ if(mcPermissions.getInstance().unarmedAbility(player)){
if(PP.getBerserkMode() && (PP.getBerserkDeactivatedTimeStamp()*1000) <= System.currentTimeMillis()){ if(PP.getBerserkMode() && (PP.getBerserkDeactivatedTimeStamp()*1000) <= curTime){
PP.setBerserkMode(false); PP.setBerserkMode(false);
PP.setBerserkInformed(false); PP.setBerserkInformed(false);
player.sendMessage(mcLocale.getString("Skills.BerserkOff")); player.sendMessage(mcLocale.getString("Skills.BerserkOff"));
} }
} }
} }
}
public static void abilityActivationCheck(Player player) public static void abilityActivationCheck(Player player)
{ {
if(LoadProperties.enableOnlyActivateWhenSneaking && !player.isSneaking()) if(LoadProperties.enableOnlyActivateWhenSneaking && !player.isSneaking())