diff --git a/pom.xml b/pom.xml
index 18209d7..c68f5e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,10 @@
codemc-repo
https://repo.codemc.org/repository/maven-public/
+
+ lwcx-repo
+ https://ci.ender.zone/plugin/repository/everything/
+
vault-repo
http://nexus.hc.to/content/repositories/pub_releases/
@@ -159,27 +163,10 @@
-
- com.griefcraft
- lwc
- 4.7.0-SNAPSHOT
- provided
-
-
- org.bukkit
- bukkit
-
-
- org.bukkit
- craftbukkit
-
-
-
-
com.griefcraft.lwc
LWCX
- 2.2.0
+ 2.2.5
provided
diff --git a/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java
index 27d6da1..06ebca8 100644
--- a/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java
+++ b/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java
@@ -203,6 +203,10 @@ public class PreShopCreationEvent extends Event implements Cancellable {
* For plugin use
*/
OTHER,
+ /**
+ * Break the sign
+ */
+ OTHER_BREAK,
SHOP_CREATED_SUCCESSFULLY
}
diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java
index edaa549..b3bc59f 100644
--- a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java
+++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java
@@ -3,7 +3,6 @@ package com.Acrobot.ChestShop.Listeners.Block;
import com.Acrobot.Breeze.Utils.BlockUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
-import com.Acrobot.ChestShop.Events.AccountQueryEvent;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Events.ShopCreatedEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign;
@@ -48,7 +47,12 @@ public class SignCreate implements Listener {
PreShopCreationEvent preEvent = new PreShopCreationEvent(event.getPlayer(), sign, lines);
ChestShop.callEvent(preEvent);
- for (byte i = 0; i < event.getLines().length; ++i) {
+ if (preEvent.isCancelled() && preEvent.getOutcome() != PreShopCreationEvent.CreationOutcome.OTHER) {
+ signBlock.breakNaturally();
+ return;
+ }
+
+ for (byte i = 0; i < preEvent.getSignLines().length && i < 3; ++i) {
event.setLine(i, preEvent.getSignLine(i));
}
diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java
index f960f50..751c995 100644
--- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java
+++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java
@@ -68,7 +68,6 @@ public class ErrorMessageSender implements Listener {
if (message != null) {
event.getPlayer().sendMessage(Messages.prefix(message));
- event.getSign().getBlock().breakNaturally();
}
}
}
diff --git a/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java b/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java
index b1cec11..fda4184 100644
--- a/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java
+++ b/src/main/java/com/Acrobot/ChestShop/Plugins/LightweightChestProtection.java
@@ -13,10 +13,11 @@ 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.modules.limits.LimitsV2;
import com.griefcraft.scripting.event.LWCProtectionRegisterEvent;
import com.griefcraft.scripting.event.LWCProtectionRegistrationPostEvent;
import org.bukkit.block.Block;
+import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
@@ -24,16 +25,20 @@ import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
+import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.OTHER_BREAK;
+
/**
* @author Acrobot
*/
public class LightweightChestProtection implements Listener {
private final LWC lwc;
private final LimitsModule limitsModule;
+ private final LimitsV2 limitsV2;
public LightweightChestProtection() {
this.lwc = LWC.getInstance();
this.limitsModule = (LimitsModule) lwc.getModuleLoader().getModule(LimitsModule.class);
+ this.limitsV2 = (LimitsV2) lwc.getModuleLoader().getModule(LimitsV2.class);
try {
if (Properties.PROTECT_SIGN_WITH_LWC)
Protection.Type.valueOf(Properties.LWC_SIGN_PROTECTION_TYPE.name());
@@ -48,24 +53,29 @@ public class LightweightChestProtection implements Listener {
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));
+ if (isAtLimit(event.getPlayer(), event.getSign())) {
+ event.setOutcome(OTHER_BREAK);
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));
+ if (container != null && isAtLimit(event.getPlayer(), container)) {
+ event.setOutcome(OTHER_BREAK);
return;
}
}
}
}
+ private boolean isAtLimit(Player player, BlockState blockState) {
+ LWCProtectionRegisterEvent protectionEvent = new LWCProtectionRegisterEvent(player, blockState.getBlock());
+ limitsModule.onRegisterProtection(protectionEvent);
+ limitsV2.onRegisterProtection(protectionEvent);
+ return protectionEvent.isCancelled();
+ }
+
@EventHandler
public static void onShopCreation(ShopCreatedEvent event) {
Player player = event.getPlayer();
@@ -164,21 +174,16 @@ public class LightweightChestProtection implements Listener {
Protection protection = null;
try {
- protection = lwc.getPhysicalDatabase().registerProtection(block.getType(), type, worldName, event.getProtectionOwner().toString(), "", x, y, z);
- } catch (LinkageError e) {
- try {
- int blockId = com.griefcraft.cache.BlockCache.getInstance().getBlockId(block);
- if (blockId < 0) {
- return;
- }
- protection = lwc.getPhysicalDatabase().registerProtection(blockId, type, worldName, event.getProtectionOwner().toString(), "", x, y, z);
- } catch (LinkageError e2) {
- ChestShop.getBukkitLogger().warning(
- "Incompatible LWC version installed! (" + lwc.getPlugin().getName() + " v" + lwc.getVersion() + ") \n" +
- "Material method error: " + e.getMessage() + "\n" +
- "Block cache/type id error: " + e2.getMessage()
- );
+ int blockId = com.griefcraft.cache.BlockCache.getInstance().getBlockId(block);
+ if (blockId < 0) {
+ return;
}
+ protection = lwc.getPhysicalDatabase().registerProtection(blockId, type, worldName, event.getProtectionOwner().toString(), "", x, y, z);
+ } catch (LinkageError e) {
+ ChestShop.getBukkitLogger().warning(
+ "Incompatible LWC version installed! (" + lwc.getPlugin().getName() + " v" + lwc.getVersion() + ") \n" +
+ "Block cache/type id error: " + e.getMessage()
+ );
}
if (protection != null) {