Impl GriefPrevention integration#delete-on-unclaim and delete-on-claim-expired

This commit is contained in:
Ghost_chu committed 2021-07-13 10:43:20 +08:00
1 parent 2ae108dd98
commit e9be7b4534
3 files changed
+53 -1

No files matched your search

@@ -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")) {
@@ -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<Flag> 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<Location, Shop> 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<Location, Shop> 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();
+5 -1
View File
@@ -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