From 6192ca7fe80235919b43cce576783df9642548d5 Mon Sep 17 00:00:00 2001 From: 1171066 <1171066@isep.ipp.pt> Date: Mon, 26 Jul 2021 19:30:53 +0100 Subject: [PATCH 1/6] Big improvements to the Grief Prevention Integration. Fixed some bugs. Refactored some things. --- .../org/maxgamer/quickshop/QuickShop.java | 4 +- .../GriefPreventionIntegration.java | 344 +++++++++++------- src/main/resources/config.yml | 4 +- 3 files changed, 216 insertions(+), 136 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 4584ca2b9..fb06e16ab 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1834,7 +1834,7 @@ public class QuickShop extends JavaPlugin { } if (selectedVersion == 128) { getConfig().set("shop.force-use-item-original-name", false); - getConfig().set("integration.griefprevention.delete-on-untrusted", false); + getConfig().set("integration.griefprevention.delete-on-claim-untrusted", false); getConfig().set("config-version", ++selectedVersion); } @@ -1860,7 +1860,7 @@ public class QuickShop extends JavaPlugin { getConfig().set("config-version", ++selectedVersion); } if (selectedVersion == 133) { - getConfig().set("integration.griefprevention.delete-on-unclaim", false); + getConfig().set("integration.griefprevention.delete-on-claim-unclaimed", false); getConfig().set("integration.griefprevention.delete-on-claim-expired", false); getConfig().set("config-version", ++selectedVersion); } 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 ee34782e6..cfaf468d4 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java @@ -24,6 +24,8 @@ import me.ryanhamshire.GriefPrevention.GriefPrevention; import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent; +import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -43,25 +45,223 @@ import java.util.Map; @IntegrationStage(loadStage = IntegrateStage.onEnableAfter) public class GriefPreventionIntegration extends QSIntegratedPlugin { + final GriefPrevention griefPrevention = GriefPrevention.instance; - private final List createLimits = new ArrayList<>(3); - private final List tradeLimits = new ArrayList<>(3); + private final boolean whiteList; - private final boolean deleteOnUntrusted; - private final boolean deleteOnUnclaim; + + private final boolean deleteOnClaimUntrusted; + + private final boolean deleteOnClaimUnclaimed; + private final boolean deleteOnClaimExpired; + private final boolean deleteOnClaimResized; + private final List createLimits = new ArrayList<>(3); + + private final List tradeLimits = new ArrayList<>(3); + 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"); - 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"))); + this.deleteOnClaimUntrusted = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-untrusted"); + this.deleteOnClaimUnclaimed = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-unclaimed"); + this.deleteOnClaimExpired = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-expired"); + this.deleteOnClaimResized = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-resized"); + this.createLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.create"))); + this.tradeLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.trade"))); + } + + @Override + public @NotNull String getName() { + return "GriefPrevention"; + } + + @Override + public void load() { + registerListener(); + } + + @Override + public void unload() { + unregisterListener(); + } + + @Override + public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { + return checkPermission(player, location, createLimits); + } + + @Override + public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) { + return checkPermission(player, location, tradeLimits); + } + + // When player changes trust, we will check if the shops there will be deleted or not. + // We will not delete the shops of the claim owner. + // The shops will be deleted if the shop owner doesn't have anymore permission to create a shop there. + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onClaimUntrusted(TrustChangedEvent event) { + if (!deleteOnClaimUntrusted) { + return; + } + for (Claim claim : event.getClaims()) { + for (Chunk chunk : claim.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (!shop.getOwner().equals(claim.getOwnerID())) { + Claim shopClaim = griefPrevention.dataStore.getClaimAt(shop.getLocation(), false, false, null); + if (shopClaim != null && + shopClaim.getID().equals(claim.getID()) && + !hasPermissionClaim(shopClaim, Bukkit.getPlayer(shop.getOwner()), createLimits)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (Untrusted) #" + shop.getOwner()); + shop.delete(); + } + } + } + } + } + } + } + + // Player can unclaim the main claim or the subclaim. + // So we need to call either the handleMainClaimUnclaimedOrExpired or the handleSubClaimUnclaimed method. + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onClaimUnclaimed(ClaimDeletedEvent event) { + if (!deleteOnClaimUnclaimed) { + return; + } + if (event.getClaim().parent == null) { + handleMainClaimUnclaimedOrExpired(event.getClaim(), "[SHOP DELETE] GP Integration: Single delete (Claim Unclaimed) #"); + } else { + handleSubClaimUnclaimed(event.getClaim(), event.getClaim().parent); + } + } + + // Since only the main claim expires, we will call the handleMainClaimUnclaimedOrExpired method. + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onClaimExpired(ClaimExpirationEvent event) { + if (!deleteOnClaimExpired) { + return; + } + handleMainClaimUnclaimedOrExpired(event.getClaim(),"[SHOP DELETE] GP Integration: Single delete (Claim Expired) #"); + } + + // Player can resize the main claim or the subclaim. + // So we need to call either the handleMainClaimResized or the handleSubClaimResized method. + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onClaimResized(ClaimModifiedEvent event) { + if (!deleteOnClaimResized) { + return; + } + Claim oldClaim = event.getFrom(); + Claim newClaim = event.getTo(); + if (oldClaim.parent == null) { + handleMainClaimResized(oldClaim, newClaim); + } else { + handleSubClaimResized(oldClaim, newClaim, oldClaim.parent); + } + } + + // If it is the main claim, then we will delete all shops that were inside of it. + private void handleMainClaimUnclaimedOrExpired(Claim claim, String logMessage) { + for (Chunk chunk : claim.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (claim.contains(shop.getLocation(), false, false)) { + plugin.log(logMessage + shop.getOwner()); + shop.delete(); + } + } + } + } + } + + // If it is a subclaim, then we will not remove the shops of the main claim owner. + // Also, we will not remove the shops of the players that have permission to build shops in the main claim. + private void handleSubClaimUnclaimed(Claim subClaim, Claim mainClaim) { + for (Chunk chunk : subClaim.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (subClaim.contains(shop.getLocation(), false, false)) { + if (!shop.getOwner().equals(mainClaim.getOwnerID()) && + !hasPermissionClaim(mainClaim, Bukkit.getPlayer(shop.getOwner()), createLimits)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Unclaimed) #" + shop.getOwner()); + shop.delete(); + } + } + } + } + } + } + + // If it is a main claim, then we will remove the shop if the main claim was resized (size was decreased). + // The shop will be removed if the old claim contains the shop but the new claim doesn't have it. + private void handleMainClaimResized(Claim oldClaim, Claim newClaim) { + for (Chunk chunk : oldClaim.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (oldClaim.contains(shop.getLocation(), false, false) && + !newClaim.contains(shop.getLocation(), false, false)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim Resized) #" + shop.getOwner()); + shop.delete(); + } + } + } + } + } + + // If it is a subclaim, then we will remove the shops in 2 situations. + // We will never remove shops of the claim owner. + // We will remove the shop if the shop is now outside the subclaim and the shop owner doesn't have permission in the main claim. + // We will remove the shop if the shop is now inside the subclaim and the shop owner doesn't have permission in the subclaim. + private void handleSubClaimResized(Claim oldClaim, Claim newClaim, Claim mainClaim) { + handleSubClaimResizedHelper(oldClaim, newClaim, mainClaim); + handleSubClaimResizedHelper(newClaim, oldClaim, newClaim); + } + + private void handleSubClaimResizedHelper(Claim claimVerifyChunks, Claim claimVerifyShop, Claim claimPermissionCheck) { + for (Chunk chunk : claimVerifyChunks.getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (!shop.getOwner().equals(claimVerifyChunks.getOwnerID())) { + if (claimVerifyChunks.contains(shop.getLocation(), false, false) && + !claimVerifyShop.contains(shop.getLocation(), false, false) && + !hasPermissionClaim(claimPermissionCheck, Bukkit.getPlayer(shop.getOwner()), createLimits)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Resized) #" + shop.getOwner()); + shop.delete(); + } + } + } + } + } + } + + private boolean checkPermission(@NotNull Player player, @NotNull Location location, List limits) { + if (!griefPrevention.claimsEnabledForWorld(location.getWorld())) { + return true; + } + Claim claim = griefPrevention.dataStore.getClaimAt(location, false, griefPrevention.dataStore.getPlayerData(player.getUniqueId()).lastClaim); + if (claim == null) { + return !whiteList; + } + return hasPermissionClaim(claim, player, limits); + } + + private boolean hasPermissionClaim(@NotNull Claim claim, Player player, List limits) { + for (Flag flag : limits) { + if (!flag.check(claim, player)) { + return false; + } + } + return true; } private List toFlags(List flags) { @@ -75,129 +275,8 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { return result; } - @Override - public @NotNull String getName() { - return "GriefPrevention"; - } - - @Override - public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { - return checkPermission(player, location, createLimits); - - } - - @Override - public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) { - return checkPermission(player, location, tradeLimits); - } - - private boolean checkPermission(@NotNull Player player, @NotNull Location location, List limits) { - if (!griefPrevention.claimsEnabledForWorld(location.getWorld())) { - return true; - } - Claim claim = griefPrevention.dataStore.getClaimAt(location, false, griefPrevention.dataStore.getPlayerData(player.getUniqueId()).lastClaim); - if (claim == null) { - return !whiteList; - } - for (Flag flag : limits) { - if (!flag.check(claim, player)) { - return false; - } - } - return true; - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onUntrusted(me.ryanhamshire.GriefPrevention.events.TrustChangedEvent event) { - if (!deleteOnUntrusted) { - return; - } - for (Claim claim : event.getClaims()) { - for (Chunk chunk : claim.getChunks()) { - Map shops = plugin.getShopManager().getShops(chunk); - if (shops != null) { - for (Shop shop : shops.values()) { - if (!shop.getOwner().equals(claim.getOwnerID())) { - - Claim shopClaim = griefPrevention.dataStore.getClaimAt(shop.getLocation(), true, false, null); - if(shopClaim != null && shopClaim.getID() == claim.getID()) { - - if(event.getIdentifier().equals(shop.getOwner().toString())) { - plugin.log("[SHOP DELETE] GP Integration: Single delete #" + event.getIdentifier()); - shop.delete(); - } else if(event.getIdentifier().contains(shop.getOwner().toString())) { - plugin.log("[SHOP DELETE] GP Integration: Group delete #" + event.getIdentifier()); - shop.delete(); - } else if("all".equals(event.getIdentifier()) || "public".equals(event.getIdentifier())) { - plugin.log("[SHOP DELETE] GP Integration: All/Public delete #" + event.getIdentifier()); - shop.delete(); - } - } - } - } - } - } - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onClaimUnclaimed(ClaimDeletedEvent event) { - onUnclaimOrExpiredHelper(event.getClaim(), deleteOnUnclaim); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onClaimExpired(ClaimExpirationEvent event) { - 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; - } - for (Chunk chunk : claim.getChunks()) { - Map shops = plugin.getShopManager().getShops(chunk); - if (shops != null) { - for (Shop shop : shops.values()) { - if (claim.contains(shop.getLocation(), true, false)) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (Unclaimed/Expired) #" + shop.getOwner()); - shop.delete(); - } - } - } - } - } - - @Override - public void load() { - this.registerListener(); - } - - @Override - public void unload() { - this.unregisterListener(); - } - enum Flag { + BUILD { @Override boolean check(Claim claim, Player player) { @@ -227,4 +306,5 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { abstract boolean check(Claim claim, Player player); } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2d2604b2a..b4b0e7fad 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -692,9 +692,9 @@ integration: #ACCESS = The Player must have the ability to access the target claim. trade: [ ] #Should QuickShop delete shops if the shop owner has been untrusted on the claim? - delete-on-untrusted: true + delete-on-claim-untrusted: true #Should QuickShop delete shops if claim has been deleted? - delete-on-unclaim: true + delete-on-claim-unclaimed: 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)? From a43abea5279d0619d9b48261bd1a514a8e2e0790 Mon Sep 17 00:00:00 2001 From: 1171066 <1171066@isep.ipp.pt> Date: Tue, 27 Jul 2021 05:19:13 +0100 Subject: [PATCH 2/6] Deleted some features/validation because of some problems found. --- .../org/maxgamer/quickshop/QuickShop.java | 2 +- .../GriefPreventionIntegration.java | 89 +++++++++---------- src/main/resources/config.yml | 19 ++-- 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index fb06e16ab..eb4f0c306 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1834,7 +1834,7 @@ public class QuickShop extends JavaPlugin { } if (selectedVersion == 128) { getConfig().set("shop.force-use-item-original-name", false); - getConfig().set("integration.griefprevention.delete-on-claim-untrusted", false); + getConfig().set("integration.griefprevention.delete-on-claim-trust-changed", false); getConfig().set("config-version", ++selectedVersion); } 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 cfaf468d4..33bae871e 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java @@ -25,7 +25,6 @@ import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent; import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -50,7 +49,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { private final boolean whiteList; - private final boolean deleteOnClaimUntrusted; + private final boolean deleteOnClaimTrustChanged; private final boolean deleteOnClaimUnclaimed; @@ -66,7 +65,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { super(plugin); ConfigurationSection configurationSection = plugin.getConfig(); this.whiteList = configurationSection.getBoolean("integration.griefprevention.whitelist-mode"); - this.deleteOnClaimUntrusted = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-untrusted"); + this.deleteOnClaimTrustChanged = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-trust-changed"); this.deleteOnClaimUnclaimed = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-unclaimed"); this.deleteOnClaimExpired = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-expired"); this.deleteOnClaimResized = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-resized"); @@ -99,12 +98,12 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { return checkPermission(player, location, tradeLimits); } - // When player changes trust, we will check if the shops there will be deleted or not. + // We will check if the shops belong to user/users whose permissions were changed. + // If so, we will delete them. // We will not delete the shops of the claim owner. - // The shops will be deleted if the shop owner doesn't have anymore permission to create a shop there. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onClaimUntrusted(TrustChangedEvent event) { - if (!deleteOnClaimUntrusted) { + public void onClaimTrustChanged(TrustChangedEvent event) { + if (!deleteOnClaimTrustChanged) { return; } for (Claim claim : event.getClaims()) { @@ -112,12 +111,16 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { Map shops = plugin.getShopManager().getShops(chunk); if (shops != null) { for (Shop shop : shops.values()) { - if (!shop.getOwner().equals(claim.getOwnerID())) { - Claim shopClaim = griefPrevention.dataStore.getClaimAt(shop.getLocation(), false, false, null); - if (shopClaim != null && - shopClaim.getID().equals(claim.getID()) && - !hasPermissionClaim(shopClaim, Bukkit.getPlayer(shop.getOwner()), createLimits)) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (Untrusted) #" + shop.getOwner()); + if (!shop.getOwner().equals(claim.getOwnerID()) && + claim.contains(shop.getLocation(), false, false)) { + if (event.getIdentifier().equals(shop.getOwner().toString())) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); + shop.delete(); + } else if (event.getIdentifier().contains(shop.getOwner().toString())) { + plugin.log("[SHOP DELETE] GP Integration: Group delete (Claim/Subclaim Trust Changed)#" + shop.ownerName()); + shop.delete(); + } else if ("all".equals(event.getIdentifier()) || "public".equals(event.getIdentifier())) { + plugin.log("[SHOP DELETE] GP Integration: All/Public delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); shop.delete(); } } @@ -137,7 +140,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { if (event.getClaim().parent == null) { handleMainClaimUnclaimedOrExpired(event.getClaim(), "[SHOP DELETE] GP Integration: Single delete (Claim Unclaimed) #"); } else { - handleSubClaimUnclaimed(event.getClaim(), event.getClaim().parent); + handleSubClaimUnclaimed(event.getClaim()); } } @@ -162,18 +165,18 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { if (oldClaim.parent == null) { handleMainClaimResized(oldClaim, newClaim); } else { - handleSubClaimResized(oldClaim, newClaim, oldClaim.parent); + handleSubClaimResized(oldClaim, newClaim); } } - // If it is the main claim, then we will delete all shops that were inside of it. + // If it is the main claim, then we will delete all the shops that were inside of it. private void handleMainClaimUnclaimedOrExpired(Claim claim, String logMessage) { for (Chunk chunk : claim.getChunks()) { Map shops = plugin.getShopManager().getShops(chunk); if (shops != null) { for (Shop shop : shops.values()) { if (claim.contains(shop.getLocation(), false, false)) { - plugin.log(logMessage + shop.getOwner()); + plugin.log(logMessage + shop.ownerName()); shop.delete(); } } @@ -182,26 +185,24 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { } // If it is a subclaim, then we will not remove the shops of the main claim owner. - // Also, we will not remove the shops of the players that have permission to build shops in the main claim. - private void handleSubClaimUnclaimed(Claim subClaim, Claim mainClaim) { + // But we will remove all the others. + private void handleSubClaimUnclaimed(Claim subClaim) { for (Chunk chunk : subClaim.getChunks()) { Map shops = plugin.getShopManager().getShops(chunk); if (shops != null) { for (Shop shop : shops.values()) { - if (subClaim.contains(shop.getLocation(), false, false)) { - if (!shop.getOwner().equals(mainClaim.getOwnerID()) && - !hasPermissionClaim(mainClaim, Bukkit.getPlayer(shop.getOwner()), createLimits)) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Unclaimed) #" + shop.getOwner()); - shop.delete(); - } + if (!shop.getOwner().equals(subClaim.getOwnerID()) && + subClaim.contains(shop.getLocation(), false, false)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Unclaimed) #" + shop.ownerName()); + shop.delete(); } } } } } - // If it is a main claim, then we will remove the shop if the main claim was resized (size was decreased). - // The shop will be removed if the old claim contains the shop but the new claim doesn't have it. + // If it is a main claim, then we will remove the shops if the main claim was resized (size was decreased). + // A shop will be removed if the old claim contain it but the new claim doesn't. private void handleMainClaimResized(Claim oldClaim, Claim newClaim) { for (Chunk chunk : oldClaim.getChunks()) { Map shops = plugin.getShopManager().getShops(chunk); @@ -209,7 +210,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { for (Shop shop : shops.values()) { if (oldClaim.contains(shop.getLocation(), false, false) && !newClaim.contains(shop.getLocation(), false, false)) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim Resized) #" + shop.getOwner()); + plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim Resized) #" + shop.ownerName()); shop.delete(); } } @@ -218,26 +219,24 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { } // If it is a subclaim, then we will remove the shops in 2 situations. - // We will never remove shops of the claim owner. - // We will remove the shop if the shop is now outside the subclaim and the shop owner doesn't have permission in the main claim. - // We will remove the shop if the shop is now inside the subclaim and the shop owner doesn't have permission in the subclaim. - private void handleSubClaimResized(Claim oldClaim, Claim newClaim, Claim mainClaim) { - handleSubClaimResizedHelper(oldClaim, newClaim, mainClaim); - handleSubClaimResizedHelper(newClaim, oldClaim, newClaim); + // We will never remove the shops of the claim owner. + // We will remove a shop if the shop was inside the subclaim but now it is outside the subclaim. + // We will remove a shop if the shop was outside the subclaim but now it is inside the subclaim. + private void handleSubClaimResized(Claim oldClaim, Claim newClaim) { + handleSubClaimResizedHelper(oldClaim, newClaim); + handleSubClaimResizedHelper(newClaim, oldClaim); } - private void handleSubClaimResizedHelper(Claim claimVerifyChunks, Claim claimVerifyShop, Claim claimPermissionCheck) { + private void handleSubClaimResizedHelper(Claim claimVerifyChunks, Claim claimVerifyShop) { for (Chunk chunk : claimVerifyChunks.getChunks()) { Map shops = plugin.getShopManager().getShops(chunk); if (shops != null) { for (Shop shop : shops.values()) { - if (!shop.getOwner().equals(claimVerifyChunks.getOwnerID())) { - if (claimVerifyChunks.contains(shop.getLocation(), false, false) && - !claimVerifyShop.contains(shop.getLocation(), false, false) && - !hasPermissionClaim(claimPermissionCheck, Bukkit.getPlayer(shop.getOwner()), createLimits)) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Resized) #" + shop.getOwner()); - shop.delete(); - } + if (!shop.getOwner().equals(claimVerifyChunks.getOwnerID()) && + claimVerifyChunks.contains(shop.getLocation(), false, false) && + !claimVerifyShop.contains(shop.getLocation(), false, false)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Resized) #" + shop.ownerName()); + shop.delete(); } } } @@ -248,14 +247,10 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { if (!griefPrevention.claimsEnabledForWorld(location.getWorld())) { return true; } - Claim claim = griefPrevention.dataStore.getClaimAt(location, false, griefPrevention.dataStore.getPlayerData(player.getUniqueId()).lastClaim); + Claim claim = griefPrevention.dataStore.getClaimAt(location, false, false, griefPrevention.dataStore.getPlayerData(player.getUniqueId()).lastClaim); if (claim == null) { return !whiteList; } - return hasPermissionClaim(claim, player, limits); - } - - private boolean hasPermissionClaim(@NotNull Claim claim, Player player, List limits) { for (Flag flag : limits) { if (!flag.check(claim, player)) { return false; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b4b0e7fad..e3a2d9f9e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -691,13 +691,22 @@ integration: #CONTAINER_ACCESS = The player must be able to access containers. #ACCESS = The Player must have the ability to access the target claim. trade: [ ] - #Should QuickShop delete shops if the shop owner has been untrusted on the claim? - delete-on-claim-untrusted: true - #Should QuickShop delete shops if claim has been deleted? + #Should QuickShop delete shops if the trust permission of the shop owner has been changed on the claim/subclaim? + #It will check if the shops belong to user/users whose permissions were changed and will delete them. + #It will never remove a shop of the claim owner. + delete-on-claim-trust-changed: true + #Should QuickShop delete shops if the claim/subclaim has been unclaimed? + #It will remove all the shops that were inside the claim/subclaim that was unclaimed. + #It will never remove a shop of the claim owner when unclaiming a subclaim. delete-on-claim-unclaimed: true - #Should QuickShop delete shops if claim has been expired? + #Should QuickShop delete shops if the claim has been expired? + #It will remove all the shops that were inside the claim. 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)? + #Should QuickShop delete shops if claim/subclaim has been resized? + #It will remove a shop that the old claim contains but the new claim doesn't. + #It will remove a shop if the shop was inside the subclaim but now it is outside the subclaim. + #It will remove a shop if the shop was outside the subclaim but now it is inside the subclaim. + #It will never remove a shop of the claim owner when resizing a subclaim. delete-on-claim-resized: true #Residence Integration residence: From 664022880f2841a60ccd6c6e4011f57def87c6a3 Mon Sep 17 00:00:00 2001 From: 1171066 <1171066@isep.ipp.pt> Date: Tue, 27 Jul 2021 17:01:12 +0100 Subject: [PATCH 3/6] Minor fix in the trust changed event. --- .../GriefPreventionIntegration.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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 33bae871e..31cf68776 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java @@ -111,17 +111,19 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { Map shops = plugin.getShopManager().getShops(chunk); if (shops != null) { for (Shop shop : shops.values()) { - if (!shop.getOwner().equals(claim.getOwnerID()) && - claim.contains(shop.getLocation(), false, false)) { - if (event.getIdentifier().equals(shop.getOwner().toString())) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); - shop.delete(); - } else if (event.getIdentifier().contains(shop.getOwner().toString())) { - plugin.log("[SHOP DELETE] GP Integration: Group delete (Claim/Subclaim Trust Changed)#" + shop.ownerName()); - shop.delete(); - } else if ("all".equals(event.getIdentifier()) || "public".equals(event.getIdentifier())) { - plugin.log("[SHOP DELETE] GP Integration: All/Public delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); - shop.delete(); + if (!shop.getOwner().equals(claim.getOwnerID())) { + Claim shopClaim = griefPrevention.dataStore.getClaimAt(shop.getLocation(), false, false, null); + if (shopClaim != null && shopClaim.getID().equals(claim.getID())) { + if (event.getIdentifier().equals(shop.getOwner().toString())) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); + shop.delete(); + } else if (event.getIdentifier().contains(shop.getOwner().toString())) { + plugin.log("[SHOP DELETE] GP Integration: Group delete (Claim/Subclaim Trust Changed)#" + shop.ownerName()); + shop.delete(); + } else if ("all".equals(event.getIdentifier()) || "public".equals(event.getIdentifier())) { + plugin.log("[SHOP DELETE] GP Integration: All/Public delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); + shop.delete(); + } } } } From d1f6f4074551a83c921b6f83ffb16a0056619661 Mon Sep 17 00:00:00 2001 From: 1171066 <1171066@isep.ipp.pt> Date: Tue, 27 Jul 2021 22:14:31 +0100 Subject: [PATCH 4/6] Improved the Grief Prevention Integration by changing the config file. --- .../org/maxgamer/quickshop/QuickShop.java | 7 ++- .../GriefPreventionIntegration.java | 61 ++++++++++++++----- src/main/resources/config.yml | 32 +++++----- 3 files changed, 67 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index eb4f0c306..d398a1cef 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1764,7 +1764,7 @@ public class QuickShop extends JavaPlugin { if (selectedVersion == 115) { getConfig().set("integration.griefprevention.enable", false); getConfig().set("integration.griefprevention.whitelist-mode", false); - getConfig().set("integration.griefprevention.create", Collections.emptyList()); + getConfig().set("integration.griefprevention.create", "Inventory"); getConfig().set("integration.griefprevention.trade", Collections.emptyList()); getConfig().set("config-version", 116); selectedVersion = 116; @@ -1872,7 +1872,10 @@ public class QuickShop extends JavaPlugin { getConfig().set("integration.advancedregionmarket.enable", true); getConfig().set("config-version", ++selectedVersion); } - + if (selectedVersion == 136) { + getConfig().set("integration.griefprevention.delete-on-subclaim-created", true); + getConfig().set("config-version", ++selectedVersion); + } if (getConfig().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) { getLogger().warning("You are not using QS Matcher, it may meeting item comparing issue mentioned there: https://hub.spigotmc.org/jira/browse/SPIGOT-5063"); 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 31cf68776..9e8c27034 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java @@ -20,11 +20,9 @@ package org.maxgamer.quickshop.integration.griefprevention; import me.ryanhamshire.GriefPrevention.Claim; +import me.ryanhamshire.GriefPrevention.ClaimPermission; import me.ryanhamshire.GriefPrevention.GriefPrevention; -import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; -import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; -import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent; -import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent; +import me.ryanhamshire.GriefPrevention.events.*; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -39,6 +37,7 @@ import org.maxgamer.quickshop.integration.IntegrationStage; import org.maxgamer.quickshop.integration.QSIntegratedPlugin; import org.maxgamer.quickshop.shop.Shop; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -57,7 +56,9 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { private final boolean deleteOnClaimResized; - private final List createLimits = new ArrayList<>(3); + private final boolean deleteOnSubClaimCreated; + + private final Flag createLimit; private final List tradeLimits = new ArrayList<>(3); @@ -69,7 +70,8 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { this.deleteOnClaimUnclaimed = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-unclaimed"); this.deleteOnClaimExpired = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-expired"); this.deleteOnClaimResized = configurationSection.getBoolean("integration.griefprevention.delete-on-claim-resized"); - this.createLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.create"))); + this.deleteOnSubClaimCreated = configurationSection.getBoolean("integration.griefprevention.delete-on-subclaim-created"); + this.createLimit = Flag.getFlag(configurationSection.getString("integration.griefprevention.create")); this.tradeLimits.addAll(toFlags(configurationSection.getStringList("integration.griefprevention.trade"))); } @@ -90,7 +92,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { @Override public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { - return checkPermission(player, location, createLimits); + return checkPermission(player, location, Arrays.asList(createLimit)); } @Override @@ -98,14 +100,20 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { return checkPermission(player, location, tradeLimits); } - // We will check if the shops belong to user/users whose permissions were changed. - // If so, we will delete them. + // We will check if the shop belongs to user whose permissions were changed. + // It will remove a shop if the shop owner no longer has permission to build a shop there. // We will not delete the shops of the claim owner. @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onClaimTrustChanged(TrustChangedEvent event) { if (!deleteOnClaimTrustChanged) { return; } + if (event.isGiven() && event.getClaimPermission() == null) { + return; + } + if (ClaimPermission.valueOf(createLimit.toString()).isGrantedBy(event.getClaimPermission())) { + return; + } for (Claim claim : event.getClaims()) { for (Chunk chunk : claim.getChunks()) { Map shops = plugin.getShopManager().getShops(chunk); @@ -171,6 +179,30 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { } } + // Player can create subclaims inside a claim. + // So if a subclaim is created that will contain, initially, shops from others players, then we will remove them. + // Because they won't have, initially, permission to create a shop in that subclaim. + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onSubClaimCreated(ClaimCreatedEvent event) { + if (!deleteOnSubClaimCreated) { + return; + } + if (event.getClaim().parent != null) { + for (Chunk chunk : event.getClaim().getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (!shop.getOwner().equals(event.getClaim().getOwnerID()) && + event.getClaim().contains(shop.getLocation(), false, false)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Created) #" + shop.ownerName()); + shop.delete(); + } + } + } + } + } + } + // If it is the main claim, then we will delete all the shops that were inside of it. private void handleMainClaimUnclaimedOrExpired(Claim claim, String logMessage) { for (Chunk chunk : claim.getChunks()) { @@ -204,7 +236,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { } // If it is a main claim, then we will remove the shops if the main claim was resized (size was decreased). - // A shop will be removed if the old claim contain it but the new claim doesn't. + // A shop will be removed if the old claim contains it but the new claim doesn't. private void handleMainClaimResized(Claim oldClaim, Claim newClaim) { for (Chunk chunk : oldClaim.getChunks()) { Map shops = plugin.getShopManager().getShops(chunk); @@ -274,17 +306,17 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { enum Flag { - BUILD { + Build { @Override boolean check(Claim claim, Player player) { return claim.allowBuild(player, Material.CHEST) == null; } - }, CONTAINER_ACCESS { + }, Inventory { @Override boolean check(Claim claim, Player player) { return claim.allowContainers(player) == null; } - }, ACCESS { + }, Access { @Override boolean check(Claim claim, Player player) { return claim.allowAccess(player) == null; @@ -292,9 +324,8 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { }; public static Flag getFlag(String flag) { - flag = flag.toUpperCase(); for (Flag value : Flag.values()) { - if (value.name().equals(flag)) { + if (value.name().equalsIgnoreCase(flag)) { return value; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e3a2d9f9e..e3395faff 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -670,29 +670,24 @@ integration: #GriefPrevention Integration griefprevention: enable: false - #Should we prevent the creation of a shop or trade with a shop outside GriefPrevetion's area? - whitelist-mode: false - #Which checks does a player need to pass to create a shop? - #You can use multiple checks at the same time. - #Priority: UP > DOWN - # + #Should we prevent the creation of a shop or trade with a shop outside GriefPrevention's area? + whitelist-mode: true + #Which check does a player need to pass to create a shop? #Available fields: - #BUILD = The player must have the ability to build in the target claim. - #CONTAINER_ACCESS = The player must be able to access containers. - #ACCESS = The Player must have the ability to access the target claim. - create: - - CONTAINER_ACCESS + #Build = The player must have the ability to build in the target claim. + #Inventory = The player must be able to access containers. + #Access = The Player must have the ability to access the target claim. + create: Inventory #Which checks does a player need to pass to trade with a shop? #You can use multiple checks at the same time. #Priority: UP > DOWN - # #Available fields: - #BUILD = The player must have the ability to build in the target claim. - #CONTAINER_ACCESS = The player must be able to access containers. - #ACCESS = The Player must have the ability to access the target claim. + #Build = The player must have the ability to build in the target claim. + #Inventory = The player must be able to access containers. + #Access = The Player must have the ability to access the target claim. trade: [ ] #Should QuickShop delete shops if the trust permission of the shop owner has been changed on the claim/subclaim? - #It will check if the shops belong to user/users whose permissions were changed and will delete them. + #It will remove a shop if the shop owner no longer has permission to build a shop there. #It will never remove a shop of the claim owner. delete-on-claim-trust-changed: true #Should QuickShop delete shops if the claim/subclaim has been unclaimed? @@ -708,6 +703,11 @@ integration: #It will remove a shop if the shop was outside the subclaim but now it is inside the subclaim. #It will never remove a shop of the claim owner when resizing a subclaim. delete-on-claim-resized: true + #Should Quickshop delete shops if a subclaim has been created? + #So if a subclaim is created that will contain, initially, shops from others players, then we will remove them. + #Because they won't have, initially, permission to create a shop in that subclaim. + #It will never remove a shop of the claim owner. + delete-on-subclaim-created: true #Residence Integration residence: enable: false From 5021aa7a1c4be04e49b01fa02e14f2bfca0162e3 Mon Sep 17 00:00:00 2001 From: 1171066 <1171066@isep.ipp.pt> Date: Wed, 28 Jul 2021 17:40:26 +0100 Subject: [PATCH 5/6] Fixed/Changed some things, in order for the pull request to be approved. --- .../org/maxgamer/quickshop/QuickShop.java | 24 ++++- .../GriefPreventionIntegration.java | 94 ++++++++++++------- src/main/resources/config.yml | 38 ++++---- 3 files changed, 96 insertions(+), 60 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 427c40b5b..265bcee14 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1756,7 +1756,7 @@ public class QuickShop extends JavaPlugin { if (selectedVersion == 115) { getConfig().set("integration.griefprevention.enable", false); getConfig().set("integration.griefprevention.whitelist-mode", false); - getConfig().set("integration.griefprevention.create", "Inventory"); + getConfig().set("integration.griefprevention.create", Collections.emptyList()); getConfig().set("integration.griefprevention.trade", Collections.emptyList()); getConfig().set("config-version", 116); selectedVersion = 116; @@ -1826,7 +1826,7 @@ public class QuickShop extends JavaPlugin { } if (selectedVersion == 128) { getConfig().set("shop.force-use-item-original-name", false); - getConfig().set("integration.griefprevention.delete-on-claim-trust-changed", false); + getConfig().set("integration.griefprevention.delete-on-untrusted", false); getConfig().set("config-version", ++selectedVersion); } @@ -1852,7 +1852,7 @@ public class QuickShop extends JavaPlugin { getConfig().set("config-version", ++selectedVersion); } if (selectedVersion == 133) { - getConfig().set("integration.griefprevention.delete-on-claim-unclaimed", false); + getConfig().set("integration.griefprevention.delete-on-unclaim", false); getConfig().set("integration.griefprevention.delete-on-claim-expired", false); getConfig().set("config-version", ++selectedVersion); } @@ -1868,8 +1868,22 @@ public class QuickShop extends JavaPlugin { getConfig().set("shop.use-global-virtual-item-queue", null); getConfig().set("config-version", ++selectedVersion); } - if(selectedVersion == 137) { - getConfig().set("integration.griefprevention.delete-on-subclaim-created", true); + if (selectedVersion == 137) { + getConfig().set("integration.griefprevention.create", null); + getConfig().set("integration.griefprevention.create", "INVENTORY"); + + getConfig().set("integration.griefprevention.trade", null); + getConfig().set("integration.griefprevention.trade", Collections.emptyList()); + + boolean oldValueUntrusted = getConfig().getBoolean("integration.griefprevention.delete-on-untrusted", false); + getConfig().set("integration.griefprevention.delete-on-untrusted", null); + getConfig().set("integration.griefprevention.delete-on-claim-trust-changed", oldValueUntrusted); + + boolean oldValueUnclaim = getConfig().getBoolean("integration.griefprevention.delete-on-unclaim", false); + getConfig().set("integration.griefprevention.delete-on-unclaim", null); + getConfig().set("integration.griefprevention.delete-on-claim-unclaimed", oldValueUnclaim); + + getConfig().set("integration.griefprevention.delete-on-subclaim-created", false); getConfig().set("config-version", ++selectedVersion); } 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 9e8c27034..d7b6ff11e 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/griefprevention/GriefPreventionIntegration.java @@ -22,7 +22,11 @@ package org.maxgamer.quickshop.integration.griefprevention; import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.ClaimPermission; import me.ryanhamshire.GriefPrevention.GriefPrevention; -import me.ryanhamshire.GriefPrevention.events.*; +import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent; +import me.ryanhamshire.GriefPrevention.events.ClaimDeletedEvent; +import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent; +import me.ryanhamshire.GriefPrevention.events.ClaimModifiedEvent; +import me.ryanhamshire.GriefPrevention.events.ClaimCreatedEvent; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; @@ -37,7 +41,7 @@ import org.maxgamer.quickshop.integration.IntegrationStage; import org.maxgamer.quickshop.integration.QSIntegratedPlugin; import org.maxgamer.quickshop.shop.Shop; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -92,7 +96,7 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { @Override public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) { - return checkPermission(player, location, Arrays.asList(createLimit)); + return checkPermission(player, location, Collections.singletonList(createLimit)); } @Override @@ -111,29 +115,32 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { if (event.isGiven() && event.getClaimPermission() == null) { return; } - if (ClaimPermission.valueOf(createLimit.toString()).isGrantedBy(event.getClaimPermission())) { + if (createLimit.toClaimPermission().isGrantedBy(event.getClaimPermission())) { return; } for (Claim claim : event.getClaims()) { for (Chunk chunk : claim.getChunks()) { Map shops = plugin.getShopManager().getShops(chunk); - if (shops != null) { - for (Shop shop : shops.values()) { - if (!shop.getOwner().equals(claim.getOwnerID())) { - Claim shopClaim = griefPrevention.dataStore.getClaimAt(shop.getLocation(), false, false, null); - if (shopClaim != null && shopClaim.getID().equals(claim.getID())) { - if (event.getIdentifier().equals(shop.getOwner().toString())) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); - shop.delete(); - } else if (event.getIdentifier().contains(shop.getOwner().toString())) { - plugin.log("[SHOP DELETE] GP Integration: Group delete (Claim/Subclaim Trust Changed)#" + shop.ownerName()); - shop.delete(); - } else if ("all".equals(event.getIdentifier()) || "public".equals(event.getIdentifier())) { - plugin.log("[SHOP DELETE] GP Integration: All/Public delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); - shop.delete(); - } - } - } + if (shops == null) { + continue; + } + for (Shop shop : shops.values()) { + if (shop.getOwner().equals(claim.getOwnerID())) { + continue; + } + Claim shopClaim = griefPrevention.dataStore.getClaimAt(shop.getLocation(), false, false, null); + if (shopClaim == null || !shopClaim.getID().equals(claim.getID())) { + continue; + } + if (event.getIdentifier().equals(shop.getOwner().toString())) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); + shop.delete(); + } else if (event.getIdentifier().contains(shop.getOwner().toString())) { + plugin.log("[SHOP DELETE] GP Integration: Group delete (Claim/Subclaim Trust Changed)#" + shop.ownerName()); + shop.delete(); + } else if ("all".equals(event.getIdentifier()) || "public".equals(event.getIdentifier())) { + plugin.log("[SHOP DELETE] GP Integration: All/Public delete (Claim/Subclaim Trust Changed) #" + shop.ownerName()); + shop.delete(); } } } @@ -187,16 +194,17 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { if (!deleteOnSubClaimCreated) { return; } - if (event.getClaim().parent != null) { - for (Chunk chunk : event.getClaim().getChunks()) { - Map shops = plugin.getShopManager().getShops(chunk); - if (shops != null) { - for (Shop shop : shops.values()) { - if (!shop.getOwner().equals(event.getClaim().getOwnerID()) && - event.getClaim().contains(shop.getLocation(), false, false)) { - plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Created) #" + shop.ownerName()); - shop.delete(); - } + if(event.getClaim().parent == null) { + return; + } + for (Chunk chunk : event.getClaim().getChunks()) { + Map shops = plugin.getShopManager().getShops(chunk); + if (shops != null) { + for (Shop shop : shops.values()) { + if (!shop.getOwner().equals(event.getClaim().getOwnerID()) && + event.getClaim().contains(shop.getLocation(), false, false)) { + plugin.log("[SHOP DELETE] GP Integration: Single delete (SubClaim Created) #" + shop.ownerName()); + shop.delete(); } } } @@ -306,23 +314,39 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { enum Flag { - Build { + BUILD { @Override boolean check(Claim claim, Player player) { return claim.allowBuild(player, Material.CHEST) == null; } - }, Inventory { + @Override + ClaimPermission toClaimPermission() { + return ClaimPermission.Build; + } + }, INVENTORY { @Override boolean check(Claim claim, Player player) { return claim.allowContainers(player) == null; } - }, Access { + @Override + ClaimPermission toClaimPermission() { + return ClaimPermission.Inventory; + } + }, ACCESS { @Override boolean check(Claim claim, Player player) { return claim.allowAccess(player) == null; } + @Override + ClaimPermission toClaimPermission() { + return ClaimPermission.Access; + } }; + abstract boolean check(Claim claim, Player player); + + abstract ClaimPermission toClaimPermission(); + public static Flag getFlag(String flag) { for (Flag value : Flag.values()) { if (value.name().equalsIgnoreCase(flag)) { @@ -331,8 +355,6 @@ public class GriefPreventionIntegration extends QSIntegratedPlugin { } return null; } - - abstract boolean check(Claim claim, Player player); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ffb44e614..3a0179d56 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: 137 +config-version: 138 #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. @@ -667,39 +667,39 @@ integration: whitelist-mode: true #Which check does a player need to pass to create a shop? #Available fields: - #Build = The player must have the ability to build in the target claim. - #Inventory = The player must be able to access containers. - #Access = The Player must have the ability to access the target claim. - create: Inventory + #BUILD = The player must have the ability to build in the target claim. + #INVENTORY = The player must be able to access containers. + #ACCESS = The Player must have the ability to access the target claim. + create: INVENTORY #Which checks does a player need to pass to trade with a shop? #You can use multiple checks at the same time. #Priority: UP > DOWN #Available fields: - #Build = The player must have the ability to build in the target claim. - #Inventory = The player must be able to access containers. - #Access = The Player must have the ability to access the target claim. + #BUILD = The player must have the ability to build in the target claim. + #INVENTORY = The player must be able to access containers. + #ACCESS = The Player must have the ability to access the target claim. trade: [ ] #Should QuickShop delete shops if the trust permission of the shop owner has been changed on the claim/subclaim? - #It will remove a shop if the shop owner no longer has permission to build a shop there. - #It will never remove a shop of the claim owner. + #Removes a shop if the shop owner no longer has permission to build a shop there. + #Never removes a shop of the claim owner. delete-on-claim-trust-changed: true #Should QuickShop delete shops if the claim/subclaim has been unclaimed? - #It will remove all the shops that were inside the claim/subclaim that was unclaimed. - #It will never remove a shop of the claim owner when unclaiming a subclaim. + #Removes all the shops that were inside the claim/subclaim that was unclaimed. + #Never removes a shop of the claim owner when unclaiming a subclaim. delete-on-claim-unclaimed: true #Should QuickShop delete shops if the claim has been expired? - #It will remove all the shops that were inside the claim. + #Removes all the shops that were inside the claim. delete-on-claim-expired: true #Should QuickShop delete shops if claim/subclaim has been resized? - #It will remove a shop that the old claim contains but the new claim doesn't. - #It will remove a shop if the shop was inside the subclaim but now it is outside the subclaim. - #It will remove a shop if the shop was outside the subclaim but now it is inside the subclaim. - #It will never remove a shop of the claim owner when resizing a subclaim. + #Removes a shop that the old claim contains but the new claim doesn't. + #Removes a shop if the shop was inside the subclaim but now it is outside the subclaim. + #Removes a shop if the shop was outside the subclaim but now it is inside the subclaim. + #Never removes a shop of the claim owner when resizing a subclaim. delete-on-claim-resized: true #Should Quickshop delete shops if a subclaim has been created? - #So if a subclaim is created that will contain, initially, shops from others players, then we will remove them. + #If a subclaim is created that will contain, initially, shops from others players, then we will remove them. #Because they won't have, initially, permission to create a shop in that subclaim. - #It will never remove a shop of the claim owner. + #Never removes a shop of the claim owner. delete-on-subclaim-created: true #Residence Integration residence: From 302847fe81800211d9f5d4d4addccea7f90485c4 Mon Sep 17 00:00:00 2001 From: 1171066 <1171066@isep.ipp.pt> Date: Fri, 30 Jul 2021 13:45:03 +0100 Subject: [PATCH 6/6] Added whitelist-mode option to Towny Integration in the config file --- src/main/java/org/maxgamer/quickshop/QuickShop.java | 4 ++++ .../quickshop/integration/towny/TownyIntegration.java | 5 +++++ src/main/resources/config.yml | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 265bcee14..2ee4e28bb 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -1886,6 +1886,10 @@ public class QuickShop extends JavaPlugin { getConfig().set("integration.griefprevention.delete-on-subclaim-created", false); getConfig().set("config-version", ++selectedVersion); } + if (selectedVersion == 138) { + getConfig().set("integration.towny.whitelist-mode", true); + getConfig().set("config-version", ++selectedVersion); + } if (getConfig().getInt("matcher.work-type") != 0 && GameVersion.get(ReflectFactory.getServerVersion()).name().contains("1_16")) { getLogger().warning("You are not using QS Matcher, it may meeting item comparing issue mentioned there: https://hub.spigotmc.org/jira/browse/SPIGOT-5063"); diff --git a/src/main/java/org/maxgamer/quickshop/integration/towny/TownyIntegration.java b/src/main/java/org/maxgamer/quickshop/integration/towny/TownyIntegration.java index 3630b962b..e30685a73 100644 --- a/src/main/java/org/maxgamer/quickshop/integration/towny/TownyIntegration.java +++ b/src/main/java/org/maxgamer/quickshop/integration/towny/TownyIntegration.java @@ -58,6 +58,7 @@ public class TownyIntegration extends QSIntegratedPlugin implements Listener { private final boolean deleteShopOnLeave; private final boolean deleteShopOnPlotClear; private boolean isNewVersion; + private boolean whiteList; public TownyIntegration(QuickShop plugin) { @@ -67,6 +68,7 @@ public class TownyIntegration extends QSIntegratedPlugin implements Listener { ignoreDisabledWorlds = plugin.getConfig().getBoolean("integration.towny.ignore-disabled-worlds"); deleteShopOnLeave = plugin.getConfig().getBoolean("integration.towny.delete-shop-on-resident-leave"); deleteShopOnPlotClear = plugin.getConfig().getBoolean("integration.towny.delete-shop-on-plot-clear"); + whiteList = plugin.getConfig().getBoolean("integration.towny.whitelist-mode"); //Testing if there have new method try { Town.class.getDeclaredMethod("getHomeblockWorld"); @@ -185,6 +187,9 @@ public class TownyIntegration extends QSIntegratedPlugin implements Listener { Util.debugLog("This world disabled Towny."); return true; } + if (!whiteList && !ShopPlotUtil.isShopPlot(location)) { + return true; + } for (TownyFlags flag : flags) { switch (flag) { case OWN: diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3a0179d56..af73e4f2b 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: 138 +config-version: 139 #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. @@ -600,6 +600,8 @@ integration: trade: [] delete-shop-on-resident-leave: false delete-shop-on-plot-clear: true + #Should we prevent the creation of a shop or trade with a shop outside Towny's area + whitelist-mode: true #WorldGuard Integration #CHANGES REQUIRE A SERVER RESTART! #CHANGES REQUIRE A SERVER RESTART!