diff --git a/pom.xml b/pom.xml index 54a66f8..fe8e781 100644 --- a/pom.xml +++ b/pom.xml @@ -68,6 +68,10 @@ sk89q-repo https://maven.enginehub.org/repo/ + + codemc-repo + https://repo.codemc.io/repository/maven-public/ + @@ -101,5 +105,11 @@ 16.18.2 provided + + com.griefcraft + lwc + 2.2.9-dev + provided + diff --git a/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java b/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java index 95b959f..16cb89e 100644 --- a/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java +++ b/src/main/java/me/youhavetrouble/yardwatch/YardWatch.java @@ -1,6 +1,7 @@ package me.youhavetrouble.yardwatch; import me.youhavetrouble.yardwatch.hooks.GriefPreventionProtection; +import me.youhavetrouble.yardwatch.hooks.LWCXProtection; import me.youhavetrouble.yardwatch.hooks.WorldGuardProtection; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; @@ -26,6 +27,12 @@ public final class YardWatch extends JavaPlugin { ); } + if (shouldRegisterService("LWC")) { + getServer().getServicesManager().register( + Protection.class, new LWCXProtection(this), this, ServicePriority.Normal + ); + } + } /** diff --git a/src/main/java/me/youhavetrouble/yardwatch/hooks/LWCXProtection.java b/src/main/java/me/youhavetrouble/yardwatch/hooks/LWCXProtection.java new file mode 100644 index 0000000..aeb49bb --- /dev/null +++ b/src/main/java/me/youhavetrouble/yardwatch/hooks/LWCXProtection.java @@ -0,0 +1,90 @@ +package me.youhavetrouble.yardwatch.hooks; + +import com.griefcraft.lwc.LWC; +import com.griefcraft.lwc.LWCPlugin; +import me.youhavetrouble.yardwatch.Protection; +import me.youhavetrouble.yardwatch.YardWatch; +import org.bukkit.Location; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +public class LWCXProtection implements Protection { + + private final YardWatch plugin; + + public LWCXProtection(YardWatch plugin) { + this.plugin = plugin; + } + + @Override + public boolean isEnabled() { + return plugin.getServer().getPluginManager().isPluginEnabled("LWC"); + } + + @Override + public boolean isProtected(Location location) { + if (!isEnabled()) return false; + return LWCPlugin.getPlugin(LWCPlugin.class).getLWC().findProtection(location) != null; + } + + @Override + public boolean canBreakBlock(Player player, BlockState blockState) { + if (!isEnabled()) return true; + return LWCPlugin.getPlugin(LWCPlugin.class) + .getLWC() + .canAccessProtection( + player, + blockState.getX(), + blockState.getY(), + blockState.getZ() + ); + } + + @Override + public boolean canPlaceBlock(Player player, Location location) { + return true; + } + + @Override + public boolean canInteract(Player player, BlockState blockState) { + if (!isEnabled()) return true; + return LWCPlugin.getPlugin(LWCPlugin.class) + .getLWC() + .canAccessProtection( + player, + blockState.getX(), + blockState.getY(), + blockState.getZ() + ); + } + + @Override + public boolean canInteract(Player player, Entity target) { + if (!isEnabled()) return true; + LWC lwc = LWCPlugin.getPlugin(LWCPlugin.class).getLWC(); + if (!lwc.isProtectable(target.getType())) return true; + // the following is extraction of lwcx internal logic. I have no clue what's happening here. + int a = 50000 + target.getUniqueId().hashCode(); + com.griefcraft.model.Protection protection = lwc.getPhysicalDatabase() + .loadProtection(target.getWorld().getName(), a, a, a); + if (protection == null) return true; + return lwc.canAccessProtection(player, protection); + } + + @Override + public boolean canDamage(Entity damager, Entity target) { + if (!isEnabled()) return true; + LWC lwc = LWCPlugin.getPlugin(LWCPlugin.class).getLWC(); + if (!lwc.isProtectable(target.getType())) return true; + // the following is extraction of lwcx internal logic. I have no clue what's happening here. + int a = 50000 + target.getUniqueId().hashCode(); + com.griefcraft.model.Protection protection = lwc.getPhysicalDatabase() + .loadProtection(target.getWorld().getName(), a, a, a); + if (protection == null) return true; + if (damager instanceof Player player) { + return lwc.canAccessProtection(player, protection); + } + return false; + } +}