Perf: Delivering claim blocks.

Calling less often, doing less work each call.  Estimated 75% cost
reduction.
This commit is contained in:
ryanhamshire 2015-04-26 18:14:01 -07:00
parent b53ec39fbb
commit e353afb1a7
3 changed files with 13 additions and 12 deletions

View File

@ -41,8 +41,6 @@ class DeliverClaimBlocksTask implements Runnable
//if no player specified, this task will create a player-specific task for each online player, scheduled one tick apart //if no player specified, this task will create a player-specific task for each online player, scheduled one tick apart
if(this.player == null && GriefPrevention.instance.config_claims_blocksAccruedPerHour > 0) if(this.player == null && GriefPrevention.instance.config_claims_blocksAccruedPerHour > 0)
{ {
GriefPrevention.AddLogEntry("Delivering claim blocks to active players...", CustomLogEntryTypes.Debug, true);
Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers(); Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
long i = 0; long i = 0;
@ -59,26 +57,20 @@ class DeliverClaimBlocksTask implements Runnable
DataStore dataStore = GriefPrevention.instance.dataStore; DataStore dataStore = GriefPrevention.instance.dataStore;
PlayerData playerData = dataStore.getPlayerData(player.getUniqueId()); PlayerData playerData = dataStore.getPlayerData(player.getUniqueId());
//if player is over accrued limit, accrued limit was probably reduced in config file AFTER he accrued
//in that case, leave his blocks where they are
int currentTotal = playerData.getAccruedClaimBlocks();
if(currentTotal >= GriefPrevention.instance.config_claims_maxAccruedBlocks) return;
Location lastLocation = playerData.lastAfkCheckLocation; Location lastLocation = playerData.lastAfkCheckLocation;
try try
{ {
//if he's not in a vehicle and has moved at least three blocks since the last check //if he's not in a vehicle and has moved at least three blocks since the last check
//and he's not being pushed around by fluids //and he's not being pushed around by fluids
if(!player.isInsideVehicle() && if(!player.isInsideVehicle() &&
(lastLocation == null || lastLocation.distanceSquared(player.getLocation()) >= 9) && (lastLocation == null || lastLocation.distanceSquared(player.getLocation()) >= 0) &&
!player.getLocation().getBlock().isLiquid()) !player.getLocation().getBlock().isLiquid())
{ {
//add blocks //add blocks
int accruedBlocks = GriefPrevention.instance.config_claims_blocksAccruedPerHour / 12; int accruedBlocks = GriefPrevention.instance.config_claims_blocksAccruedPerHour / 6;
if(accruedBlocks < 0) accruedBlocks = 1; if(accruedBlocks < 0) accruedBlocks = 1;
GriefPrevention.AddLogEntry(accruedBlocks + " for " + player.getName(), CustomLogEntryTypes.Debug, true); GriefPrevention.AddLogEntry("Delivering " + accruedBlocks + " blocks to " + player.getName(), CustomLogEntryTypes.Debug, true);
playerData.accrueBlocks(accruedBlocks); playerData.accrueBlocks(accruedBlocks);

View File

@ -285,7 +285,7 @@ public class GriefPrevention extends JavaPlugin
if(this.config_claims_blocksAccruedPerHour > 0) if(this.config_claims_blocksAccruedPerHour > 0)
{ {
DeliverClaimBlocksTask task = new DeliverClaimBlocksTask(null); DeliverClaimBlocksTask task = new DeliverClaimBlocksTask(null);
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task, 20L * 60 * 5, 20L * 60 * 5); this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task, 20L * 60 * 10, 20L * 60 * 10);
} }
//start the recurring cleanup event for entities in creative worlds //start the recurring cleanup event for entities in creative worlds

View File

@ -172,6 +172,15 @@ public class PlayerData
{ {
if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage(); if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
//if player is over accrued limit, accrued limit was probably reduced in config file AFTER he accrued
//in that case, leave his blocks where they are
int currentTotal = this.accruedClaimBlocks;
if(currentTotal >= GriefPrevention.instance.config_claims_maxAccruedBlocks)
{
this.newlyAccruedClaimBlocks = 0;
return currentTotal;
}
//move any in the holding area //move any in the holding area
int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks; int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
this.newlyAccruedClaimBlocks = 0; this.newlyAccruedClaimBlocks = 0;