From eceeaf1dca28f6eb686eda28369c0bd780dc4984 Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Sun, 22 May 2022 02:46:56 +0200 Subject: [PATCH] Fix subclaims not deleting when converting to a temp claim --- .../CleanupUnusedClaimTask.java | 209 +++++++++--------- 1 file changed, 105 insertions(+), 104 deletions(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java index 9e1313e..fccd783 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java @@ -1,104 +1,105 @@ -/* - 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 . - */ - -package me.ryanhamshire.GriefPrevention; - -import me.ryanhamshire.GriefPrevention.alttd.config.Config; -import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; - -import java.util.Calendar; -import java.util.Date; -import java.util.Vector; - -class CleanupUnusedClaimTask implements Runnable -{ - Claim claim; - PlayerData ownerData; - OfflinePlayer ownerInfo; - boolean forced; - - CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo) - { - this(claim, ownerData, ownerInfo, false); - } - - CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo, boolean forced) - { - this.claim = claim; - this.ownerData = ownerData; - this.ownerInfo = ownerInfo; - this.forced = forced; - } - - @Override - public void run() - { - - //if configured to always remove claims after some inactivity period without exceptions... - if (GriefPrevention.instance.config_claims_expirationDays > 0) - { - Calendar earliestPermissibleLastLogin = Calendar.getInstance(); - earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays); - - if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())) || forced) - { - if (expireEventCanceled()) - return; - //make a copy of this player's claim list - Vector claims = new Vector<>(ownerData.getClaims()); - // Alternative logic for deleting claims - if(Config.alternativeClaimExpiring) { - 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); - Config.addExpiringClaim(claim.id); - } - 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; - } - //delete them - GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true); - GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity); - GriefPrevention.AddLogEntry("earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin.getTime(), CustomLogEntryTypes.Debug, true); - GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true); - } - } - } - - 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(); - } -} +/* + 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 . + */ + +package me.ryanhamshire.GriefPrevention; + +import me.ryanhamshire.GriefPrevention.alttd.config.Config; +import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; + +import java.util.Calendar; +import java.util.Date; +import java.util.Vector; + +class CleanupUnusedClaimTask implements Runnable +{ + Claim claim; + PlayerData ownerData; + OfflinePlayer ownerInfo; + boolean forced; + + CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo) + { + this(claim, ownerData, ownerInfo, false); + } + + CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo, boolean forced) + { + this.claim = claim; + this.ownerData = ownerData; + this.ownerInfo = ownerInfo; + this.forced = forced; + } + + @Override + public void run() + { + + //if configured to always remove claims after some inactivity period without exceptions... + if (GriefPrevention.instance.config_claims_expirationDays > 0) + { + Calendar earliestPermissibleLastLogin = Calendar.getInstance(); + earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays); + + if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())) || forced) + { + if (expireEventCanceled()) + return; + //make a copy of this player's claim list + Vector claims = new Vector<>(ownerData.getClaims()); + // Alternative logic for deleting claims + if(Config.alternativeClaimExpiring) { + for (Claim claim : claims) + { + // remove all subclaims a claim has +// for (int j = 1; (j - 1) < claim.children.size(); j++) + for (Claim subClaim : claim.children) + { + GriefPrevention.instance.dataStore.deleteClaim(subClaim, false, 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); + Config.addExpiringClaim(claim.id); + } + 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; + } + //delete them + GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true); + GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity); + GriefPrevention.AddLogEntry("earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin.getTime(), CustomLogEntryTypes.Debug, true); + GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true); + } + } + } + + 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(); + } +}