From e9be7b4534ded7b9df8058c6dbfb8636edd5d55d Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Tue, 13 Jul 2021 10:43:20 +0800 Subject: [PATCH] Impl GriefPrevention integration#delete-on-unclaim and delete-on-claim-expired --- .../org/maxgamer/quickshop/QuickShop.java | 5 +++ .../GriefPreventionIntegration.java | 43 +++++++++++++++++++ src/main/resources/config.yml | 6 ++- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 41c2d1f7b..a992b5ad4 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1859,6 +1859,11 @@ public class QuickShop extends JavaPlugin { getConfig().set("unlimited-shop-owner-change-account", "quickshop"); getConfig().set("config-version", ++selectedVersion); } + if (selectedVersion == 133) { + getConfig().set("integration.griefprevention.delete-on-unclaim", false); + getConfig().set("integration.griefprevention.delete-on-claim-expired", 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 e99482b16..c49367079 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java @@ -21,12 +21,15 @@ package org.maxgamer.quickshop.integration.griefprevention; import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.GriefPrevention; +import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; +import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.jetbrains.annotations.NotNull; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.integration.IntegrateStage; @@ -45,12 +48,16 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { private final List tradeLimits = new ArrayList<>(3); private final boolean whiteList; private final boolean deleteOnUntrusted; + private final boolean deleteOnUnClaim; + private final boolean deleteOnClaimExpired; public GriefPreventionIntegration(QuickShop plugin) { super(plugin); ConfigurationSection configurationSection = plugin.getConfig(); this.whiteList = configurationSection.getBoolean("integration.griefprevention.whitelist-mode"); 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"); createLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.create"))); tradeLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.trade"))); } @@ -138,6 +145,42 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { } } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onUnclaimed(ClaimDeletedEvent event) { + if (!deleteOnUnClaim) { + return; + } + Claim claim = event.getClaim(); + for (Chunk chunk : claim.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null && !shops.isEmpty()) { + for (Shop shop : shops.values()) { + if (griefPrevention.dataStore.getClaimAt(shop.getLocation(), true, true, null) == null) { + shop.delete(); + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onUnclaimed(ClaimExpirationEvent event) { + if (!deleteOnClaimExpired) { + return; + } + Claim claim = event.getClaim(); + for (Chunk chunk : claim.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null && !shops.isEmpty()) { + for (Shop shop : shops.values()) { + if (griefPrevention.dataStore.getClaimAt(shop.getLocation(), true, true, null) == null) { + shop.delete(); + } + } + } + } + } + @Override public void load() { this.registerListener(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fe6fcf9e3..57849258e 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: 133 +config-version: 134 #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. @@ -693,6 +693,10 @@ integration: trade: [ ] #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 + #Should QuickShop delete shops if claim has been expired? + delete-on-claim-expired: true #Residence Integration residence: enable: false