292 lines
13 KiB
Diff
292 lines
13 KiB
Diff
From 5776cb9ef52839ac02c90408afbd3971ba73d330 Mon Sep 17 00:00:00 2001
|
|
From: destro174 <40720638+destro174@users.noreply.github.com>
|
|
Date: Sat, 20 Nov 2021 18:33:37 +0100
|
|
Subject: [PATCH] Add alternative claim expiriation
|
|
|
|
|
|
diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java
|
|
index ce3f1c6..3888956 100644
|
|
--- a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java
|
|
+++ b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java
|
|
@@ -18,6 +18,7 @@
|
|
|
|
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;
|
|
@@ -31,12 +32,19 @@ 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
|
|
@@ -80,13 +88,35 @@ class CleanupUnusedClaimTask implements Runnable
|
|
Calendar earliestPermissibleLastLogin = Calendar.getInstance();
|
|
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays);
|
|
|
|
- if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())))
|
|
+ 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);
|
|
diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
|
|
index 5bd74d8..475e82e 100644
|
|
--- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
|
|
+++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
|
|
@@ -19,6 +19,7 @@
|
|
package me.ryanhamshire.GriefPrevention;
|
|
|
|
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
|
|
+import me.ryanhamshire.GriefPrevention.alttd.ClaimExpireTask;
|
|
import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
|
import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
|
|
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
|
|
@@ -66,6 +67,7 @@ import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.EnumSet;
|
|
import java.util.HashMap;
|
|
+import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map.Entry;
|
|
import java.util.Set;
|
|
@@ -357,6 +359,9 @@ public class GriefPrevention extends JavaPlugin
|
|
FindUnusedClaimsTask task2 = new FindUnusedClaimsTask();
|
|
this.getServer().getScheduler().scheduleSyncRepeatingTask(this, task2, 20L * 60, 20L * config_advanced_claim_expiration_check_rate);
|
|
|
|
+ // start task to clean up temporary admin claims
|
|
+ ClaimExpireTask claimExpireTask = new ClaimExpireTask(this);
|
|
+ claimExpireTask.init();
|
|
//register for events
|
|
PluginManager pluginManager = this.getServer().getPluginManager();
|
|
|
|
@@ -1271,7 +1276,52 @@ public class GriefPrevention extends JavaPlugin
|
|
{
|
|
return this.abandonClaimHandler(player, true);
|
|
}
|
|
+ //forceabandonclaim
|
|
+ if (cmd.getName().equalsIgnoreCase("forceabandonclaim") && player != null)
|
|
+ {
|
|
+ Claim claim = this.dataStore.getClaimAt(player.getLocation(), true /*ignore height*/, true, null);
|
|
+ if (claim == null)
|
|
+ {
|
|
+ GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing);
|
|
+ return true;
|
|
+ }
|
|
+ PlayerData ownerData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(claim.ownerID);
|
|
+ OfflinePlayer ownerInfo = Bukkit.getServer().getOfflinePlayer(claim.ownerID);
|
|
+ Bukkit.getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new CleanupUnusedClaimTask(claim, ownerData, ownerInfo, true), 0);
|
|
+ return true;
|
|
+ }
|
|
+ //abandonsubclaim - remove all subclaims in this claim.
|
|
+ if (cmd.getName().equalsIgnoreCase("abandonsubclaims") && player != null)
|
|
+ {
|
|
+ //which claim is being abandoned?
|
|
+ Claim claim = this.dataStore.getClaimAt(player.getLocation(), true /*ignore height*/, true, null);
|
|
+ if (claim == null)
|
|
+ {
|
|
+ GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AbandonClaimMissing);
|
|
+ return true;
|
|
+ }
|
|
|
|
+ //verify ownership
|
|
+ else if (claim.checkPermission(player, ClaimPermission.Edit, null) != null)
|
|
+ {
|
|
+ GriefPrevention.sendMessage(player, TextMode.Err, Messages.NotYourClaim);
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ if (claim.children.isEmpty()) {
|
|
+ GriefPrevention.sendMessage(player, TextMode.Err, "This claim does not have any subclaims.");
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ // remove all subclaims
|
|
+ for (int j = 0; j < claim.children.size(); j++)
|
|
+ {
|
|
+ GriefPrevention.instance.dataStore.deleteClaim(claim.children.get(j), false);
|
|
+ }
|
|
+ GriefPrevention.sendMessage(player, TextMode.Instr, "Subclaims have been removed.");
|
|
+ Visualization.Revert(player);
|
|
+ return true;
|
|
+ }
|
|
//ignoreclaims
|
|
if (cmd.getName().equalsIgnoreCase("ignoreclaims") && player != null)
|
|
{
|
|
diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/ClaimExpireTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/ClaimExpireTask.java
|
|
new file mode 100644
|
|
index 0000000..402a52d
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/ClaimExpireTask.java
|
|
@@ -0,0 +1,37 @@
|
|
+package me.ryanhamshire.GriefPrevention.alttd;
|
|
+
|
|
+import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
|
+import me.ryanhamshire.GriefPrevention.alttd.config.Config;
|
|
+import org.bukkit.scheduler.BukkitRunnable;
|
|
+
|
|
+import java.util.Iterator;
|
|
+import java.util.Map;
|
|
+
|
|
+public class ClaimExpireTask extends BukkitRunnable
|
|
+{
|
|
+ private GriefPrevention plugin;
|
|
+
|
|
+ public ClaimExpireTask(GriefPrevention plugin)
|
|
+ {
|
|
+ this.plugin = plugin;
|
|
+ }
|
|
+
|
|
+ public void init()
|
|
+ {
|
|
+ runTaskTimer(plugin, 0, Config.expireCheckRate);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run()
|
|
+ {
|
|
+ //Config.expiringClaims.entrySet().removeIf(entry -> System.currentTimeMillis() >= entry.getValue());
|
|
+ for(Iterator<Map.Entry<Long, Long>> it = Config.expiringClaims.entrySet().iterator(); it.hasNext(); ) {
|
|
+ Map.Entry<Long, Long> entry = it.next();
|
|
+ if(System.currentTimeMillis() >= entry.getValue()) {
|
|
+ it.remove();
|
|
+ plugin.getLogger().info("Removed temporary admin claim with id " + entry.getKey());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java
|
|
index a74a9e6..958cd91 100644
|
|
--- a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java
|
|
+++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/AbstractConfig.java
|
|
@@ -75,6 +75,7 @@ abstract class AbstractConfig {
|
|
}
|
|
|
|
void set(String path, Object val) {
|
|
+ yaml.addDefault(path, val);
|
|
yaml.addDefault(path, val);
|
|
yaml.set(path, val);
|
|
}
|
|
diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java
|
|
index fe296b6..6e00e16 100644
|
|
--- a/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java
|
|
+++ b/src/main/java/me/ryanhamshire/GriefPrevention/alttd/config/Config.java
|
|
@@ -1,7 +1,15 @@
|
|
package me.ryanhamshire.GriefPrevention.alttd.config;
|
|
|
|
+import me.ryanhamshire.GriefPrevention.alttd.config.util.Logger;
|
|
+
|
|
+import java.io.IOException;
|
|
+import java.util.HashMap;
|
|
+import java.util.Map;
|
|
+import java.util.concurrent.TimeUnit;
|
|
+
|
|
@SuppressWarnings("unused")
|
|
public class Config extends AbstractConfig {
|
|
+
|
|
private Config() {
|
|
super("alttdconfig.yml");
|
|
}
|
|
@@ -19,8 +27,35 @@ public class Config extends AbstractConfig {
|
|
}
|
|
|
|
public static boolean DEBUG_MODE = false;
|
|
+ public static boolean alternativeClaimExpiring = false;
|
|
+ public static int alternativeClaimExpireDays = 1;
|
|
+ public static int expireCheckRate = 1200;
|
|
+ public static HashMap<Long, Long> expiringClaims = new HashMap<>();
|
|
private static void settings() {
|
|
+ String node = "alternative-claim-expiring";
|
|
DEBUG_MODE = config.getBoolean("debug-mode", DEBUG_MODE);
|
|
+ alternativeClaimExpiring = config.getBoolean(node + ".enabled", alternativeClaimExpiring);
|
|
+ alternativeClaimExpireDays = config.getInt(node + ".days", alternativeClaimExpireDays);
|
|
+ expireCheckRate = config.getInt(node + ".expire-check-rate", expireCheckRate);
|
|
+ // todo create an alternative way of loading these in
|
|
+ expiringClaims.clear();
|
|
+ config.getMap(node + ".claims", new HashMap<String, Long>())
|
|
+ .forEach((key, value) -> {
|
|
+ try {
|
|
+ expiringClaims.put(Long.parseLong(key), value);
|
|
+ } catch (NumberFormatException ignored) {}
|
|
+ });
|
|
+ }
|
|
+
|
|
+ public static void addExpiringClaim(Long id) {
|
|
+ expiringClaims.put(id, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(alternativeClaimExpireDays));
|
|
+ config.set("alternative-claim-expiring.claims", expiringClaims);
|
|
+ try {
|
|
+ config.yaml.save(config.file);
|
|
+ } catch (IOException ex) {
|
|
+ Logger.severe("Could not save " + config.file.getName());
|
|
+ ex.printStackTrace();
|
|
+ }
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
|
|
index b1d0fc1..dae38bd 100644
|
|
--- a/src/main/resources/plugin.yml
|
|
+++ b/src/main/resources/plugin.yml
|
|
@@ -19,6 +19,14 @@ commands:
|
|
description: Deletes ALL your claims.
|
|
usage: /AbandonAllClaims
|
|
permission: griefprevention.claims
|
|
+ abandonsubclaims:
|
|
+ description: Deletes ALL subclaims in the claim you are standing in.
|
|
+ usage: /abandonsubclaims
|
|
+ permission: griefprevention.claims
|
|
+ forceabandonclaim:
|
|
+ description: Forces the claim you are standing in to abandon.
|
|
+ usage: /forceabandonclaim
|
|
+ permission: griefprevention.forceabandonclaim
|
|
trust:
|
|
description: Grants a player full access to your claim(s).
|
|
usage: /Trust <player> Grants a player permission to build. See also /UnTrust, /ContainerTrust, /AccessTrust, and /PermissionTrust.
|
|
--
|
|
2.34.1
|
|
|