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
|
GriefPrevention Server Plugin for Minecraft
|
||||||
Copyright (C) 2012 Ryan Hamshire
|
Copyright (C) 2012 Ryan Hamshire
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.ryanhamshire.GriefPrevention;
|
package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
||||||
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
|
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
class CleanupUnusedClaimTask implements Runnable
|
class CleanupUnusedClaimTask implements Runnable
|
||||||
{
|
{
|
||||||
Claim claim;
|
Claim claim;
|
||||||
PlayerData ownerData;
|
PlayerData ownerData;
|
||||||
OfflinePlayer ownerInfo;
|
OfflinePlayer ownerInfo;
|
||||||
boolean forced;
|
boolean forced;
|
||||||
|
|
||||||
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo)
|
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo)
|
||||||
{
|
{
|
||||||
this(claim, ownerData, ownerInfo, false);
|
this(claim, ownerData, ownerInfo, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo, boolean forced)
|
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo, boolean forced)
|
||||||
{
|
{
|
||||||
this.claim = claim;
|
this.claim = claim;
|
||||||
this.ownerData = ownerData;
|
this.ownerData = ownerData;
|
||||||
this.ownerInfo = ownerInfo;
|
this.ownerInfo = ownerInfo;
|
||||||
this.forced = forced;
|
this.forced = forced;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
|
||||||
//if configured to always remove claims after some inactivity period without exceptions...
|
//if configured to always remove claims after some inactivity period without exceptions...
|
||||||
if (GriefPrevention.instance.config_claims_expirationDays > 0)
|
if (GriefPrevention.instance.config_claims_expirationDays > 0)
|
||||||
{
|
{
|
||||||
Calendar earliestPermissibleLastLogin = Calendar.getInstance();
|
Calendar earliestPermissibleLastLogin = Calendar.getInstance();
|
||||||
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays);
|
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays);
|
||||||
|
|
||||||
if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())) || forced)
|
if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())) || forced)
|
||||||
{
|
{
|
||||||
if (expireEventCanceled())
|
if (expireEventCanceled())
|
||||||
return;
|
return;
|
||||||
//make a copy of this player's claim list
|
//make a copy of this player's claim list
|
||||||
Vector<Claim> claims = new Vector<>(ownerData.getClaims());
|
Vector<Claim> claims = new Vector<>(ownerData.getClaims());
|
||||||
// Alternative logic for deleting claims
|
// Alternative logic for deleting claims
|
||||||
if(Config.alternativeClaimExpiring) {
|
if(Config.alternativeClaimExpiring) {
|
||||||
for (Claim claim : claims)
|
for (Claim claim : claims)
|
||||||
{
|
{
|
||||||
// remove all subclaims a claim has
|
// remove all subclaims a claim has
|
||||||
for (int j = 1; (j - 1) < claim.children.size(); j++)
|
// for (int j = 1; (j - 1) < claim.children.size(); j++)
|
||||||
{
|
for (Claim subClaim : claim.children)
|
||||||
GriefPrevention.instance.dataStore.deleteClaim(claim.children.get(j - 1), true);
|
{
|
||||||
}
|
GriefPrevention.instance.dataStore.deleteClaim(subClaim, false, true);
|
||||||
// remove all trusted players
|
}
|
||||||
claim.clearPermissions();
|
// remove all trusted players
|
||||||
// public trust
|
claim.clearPermissions();
|
||||||
claim.setPermission("public", ClaimPermission.Build);
|
// public trust
|
||||||
// make the claim an (expiring) admin claim
|
claim.setPermission("public", ClaimPermission.Build);
|
||||||
GriefPrevention.instance.dataStore.changeClaimOwner(claim, null);
|
// make the claim an (expiring) admin claim
|
||||||
Config.addExpiringClaim(claim.id);
|
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(" All of " + claim.getOwnerName() + "'s claims have expired and converted to a temp claim.", CustomLogEntryTypes.AdminActivity);
|
||||||
GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true);
|
GriefPrevention.AddLogEntry("earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin.getTime(), CustomLogEntryTypes.Debug, true);
|
||||||
return;
|
GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true);
|
||||||
}
|
return;
|
||||||
//delete them
|
}
|
||||||
GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true);
|
//delete them
|
||||||
GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity);
|
GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true);
|
||||||
GriefPrevention.AddLogEntry("earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin.getTime(), CustomLogEntryTypes.Debug, true);
|
GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity);
|
||||||
GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true);
|
GriefPrevention.AddLogEntry("earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin.getTime(), CustomLogEntryTypes.Debug, true);
|
||||||
}
|
GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public boolean expireEventCanceled()
|
|
||||||
{
|
public boolean expireEventCanceled()
|
||||||
//see if any other plugins don't want this claim deleted
|
{
|
||||||
ClaimExpirationEvent event = new ClaimExpirationEvent(this.claim);
|
//see if any other plugins don't want this claim deleted
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
ClaimExpirationEvent event = new ClaimExpirationEvent(this.claim);
|
||||||
return event.isCancelled();
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
}
|
return event.isCancelled();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user