2016-01-15 18:06:34 +00:00
/ *
GriefPrevention Server Plugin for Minecraft
Copyright ( C ) 2012 Ryan Hamshire
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
* /
package me.ryanhamshire.GriefPrevention ;
import org.bukkit.Bukkit ;
2016-04-16 04:16:33 +00:00
import org.bukkit.OfflinePlayer ;
2016-01-15 18:06:34 +00:00
//asynchronously loads player data without caching it in the datastore, then
//passes those data to a claim cleanup task which might decide to delete a claim for inactivity
class CleanupUnusedClaimPreTask implements Runnable
{
private Claim claim = null ;
CleanupUnusedClaimPreTask ( Claim claim )
{
this . claim = claim ;
}
@Override
public void run ( )
{
//get the data
PlayerData ownerData = GriefPrevention . instance . dataStore . getPlayerDataFromStorage ( claim . ownerID ) ;
2016-04-16 04:16:33 +00:00
OfflinePlayer ownerInfo = Bukkit . getServer ( ) . getOfflinePlayer ( claim . ownerID ) ;
2016-01-15 18:06:34 +00:00
2016-05-04 23:46:48 +00:00
//expiration code uses last logout timestamp to decide whether to expire claims
//don't expire claims for online players
if ( ownerInfo . isOnline ( ) ) return ;
2016-10-08 22:49:17 +00:00
if ( ownerInfo . getLastPlayed ( ) < = 0 ) return ;
2016-05-04 23:46:48 +00:00
2016-03-31 03:29:43 +00:00
GriefPrevention . AddLogEntry ( " Looking for expired claims. Checking data for " + claim . ownerID . toString ( ) , CustomLogEntryTypes . Debug , true ) ;
2016-01-15 18:06:34 +00:00
//skip claims belonging to exempted players based on block totals in config
int bonusBlocks = ownerData . getBonusClaimBlocks ( ) ;
2016-03-31 03:29:43 +00:00
if ( bonusBlocks > = GriefPrevention . instance . config_claims_expirationExemptionBonusBlocks | | bonusBlocks + ownerData . getAccruedClaimBlocks ( ) > = GriefPrevention . instance . config_claims_expirationExemptionTotalBlocks )
{
GriefPrevention . AddLogEntry ( " Player exempt from claim expiration based on claim block counts vs. config file settings. " , CustomLogEntryTypes . Debug , true ) ;
return ;
}
2016-01-15 18:06:34 +00:00
//pass it back to the main server thread, where it's safe to delete a claim if needed
2016-04-16 04:16:33 +00:00
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( GriefPrevention . instance , new CleanupUnusedClaimTask ( claim , ownerData , ownerInfo ) , 1L ) ;
2016-01-15 18:06:34 +00:00
}
}