From c26e0b316016eccb2460c0a6e148669929fa102b Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Wed, 14 Jan 2015 17:39:44 -0800 Subject: [PATCH] Perf: Deliver claim blocks task. Now this task never has to read from file. --- .../DeliverClaimBlocksTask.java | 6 +---- .../GriefPrevention/PlayerData.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java b/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java index 3fc34e4..0f8d3f6 100644 --- a/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java +++ b/src/me/ryanhamshire/GriefPrevention/DeliverClaimBlocksTask.java @@ -75,12 +75,8 @@ class DeliverClaimBlocksTask implements Runnable //add blocks int accruedBlocks = GriefPrevention.instance.config_claims_blocksAccruedPerHour / 12; if(accruedBlocks < 0) accruedBlocks = 1; - int newTotal = currentTotal + accruedBlocks; - //respect limits - if(newTotal > GriefPrevention.instance.config_claims_maxAccruedBlocks) newTotal = GriefPrevention.instance.config_claims_maxAccruedBlocks; - - playerData.setAccruedClaimBlocks(newTotal); + playerData.accrueBlocks(accruedBlocks); //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 diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerData.java b/src/me/ryanhamshire/GriefPrevention/PlayerData.java index 07a230f..e3efbfe 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerData.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerData.java @@ -44,6 +44,9 @@ public class PlayerData //how many claim blocks the player has earned via play time 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 public Location lastAfkCheckLocation = null; @@ -160,12 +163,22 @@ public class PlayerData public int getAccruedClaimBlocks() { 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) { this.accruedClaimBlocks = accruedClaimBlocks; + this.newlyAccruedClaimBlocks = 0; } public int getBonusClaimBlocks() @@ -258,6 +271,9 @@ public class PlayerData return claims; } - - + + public void accrueBlocks(int howMany) + { + this.newlyAccruedClaimBlocks += howMany; + } } \ No newline at end of file