Option to block shop creation when LWC limit is reached (Resolves #293)
This commit is contained in:
parent
3bed1261aa
commit
8c83be59ba
|
@ -261,6 +261,9 @@ public class Properties {
|
||||||
@ConfigurationComment("Should the chest's LWC protection be removed once the shop sign is destroyed? ")
|
@ConfigurationComment("Should the chest's LWC protection be removed once the shop sign is destroyed? ")
|
||||||
public static boolean REMOVE_LWC_PROTECTION_AUTOMATICALLY = true;
|
public static boolean REMOVE_LWC_PROTECTION_AUTOMATICALLY = true;
|
||||||
|
|
||||||
|
@ConfigurationComment("Should LWC limits block shop creations?")
|
||||||
|
public static boolean LWC_LIMITS_BLOCK_CREATION = true;
|
||||||
|
|
||||||
@PrecededBySpace
|
@PrecededBySpace
|
||||||
@ConfigurationComment("Do you want to only let people build inside WorldGuard regions?")
|
@ConfigurationComment("Do you want to only let people build inside WorldGuard regions?")
|
||||||
public static boolean WORLDGUARD_INTEGRATION = false;
|
public static boolean WORLDGUARD_INTEGRATION = false;
|
||||||
|
|
|
@ -3,13 +3,17 @@ package com.Acrobot.ChestShop.Plugins;
|
||||||
import com.Acrobot.ChestShop.ChestShop;
|
import com.Acrobot.ChestShop.ChestShop;
|
||||||
import com.Acrobot.ChestShop.Configuration.Messages;
|
import com.Acrobot.ChestShop.Configuration.Messages;
|
||||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
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.ProtectBlockEvent;
|
||||||
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent;
|
||||||
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
|
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
|
||||||
import com.Acrobot.ChestShop.Events.ShopDestroyedEvent;
|
import com.Acrobot.ChestShop.Events.ShopDestroyedEvent;
|
||||||
import com.Acrobot.ChestShop.Security;
|
import com.Acrobot.ChestShop.Security;
|
||||||
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||||
import com.griefcraft.lwc.LWC;
|
import com.griefcraft.lwc.LWC;
|
||||||
import com.griefcraft.model.Protection;
|
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.LWCProtectionRegisterEvent;
|
||||||
import com.griefcraft.scripting.event.LWCProtectionRegistrationPostEvent;
|
import com.griefcraft.scripting.event.LWCProtectionRegistrationPostEvent;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
@ -24,10 +28,12 @@ import org.bukkit.event.Listener;
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
public class LightweightChestProtection implements Listener {
|
public class LightweightChestProtection implements Listener {
|
||||||
private LWC lwc;
|
private final LWC lwc;
|
||||||
|
private final LimitsModule limitsModule;
|
||||||
|
|
||||||
public LightweightChestProtection() {
|
public LightweightChestProtection() {
|
||||||
this.lwc = LWC.getInstance();
|
this.lwc = LWC.getInstance();
|
||||||
|
this.limitsModule = (LimitsModule) lwc.getModuleLoader().getModule(LimitsModule.class);
|
||||||
try {
|
try {
|
||||||
if (Properties.PROTECT_SIGN_WITH_LWC)
|
if (Properties.PROTECT_SIGN_WITH_LWC)
|
||||||
Protection.Type.valueOf(Properties.LWC_SIGN_PROTECTION_TYPE.name());
|
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
|
@EventHandler
|
||||||
public static void onShopCreation(ShopCreatedEvent event) {
|
public static void onShopCreation(ShopCreatedEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
Loading…
Reference in New Issue