Fix subclaims not deleting when converting to a temp claim
This commit is contained in:
parent
405f7547a6
commit
eceeaf1dca
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Claim> 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Claim> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user