Skip to content

Commit

Permalink
Added support for Towny Advanced
Browse files Browse the repository at this point in the history
- Updated Permissions utils class
- Updated pom.xml and plugin.yml
- Updated README.md

> Closes #87
  • Loading branch information
josemmo committed Apr 3, 2023
1 parent 15284f1 commit 68a0052
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
<version>16.18.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>towny</artifactId>
<version>0.98.6.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/io/josemmo/bukkit/plugin/utils/Permissions.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -33,6 +38,12 @@ public class Permissions {
} catch (NoClassDefFoundError __) {
// GriefPrevention is not installed
}

try {
townyApi = TownyAPI.getInstance();
} catch (NoClassDefFoundError __) {
// Towny is not installed
}
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ softdepend:
- Hyperverse
- Multiverse-Core
- My_Worlds
- Towny
- WorldGuard

permissions:
Expand Down

0 comments on commit 68a0052

Please sign in to comment.