Update LWC protection and support more LWC forks (LWCX and Modern-LWC)

This commit is contained in:
Phoenix616 2019-08-22 13:09:54 +01:00
parent 285b6b9089
commit f90d23cfc3
2 changed files with 38 additions and 5 deletions

21
pom.xml
View File

@ -167,9 +167,26 @@
</dependency>
<dependency>
<groupId>com.griefcraft.lwc</groupId>
<groupId>com.griefcraft</groupId>
<artifactId>lwc</artifactId>
<version>4.3.1</version>
<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>
<scope>provided</scope>
<exclusions>
<exclusion>

View File

@ -1,5 +1,6 @@
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.Protection.ProtectBlockEvent;
@ -11,7 +12,6 @@ import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection;
import com.griefcraft.scripting.event.LWCProtectionRegisterEvent;
import org.bukkit.block.Block;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
@ -99,8 +99,24 @@ public class LightweightChestProtection implements Listener {
return;
}
// TODO: Update to new API once LWC is updated
Protection protection = lwc.getPhysicalDatabase().registerProtection(block.getType().getId(), Protection.Type.PRIVATE, worldName, player.getUniqueId().toString(), "", x, y, z);
Protection protection = null;
try {
protection = lwc.getPhysicalDatabase().registerProtection(block.getType(), Protection.Type.PRIVATE, worldName, player.getUniqueId().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, Protection.Type.PRIVATE, worldName, player.getUniqueId().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()
);
}
}
if (protection != null) {
event.setProtected(true);