Option to block shop creation when LWC limit is reached (Resolves #293)

This commit is contained in:
Phoenix616 2020-05-02 15:57:42 +01:00
parent 3bed1261aa
commit 8c83be59ba
2 changed files with 32 additions and 1 deletions

View File

@ -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;

View File

@ -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();