diff --git a/Core/pom.xml b/Core/pom.xml
index ab3f6eee..4d523fd1 100644
--- a/Core/pom.xml
+++ b/Core/pom.xml
@@ -360,6 +360,13 @@
com.songoda
UltimateClaims
1.3.2
+ provided
+
+
+ com.palmergames
+ Towny
+ 0.96.5.0
+ provided
diff --git a/Core/src/main/java/com/songoda/core/hooks/PluginHook.java b/Core/src/main/java/com/songoda/core/hooks/PluginHook.java
index f1a694d0..a1327ae0 100644
--- a/Core/src/main/java/com/songoda/core/hooks/PluginHook.java
+++ b/Core/src/main/java/com/songoda/core/hooks/PluginHook.java
@@ -44,6 +44,7 @@ public final class PluginHook {
public static final PluginHook PROTECTION_LANDS = new PluginHook(Protection.class, "Lands", LandsProtection.class);
public static final PluginHook PROTECTION_REDPROTECT = new PluginHook(Protection.class, "RedProtect", RedProtectProtection.class);
public static final PluginHook PROTECTION_ULTIMATECLAIMS = new PluginHook(Protection.class, "UltimateClaims", UltimateClaimsProtection.class);
+ public static final PluginHook PROTECTION_TOWNY = new PluginHook(Protection.class, "Towny", TownyProtection.class);
/******* Start Manager stuff *******/
diff --git a/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java b/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java
index 3de0e8a9..4c86c7e6 100644
--- a/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java
+++ b/Core/src/main/java/com/songoda/core/hooks/protection/LandsProtection.java
@@ -1,6 +1,7 @@
package com.songoda.core.hooks.protection;
import me.angeschossen.lands.api.integration.LandsIntegration;
+import me.angeschossen.lands.api.land.Area;
import me.angeschossen.lands.api.role.enums.RoleSetting;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -17,17 +18,26 @@ public class LandsProtection extends Protection {
@Override
public boolean canPlace(Player player, Location location) {
- return landsIntegration.getAreaByLoc(location).canSetting(player, RoleSetting.BLOCK_PLACE, false);
+ return hasPerms(player, location, RoleSetting.BLOCK_PLACE);
}
@Override
public boolean canBreak(Player player, Location location) {
- return landsIntegration.getAreaByLoc(location).canSetting(player, RoleSetting.BLOCK_BREAK, false);
+ return hasPerms(player, location, RoleSetting.BLOCK_BREAK);
}
@Override
public boolean canInteract(Player player, Location location) {
- return landsIntegration.getAreaByLoc(location).canSetting(player, RoleSetting.INTERACT_CONTAINER, false);
+ return hasPerms(player, location, RoleSetting.INTERACT_CONTAINER);
+ }
+
+ private boolean hasPerms(Player player, Location location, RoleSetting roleSetting) {
+ Area area = landsIntegration.getAreaByLoc(location);
+ if (area == null) {
+ return true;
+ }
+
+ return area.canSetting(player, roleSetting, false);
}
@Override
diff --git a/Core/src/main/java/com/songoda/core/hooks/protection/TownyProtection.java b/Core/src/main/java/com/songoda/core/hooks/protection/TownyProtection.java
new file mode 100644
index 00000000..e57090d6
--- /dev/null
+++ b/Core/src/main/java/com/songoda/core/hooks/protection/TownyProtection.java
@@ -0,0 +1,38 @@
+package com.songoda.core.hooks.protection;
+
+import com.palmergames.bukkit.towny.object.TownyPermission;
+import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+public class TownyProtection extends Protection {
+ public TownyProtection(Plugin plugin) {
+ super(plugin);
+ }
+
+ @Override
+ public boolean canPlace(Player player, Location location) {
+ return PlayerCacheUtil.getCachePermission(player, location, location.getBlock().getType(), TownyPermission.ActionType.BUILD);
+ }
+
+ @Override
+ public boolean canBreak(Player player, Location location) {
+ return PlayerCacheUtil.getCachePermission(player, location, location.getBlock().getType(), TownyPermission.ActionType.DESTROY);
+ }
+
+ @Override
+ public boolean canInteract(Player player, Location location) {
+ return PlayerCacheUtil.getCachePermission(player, location, location.getBlock().getType(), TownyPermission.ActionType.ITEM_USE);
+ }
+
+ @Override
+ public String getName() {
+ return "Towny";
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+}
diff --git a/Core/src/main/java/com/songoda/core/hooks/protection/UltimateClaimsProtection.java b/Core/src/main/java/com/songoda/core/hooks/protection/UltimateClaimsProtection.java
index a1c4166b..0921497b 100644
--- a/Core/src/main/java/com/songoda/core/hooks/protection/UltimateClaimsProtection.java
+++ b/Core/src/main/java/com/songoda/core/hooks/protection/UltimateClaimsProtection.java
@@ -1,6 +1,7 @@
package com.songoda.core.hooks.protection;
import com.songoda.ultimateclaims.UltimateClaims;
+import com.songoda.ultimateclaims.claim.Claim;
import com.songoda.ultimateclaims.member.ClaimPerm;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -17,17 +18,26 @@ public class UltimateClaimsProtection extends Protection {
@Override
public boolean canPlace(Player player, Location location) {
- return instance.getClaimManager().getClaim(location.getChunk()).playerHasPerms(player, ClaimPerm.PLACE);
+ return hasPerms(player, location, ClaimPerm.PLACE);
}
@Override
public boolean canBreak(Player player, Location location) {
- return instance.getClaimManager().getClaim(location.getChunk()).playerHasPerms(player, ClaimPerm.BREAK);
+ return hasPerms(player, location, ClaimPerm.BREAK);
}
@Override
public boolean canInteract(Player player, Location location) {
- return instance.getClaimManager().getClaim(location.getChunk()).playerHasPerms(player, ClaimPerm.INTERACT);
+ return hasPerms(player, location, ClaimPerm.INTERACT);
+ }
+
+ private boolean hasPerms(Player player, Location location, ClaimPerm claimPerm) {
+ Claim claim = instance.getClaimManager().getClaim(location.getChunk());
+ if (claim == null) {
+ return true;
+ }
+
+ return claim.playerHasPerms(player, claimPerm);
}
@Override