From 68a005267ac9514e9ad98ccaf97e426372e7fd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20Moreno?= Date: Mon, 3 Apr 2023 13:08:30 +0200 Subject: [PATCH] Added support for Towny Advanced - Updated Permissions utils class - Updated pom.xml and plugin.yml - Updated README.md > Closes #87 --- README.md | 1 + pom.xml | 6 +++++ .../bukkit/plugin/utils/Permissions.java | 26 +++++++++++++++++-- src/main/resources/plugin.yml | 1 + 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 805c1e1..d1adc5c 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ The supported plugins are: - [WorldGuard](https://enginehub.org/worldguard/) - [GriefPrevention](https://www.spigotmc.org/resources/griefprevention.1884/) +- [Towny Advanced](https://townyadvanced.github.io/) ## Flags Images from this plugin have a set of boolean attributes called "flags" that modify its behavior. Possible values are: diff --git a/pom.xml b/pom.xml index e437d82..36637da 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,12 @@ 16.18.1 provided + + com.github.TownyAdvanced + towny + 0.98.6.25 + provided + org.jetbrains annotations diff --git a/src/main/java/io/josemmo/bukkit/plugin/utils/Permissions.java b/src/main/java/io/josemmo/bukkit/plugin/utils/Permissions.java index 212d81c..e1c1586 100644 --- a/src/main/java/io/josemmo/bukkit/plugin/utils/Permissions.java +++ b/src/main/java/io/josemmo/bukkit/plugin/utils/Permissions.java @@ -1,5 +1,8 @@ package io.josemmo.bukkit.plugin.utils; +import com.palmergames.bukkit.towny.TownyAPI; +import com.palmergames.bukkit.towny.object.TownyPermission; +import com.palmergames.bukkit.towny.utils.PlayerCacheUtil; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.WorldGuard; @@ -11,6 +14,7 @@ import me.ryanhamshire.GriefPrevention.GriefPrevention; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,6 +24,7 @@ public class Permissions { @Nullable private static WorldGuard worldGuard = null; @Nullable private static GriefPrevention griefPrevention = null; + @Nullable private static TownyAPI townyApi = null; static { try { @@ -33,6 +38,12 @@ public class Permissions { } catch (NoClassDefFoundError __) { // GriefPrevention is not installed } + + try { + townyApi = TownyAPI.getInstance(); + } catch (NoClassDefFoundError __) { + // Towny is not installed + } } /** @@ -43,7 +54,8 @@ public class Permissions { */ public static boolean canBuild(@NotNull Player player, @NotNull Location location) { return queryWorldGuard(player, location, true) - && queryGriefPrevention(player, location, true); + && queryGriefPrevention(player, location, true) + && queryTowny(player, location, true); } /** @@ -54,7 +66,8 @@ public static boolean canBuild(@NotNull Player player, @NotNull Location locatio */ public static boolean canDestroy(@NotNull Player player, @NotNull Location location) { return queryWorldGuard(player, location, false) - && queryGriefPrevention(player, location, false); + && queryGriefPrevention(player, location, false) + && queryTowny(player, location, false); } private static boolean queryWorldGuard(@NotNull Player player, @NotNull Location location, boolean isBuild) { @@ -100,4 +113,13 @@ private static boolean queryGriefPrevention(@NotNull Player player, @NotNull Loc return false; } } + + private static boolean queryTowny(@NotNull Player player, @NotNull Location location, boolean isBuild) { + if (townyApi == null) { + return true; + } + Material material = location.getBlock().getType(); + TownyPermission.ActionType type = isBuild ? TownyPermission.ActionType.BUILD : TownyPermission.ActionType.DESTROY; + return PlayerCacheUtil.getCachePermission(player, location, material, type); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f100005..bb95eb3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,6 +8,7 @@ softdepend: - Hyperverse - Multiverse-Core - My_Worlds + - Towny - WorldGuard permissions: