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
2022-02-15 15:41:32 +00:00
import me.ryanhamshire.GriefPrevention.alttd.config.Config ;
2020-06-09 04:57:55 +00:00
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent ;
2016-02-02 21:34:54 +00:00
import org.bukkit.Bukkit ;
2016-04-16 04:16:33 +00:00
import org.bukkit.OfflinePlayer ;
2016-02-02 21:34:54 +00:00
2020-06-09 04:57:55 +00:00
import java.util.Calendar ;
import java.util.Date ;
import java.util.Vector ;
2016-02-02 21:34:54 +00:00
2020-06-09 04:57:55 +00:00
class CleanupUnusedClaimTask implements Runnable
{
2016-01-15 18:06:34 +00:00
Claim claim ;
PlayerData ownerData ;
2016-04-16 04:16:33 +00:00
OfflinePlayer ownerInfo ;
2022-02-15 13:07:31 +00:00
boolean forced ;
2020-06-09 04:57:55 +00:00
CleanupUnusedClaimTask ( Claim claim , PlayerData ownerData , OfflinePlayer ownerInfo )
2022-02-15 13:07:31 +00:00
{
this ( claim , ownerData , ownerInfo , false ) ;
}
CleanupUnusedClaimTask ( Claim claim , PlayerData ownerData , OfflinePlayer ownerInfo , boolean forced )
2020-06-09 04:57:55 +00:00
{
this . claim = claim ;
this . ownerData = ownerData ;
this . ownerInfo = ownerInfo ;
2022-02-15 13:07:31 +00:00
this . forced = forced ;
2020-06-09 04:57:55 +00:00
}
@Override
public void run ( )
{
//if configured to always remove claims after some inactivity period without exceptions...
2022-02-20 00:18:18 +00:00
if ( GriefPrevention . instance . config_claims_expirationDays > 0 )
2020-06-09 04:57:55 +00:00
{
Calendar earliestPermissibleLastLogin = Calendar . getInstance ( ) ;
earliestPermissibleLastLogin . add ( Calendar . DATE , - GriefPrevention . instance . config_claims_expirationDays ) ;
2022-02-15 13:07:31 +00:00
if ( earliestPermissibleLastLogin . getTime ( ) . after ( new Date ( ownerInfo . getLastPlayed ( ) ) ) | | forced )
2020-06-09 04:57:55 +00:00
{
if ( expireEventCanceled ( ) )
return ;
//make a copy of this player's claim list
2020-09-19 21:14:11 +00:00
Vector < Claim > claims = new Vector < > ( ownerData . getClaims ( ) ) ;
2022-02-15 13:07:31 +00:00
// Alternative logic for deleting claims
2022-02-15 15:41:32 +00:00
if ( Config . alternativeClaimExpiring ) {
2022-02-15 13:07:31 +00:00
for ( Claim claim : claims )
{
// remove all subclaims a claim has
for ( int j = 1 ; ( j - 1 ) < claim . children . size ( ) ; j + + )
{
GriefPrevention . instance . dataStore . deleteClaim ( claim . children . get ( j - 1 ) , true ) ;
}
// remove all trusted players
claim . clearPermissions ( ) ;
// public trust
claim . setPermission ( " public " , ClaimPermission . Build ) ;
// make the claim an (expiring) admin claim
GriefPrevention . instance . dataStore . changeClaimOwner ( claim , null ) ;
2022-02-15 15:41:32 +00:00
Config . addExpiringClaim ( claim . id ) ;
2022-02-15 13:07:31 +00:00
}
GriefPrevention . AddLogEntry ( " All of " + claim . getOwnerName ( ) + " 's claims have expired and converted to a temp claim. " , CustomLogEntryTypes . AdminActivity ) ;
GriefPrevention . AddLogEntry ( " earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin . getTime ( ) , CustomLogEntryTypes . Debug , true ) ;
GriefPrevention . AddLogEntry ( " ownerInfo#getLastPlayed: " + ownerInfo . getLastPlayed ( ) , CustomLogEntryTypes . Debug , true ) ;
return ;
}
2020-06-09 04:57:55 +00:00
//delete them
GriefPrevention . instance . dataStore . deleteClaimsForPlayer ( claim . ownerID , true ) ;
GriefPrevention . AddLogEntry ( " All of " + claim . getOwnerName ( ) + " 's claims have expired. " , CustomLogEntryTypes . AdminActivity ) ;
2020-09-14 23:37:20 +00:00
GriefPrevention . AddLogEntry ( " earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin . getTime ( ) , CustomLogEntryTypes . Debug , true ) ;
GriefPrevention . AddLogEntry ( " ownerInfo#getLastPlayed: " + ownerInfo . getLastPlayed ( ) , CustomLogEntryTypes . Debug , true ) ;
2020-06-09 04:57:55 +00:00
}
}
}
public boolean expireEventCanceled ( )
{
//see if any other plugins don't want this claim deleted
ClaimExpirationEvent event = new ClaimExpirationEvent ( this . claim ) ;
Bukkit . getPluginManager ( ) . callEvent ( event ) ;
return event . isCancelled ( ) ;
}
2016-01-15 18:06:34 +00:00
}