diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index d1d6a56..d5c8126 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -261,6 +261,9 @@ public class Properties { @ConfigurationComment("Should the chest's LWC protection be removed once the shop sign is destroyed? ") public static boolean REMOVE_LWC_PROTECTION_AUTOMATICALLY = true; + @ConfigurationComment("Should LWC limits block shop creations?") + public static boolean LWC_LIMITS_BLOCK_CREATION = true; + @PrecededBySpace @ConfigurationComment("Do you want to only let people build inside WorldGuard regions?") public static boolean WORLDGUARD_INTEGRATION = false; diff --git a/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java b/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java index b0a1b86..b1cec11 100644 --- a/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java +++ b/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java @@ -3,13 +3,17 @@ package com.Acrobot.ChestShop.Plugins; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Messages; import com.Acrobot.ChestShop.Configuration.Properties; +import com.Acrobot.ChestShop.Events.PreShopCreationEvent; import com.Acrobot.ChestShop.Events.Protection.ProtectBlockEvent; import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent; import com.Acrobot.ChestShop.Events.ShopCreatedEvent; import com.Acrobot.ChestShop.Events.ShopDestroyedEvent; import com.Acrobot.ChestShop.Security; +import com.Acrobot.ChestShop.Utils.uBlock; import com.griefcraft.lwc.LWC; import com.griefcraft.model.Protection; +import com.griefcraft.modules.limits.LimitsModule; +import com.griefcraft.scripting.Module; import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; import com.griefcraft.scripting.event.LWCProtectionRegistrationPostEvent; import org.bukkit.block.Block; @@ -24,10 +28,12 @@ import org.bukkit.event.Listener; * @author Acrobot */ public class LightweightChestProtection implements Listener { - private LWC lwc; + private final LWC lwc; + private final LimitsModule limitsModule; public LightweightChestProtection() { this.lwc = LWC.getInstance(); + this.limitsModule = (LimitsModule) lwc.getModuleLoader().getModule(LimitsModule.class); try { if (Properties.PROTECT_SIGN_WITH_LWC) Protection.Type.valueOf(Properties.LWC_SIGN_PROTECTION_TYPE.name()); @@ -38,6 +44,28 @@ public class LightweightChestProtection implements Listener { } } + @EventHandler(ignoreCancelled = true) + public void onPreShopCreation(PreShopCreationEvent event) { + if (Properties.LWC_LIMITS_BLOCK_CREATION) { + if (Properties.PROTECT_SIGN_WITH_LWC) { + if (limitsModule.hasReachedLimit(event.getPlayer(), event.getSign().getBlock())) { + event.setCancelled(true); + event.getPlayer().sendMessage(Messages.prefix(Messages.NOT_ENOUGH_PROTECTIONS)); + return; + } + } + + if (Properties.PROTECT_CHEST_WITH_LWC) { + Container container = uBlock.findConnectedContainer(event.getSign()); + if (container != null && limitsModule.hasReachedLimit(event.getPlayer(), container.getBlock())) { + event.setCancelled(true); + event.getPlayer().sendMessage(Messages.prefix(Messages.NOT_ENOUGH_PROTECTIONS)); + return; + } + } + } + } + @EventHandler public static void onShopCreation(ShopCreatedEvent event) { Player player = event.getPlayer();