Perf: Deliver claim blocks task.

Now this task never has to read from file.
This commit is contained in:
ryanhamshire 2015-01-14 17:39:44 -08:00
parent 84731dc28e
commit c26e0b3160
2 changed files with 20 additions and 8 deletions

View File

@ -75,12 +75,8 @@ class DeliverClaimBlocksTask implements Runnable
//add blocks //add blocks
int accruedBlocks = GriefPrevention.instance.config_claims_blocksAccruedPerHour / 12; int accruedBlocks = GriefPrevention.instance.config_claims_blocksAccruedPerHour / 12;
if(accruedBlocks < 0) accruedBlocks = 1; if(accruedBlocks < 0) accruedBlocks = 1;
int newTotal = currentTotal + accruedBlocks;
//respect limits playerData.accrueBlocks(accruedBlocks);
if(newTotal > GriefPrevention.instance.config_claims_maxAccruedBlocks) newTotal = GriefPrevention.instance.config_claims_maxAccruedBlocks;
playerData.setAccruedClaimBlocks(newTotal);
//intentionally NOT saving data here to reduce overall secondary storage access frequency //intentionally NOT saving data here to reduce overall secondary storage access frequency
//many other operations will cause this players data to save, including his eventual logout //many other operations will cause this players data to save, including his eventual logout

View File

@ -44,6 +44,9 @@ public class PlayerData
//how many claim blocks the player has earned via play time //how many claim blocks the player has earned via play time
private Integer accruedClaimBlocks = null; private Integer accruedClaimBlocks = null;
//temporary holding area to avoid opening data files too early
private int newlyAccruedClaimBlocks = 0;
//where this player was the last time we checked on him for earning claim blocks //where this player was the last time we checked on him for earning claim blocks
public Location lastAfkCheckLocation = null; public Location lastAfkCheckLocation = null;
@ -160,12 +163,22 @@ public class PlayerData
public int getAccruedClaimBlocks() public int getAccruedClaimBlocks()
{ {
if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage(); if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
return accruedClaimBlocks;
//move any in the holding area
int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
this.newlyAccruedClaimBlocks = 0;
//respect limits
if(newTotal > GriefPrevention.instance.config_claims_maxAccruedBlocks) newTotal = GriefPrevention.instance.config_claims_maxAccruedBlocks;
this.accruedClaimBlocks = newTotal;
return accruedClaimBlocks;
} }
public void setAccruedClaimBlocks(Integer accruedClaimBlocks) public void setAccruedClaimBlocks(Integer accruedClaimBlocks)
{ {
this.accruedClaimBlocks = accruedClaimBlocks; this.accruedClaimBlocks = accruedClaimBlocks;
this.newlyAccruedClaimBlocks = 0;
} }
public int getBonusClaimBlocks() public int getBonusClaimBlocks()
@ -259,5 +272,8 @@ public class PlayerData
return claims; return claims;
} }
public void accrueBlocks(int howMany)
{
this.newlyAccruedClaimBlocks += howMany;
}
} }