Added Towny protection, and fixed UltimateClaims and Lands NPEs.

This commit is contained in:
Fernando Pettinelli 2021-01-14 18:36:46 -03:00 committed by Brianna
parent 32dfc01a2a
commit 1873b2f647
5 changed files with 72 additions and 6 deletions

View File

@ -360,6 +360,13 @@
<groupId>com.songoda</groupId>
<artifactId>UltimateClaims</artifactId>
<version>1.3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.palmergames</groupId>
<artifactId>Towny</artifactId>
<version>0.96.5.0</version>
<scope>provided</scope>
</dependency>
<!-- End Plugin Hooks -->

View File

@ -44,6 +44,7 @@ public final class PluginHook<T extends Class> {
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 *******/

View File

@ -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

View File

@ -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;
}
}

View File

@ -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