Add support for LWC LimitsV2 module (#293)
This adds a new OTHER_BREAK PreShopCreationEvent outcome to indicate that the sign should get broken. To keep it backwards compatible with other plugins setCancelled still sets OTHER and will not lead to a sign break. The breaking logic is also moved out of the ErrorMessageSender as it didn't make sense to have there. (It also wasted a tiny bit of CPU by getting the block of the state again) Do do this it now fully depend on LWCX, it's the only active version anways. Also fixed a possible out of index error with the sign lines.
This commit is contained in:
parent
bb4eece790
commit
3bf54529db
23
pom.xml
23
pom.xml
|
@ -25,6 +25,10 @@
|
|||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>lwcx-repo</id>
|
||||
<url>https://ci.ender.zone/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>vault-repo</id>
|
||||
<url>http://nexus.hc.to/content/repositories/pub_releases/</url>
|
||||
|
@ -159,27 +163,10 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.griefcraft</groupId>
|
||||
<artifactId>lwc</artifactId>
|
||||
<version>4.7.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.griefcraft.lwc</groupId>
|
||||
<artifactId>LWCX</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<version>2.2.5</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
|
|
@ -203,6 +203,10 @@ public class PreShopCreationEvent extends Event implements Cancellable {
|
|||
* For plugin use
|
||||
*/
|
||||
OTHER,
|
||||
/**
|
||||
* Break the sign
|
||||
*/
|
||||
OTHER_BREAK,
|
||||
|
||||
SHOP_CREATED_SUCCESSFULLY
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ public class ErrorMessageSender implements Listener {
|
|||
|
||||
if (message != null) {
|
||||
event.getPlayer().sendMessage(Messages.prefix(message));
|
||||
event.getSign().getBlock().breakNaturally();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue