From ed3347ab9bf9f57e0855c455910353969cbe5b8d Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Wed, 11 Feb 2015 16:00:44 -0800 Subject: [PATCH] Automatic claim block totals corrections. For settings changes and data fix-ups due to damage done by old bugs. --- .../GriefPrevention/PlayerData.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerData.java b/src/me/ryanhamshire/GriefPrevention/PlayerData.java index 4c1fd54..8441f00 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerData.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerData.java @@ -238,6 +238,13 @@ public class PlayerData if(storageData.accruedClaimBlocks != null) { this.accruedClaimBlocks = storageData.accruedClaimBlocks; + + //ensure at least minimum accrued are accrued (in case of settings changes to increase initial amount) + if(this.accruedClaimBlocks < GriefPrevention.instance.config_claims_initialBlocks) + { + this.accruedClaimBlocks = GriefPrevention.instance.config_claims_initialBlocks; + } + } else { @@ -266,12 +273,37 @@ public class PlayerData //find all the claims belonging to this player and note them for future reference DataStore dataStore = GriefPrevention.instance.dataStore; + int totalClaimsArea = 0; for(int i = 0; i < dataStore.claims.size(); i++) { Claim claim = dataStore.claims.get(i); if(playerID.equals(claim.ownerID)) { this.claims.add(claim); + totalClaimsArea += claim.getArea(); + } + } + + //ensure player has claim blocks for his claims, and at least the minimum accrued + this.loadDataFromSecondaryStorage(); + + //if total claimed area is more than total blocks available + int totalBlocks = this.accruedClaimBlocks + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID); + if(totalBlocks < totalClaimsArea) + { + //try to fix it by adding to accrued blocks + this.accruedClaimBlocks = totalClaimsArea; + if(this.accruedClaimBlocks > GriefPrevention.instance.config_claims_maxAccruedBlocks) + { + //remember to respect the maximum on accrued blocks + this.accruedClaimBlocks = GriefPrevention.instance.config_claims_maxAccruedBlocks; + } + + //if that didn't fix it, then make up the difference with bonus blocks + totalBlocks = this.accruedClaimBlocks + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID); + if(totalBlocks < totalClaimsArea) + { + this.bonusClaimBlocks += totalClaimsArea - totalBlocks; } } }