From d0a871cced129aca60de553659919450a8ea761f Mon Sep 17 00:00:00 2001 From: 1171066 <1171066@isep.ipp.pt> Date: Tue, 13 Jul 2021 23:51:01 +0100 Subject: [PATCH] Implemented event listener to delete shops if they are outside a Grief Prevention claim when the claim is resized/shrinked. --- .../org/maxgamer/quickshop/QuickShop.java | 4 ++++ .../GriefPreventionIntegration.java | 23 +++++++++++++++++++ src/main/resources/config.yml | 6 +++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index a992b5ad4..fe6f4542b 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1864,6 +1864,10 @@ public class QuickShop extends JavaPlugin { getConfig().set("integration.griefprevention.delete-on-claim-expired", false); getConfig().set("config-version", ++selectedVersion); } + if (selectedVersion == 134) { + getConfig().set("integration.griefprevention.delete-on-claim-resized", false); + getConfig().set("config-version", ++selectedVersion); + } if (getConfig().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) { diff --git a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java index 6b3995d70..ee34782e6 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java @@ -23,6 +23,7 @@ import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.GriefPrevention; import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; +import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -49,6 +50,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { private final boolean deleteOnUntrusted; private final boolean deleteOnUnclaim; private final boolean deleteOnClaimExpired; + private final boolean deleteOnClaimResized; public GriefPreventionIntegration(QuickShop plugin) { super(plugin); @@ -57,6 +59,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { deleteOnUntrusted = configurationSection.getBoolean("integration.griefprevention.delete-on-untrusted"); deleteOnUnclaim = configurationSection.getBoolean("integration.griefprevention.delete-on-unclaim"); deleteOnClaimExpired = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-expired"); + deleteOnClaimResized = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-resized"); createLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.create"))); tradeLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.trade"))); } @@ -147,6 +150,26 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { onUnclaimOrExpiredHelper(event.getClaim(), deleteOnClaimExpired); } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onClaimResized(ClaimModifiedEvent event) { + if (!deleteOnClaimResized) { + return; + } + Claim oldClaim = event.getFrom(); + Claim newClaim = event.getTo(); + for (Chunk chunk : oldClaim.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (oldClaim.contains(shop.getLocation(), true, false) && !newClaim.contains(shop.getLocation(), true, false)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (Resized) #" + shop.getOwner()); + shop.delete(); + } + } + } + } + } + private void onUnclaimOrExpiredHelper(Claim claim, boolean configSectionBoolean) { if (!configSectionBoolean) { return; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 57849258e..b0dca484d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,7 +22,7 @@ # TO EDIT QUICKSHOP'S CONFIGURATION, USE THE "config.yml" FILE! #Do not touch this if you don't know what you're doing! -config-version: 134 +config-version: 135 #Select the language you want to use, (e.g de), use only supported language codes from the list below. #If you use a not existant/not supported language, then QuickShop will use en_US. @@ -694,9 +694,11 @@ integration: #Should QuickShop delete shops if the shop owner has been untrusted on the claim? delete-on-untrusted: true #Should QuickShop delete shops if claim has been deleted? - delete-on-unclaim: false + delete-on-unclaim: true #Should QuickShop delete shops if claim has been expired? delete-on-claim-expired: true + #Should QuickShop delete shops if claim has been resized (claim has become smaller and the shop is now outside claim)? + delete-on-claim-resized: true #Residence Integration residence: enable: false