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/>.
* /
2020-06-09 04:57:55 +00:00
package me.ryanhamshire.GriefPrevention ;
2016-01-15 18:06:34 +00:00
import org.bukkit.Bukkit ;
2016-04-16 04:16:33 +00:00
import org.bukkit.OfflinePlayer ;
2016-01-15 18:06:34 +00:00
2018-09-22 12:21:00 +00:00
import java.util.UUID ;
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
2020-06-09 04:57:55 +00:00
class CleanupUnusedClaimPreTask implements Runnable
{
private UUID ownerID = null ;
CleanupUnusedClaimPreTask ( UUID uuid )
{
this . ownerID = uuid ;
}
@Override
public void run ( )
{
//get the data
PlayerData ownerData = GriefPrevention . instance . dataStore . getPlayerDataFromStorage ( ownerID ) ;
OfflinePlayer ownerInfo = Bukkit . getServer ( ) . getOfflinePlayer ( ownerID ) ;
GriefPrevention . AddLogEntry ( " Looking for expired claims. Checking data for " + ownerID . toString ( ) , CustomLogEntryTypes . Debug , true ) ;
//expiration code uses last logout timestamp to decide whether to expire claims
//don't expire claims for online players
if ( ownerInfo . isOnline ( ) )
{
GriefPrevention . AddLogEntry ( " Player is online. Ignoring. " , CustomLogEntryTypes . Debug , true ) ;
return ;
}
if ( ownerInfo . getLastPlayed ( ) < = 0 )
{
GriefPrevention . AddLogEntry ( " Player is new or not in the server's cached userdata. Ignoring. getLastPlayed = " + ownerInfo . getLastPlayed ( ) , CustomLogEntryTypes . Debug , true ) ;
return ;
}
//skip claims belonging to exempted players based on block totals in config
int bonusBlocks = ownerData . getBonusClaimBlocks ( ) ;
if ( bonusBlocks > = GriefPrevention . instance . config_claims_expirationExemptionBonusBlocks | | bonusBlocks + ownerData . getAccruedClaimBlocks ( ) > = GriefPrevention . instance . config_claims_expirationExemptionTotalBlocks )
2016-03-31 03:29:43 +00:00
{
GriefPrevention . AddLogEntry ( " Player exempt from claim expiration based on claim block counts vs. config file settings. " , CustomLogEntryTypes . Debug , true ) ;
return ;
}
2018-09-22 12:21:00 +00:00
Claim claimToExpire = null ;
2020-06-09 04:57:55 +00:00
for ( Claim claim : GriefPrevention . instance . dataStore . getClaims ( ) )
{
if ( ownerID . equals ( claim . ownerID ) )
{
claimToExpire = claim ;
break ;
}
}
if ( claimToExpire = = null )
{
GriefPrevention . AddLogEntry ( " Unable to find a claim to expire for " + ownerID . toString ( ) , CustomLogEntryTypes . Debug , false ) ;
return ;
}
//pass it back to the main server thread, where it's safe to delete a claim if needed
Bukkit . getScheduler ( ) . scheduleSyncDelayedTask ( GriefPrevention . instance , new CleanupUnusedClaimTask ( claimToExpire , ownerData , ownerInfo ) , 1L ) ;
}
2016-01-15 18:06:34 +00:00
}