diff --git a/README.md b/README.md index 39f6d95..e3f4628 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ ProtectionLib.canUse(player,location); 4) Add softdepend to plugin.yml ```yaml - softdepend: [ WorldGuard, Towny, Factions, Lands, PlotSquared, CrashClaim ] + softdepend: [ WorldGuard, Towny, Factions, Lands, PlotSquared, CrashClaim, HuskTowns ] ``` # Supported plugins @@ -59,3 +59,4 @@ ProtectionLib.canUse(player,location); - [Lands](https://www.spigotmc.org/resources/lands-land-claim-plugin-grief-prevention-protection-gui-management-nations-wars-1-17-support.53313/) (Paid) - [PlotSquared](https://www.spigotmc.org/resources/plotsquared.1177/) (Free) - [CrashClaim](https://www.spigotmc.org/resources/crashclaim-claiming-plugin.94037/) (Paid) +- [HuskTowns](https://www.spigotmc.org/resources/92672) (Paid) diff --git a/build.gradle.kts b/build.gradle.kts index d1779fa..6f14dc7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -42,6 +42,7 @@ dependencies { //compileOnly("com.github.TechFortress:GriefPrevention:16.18") implementation(files("libs/GriefPrevention-16.18.jar")) compileOnly("net.william278.huskclaims:huskclaims-bukkit:1.1.2") + compileOnly("net.william278.husktowns:husktowns-bukkit:3.0.4") } java { diff --git a/src/main/java/io/th0rgal/protectionlib/ProtectionLib.java b/src/main/java/io/th0rgal/protectionlib/ProtectionLib.java index 83ad29e..b7541d3 100644 --- a/src/main/java/io/th0rgal/protectionlib/ProtectionLib.java +++ b/src/main/java/io/th0rgal/protectionlib/ProtectionLib.java @@ -62,6 +62,11 @@ public static void init(JavaPlugin plugin) { } catch (Exception | NoClassDefFoundError e) { if (debug) e.printStackTrace(); } + try { + handleCompatibility("HuskTowns", plugin, (m, p) -> new HuskTownsCompat(m, p)); + } catch (Exception | NoClassDefFoundError e) { + if (debug) e.printStackTrace(); + } } public static void setDebug(boolean debug) { diff --git a/src/main/java/io/th0rgal/protectionlib/compatibilities/HuskTownsCompat.java b/src/main/java/io/th0rgal/protectionlib/compatibilities/HuskTownsCompat.java new file mode 100644 index 0000000..f174d9c --- /dev/null +++ b/src/main/java/io/th0rgal/protectionlib/compatibilities/HuskTownsCompat.java @@ -0,0 +1,51 @@ +package io.th0rgal.protectionlib.compatibilities; + +import io.th0rgal.protectionlib.ProtectionCompatibility; +import net.william278.husktowns.api.BukkitHuskTownsAPI; +import net.william278.husktowns.api.HuskTownsAPI; +import net.william278.husktowns.claim.Position; +import net.william278.husktowns.libraries.cloplib.operation.OperationType; +import net.william278.husktowns.user.OnlineUser; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +public class HuskTownsCompat extends ProtectionCompatibility { + private final HuskTownsAPI commonAPI; + private final BukkitHuskTownsAPI bukkitAPI; + + public HuskTownsCompat(JavaPlugin mainPlugin, Plugin plugin) { + super(mainPlugin, plugin); + commonAPI = HuskTownsAPI.getInstance(); + bukkitAPI = BukkitHuskTownsAPI.getInstance(); + } + + @Override + public boolean canBuild(Player player, Location target) { + return isOperationAllowed(player, target, OperationType.BLOCK_PLACE); + } + + @Override + public boolean canBreak(Player player, Location target) { + return isOperationAllowed(player, target, OperationType.BLOCK_BREAK); + } + + @Override + public boolean canInteract(Player player, Location target) { + OperationType type = target.getBlock().getType().isBlock() ? OperationType.BLOCK_INTERACT : OperationType.ENTITY_INTERACT; + return isOperationAllowed(player, target, type); + } + + @Override + public boolean canUse(Player player, Location target) { + return isOperationAllowed(player, target, OperationType.BLOCK_INTERACT); + } + + private boolean isOperationAllowed(@NotNull Player player, @NotNull Location location, @NotNull OperationType type) { + OnlineUser user = bukkitAPI.getOnlineUser(player); + Position position = bukkitAPI.getPosition(location); + return commonAPI.isOperationAllowed(user, type, position); + } +}