Skip to content

Commit

Permalink
Merge pull request #105 from XXY233/develop
Browse files Browse the repository at this point in the history
add Lands support
  • Loading branch information
josemmo authored Oct 14, 2023
2 parents 6f27717 + d1bfffe commit 8a97f07
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ The supported plugins are:
- [WorldGuard](https://enginehub.org/worldguard/)
- [GriefPrevention](https://www.spigotmc.org/resources/griefprevention.1884/)
- [Towny Advanced](https://townyadvanced.github.io/)
- [Lands](https://www.spigotmc.org/resources/53313/)

## Flags
Images from this plugin have a set of boolean attributes called "flags" that modify its behavior. Possible values are:
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
<scope>provided</scope>
</dependency>

<!-- https://jitpack.io/com/github/Angeschossen/LandsAPI/ -->
<dependency>
<groupId>com.github.angeschossen</groupId>
<artifactId>LandsAPI</artifactId>
<version>6.35.0</version>
<scope>provided</scope>
</dependency>

<!-- https://repo.maven.apache.org/maven2/org/jetbrains/annotations/ -->
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/io/josemmo/bukkit/plugin/utils/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import io.josemmo.bukkit.plugin.YamipaPlugin;
import me.angeschossen.lands.api.LandsIntegration;
import me.angeschossen.lands.api.flags.type.RoleFlag;
import me.angeschossen.lands.api.land.LandWorld;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -25,6 +28,7 @@ public class Permissions {
@Nullable private static WorldGuard worldGuard = null;
@Nullable private static GriefPrevention griefPrevention = null;
@Nullable private static TownyAPI townyApi = null;
@Nullable private static LandsIntegration landsApi = null;

static {
try {
Expand All @@ -44,6 +48,12 @@ public class Permissions {
} catch (NoClassDefFoundError __) {
// Towny is not installed
}

try {
landsApi = LandsIntegration.of(YamipaPlugin.getInstance());
} catch (NoClassDefFoundError __) {
// Lands is not installed
}
}

/**
Expand All @@ -55,7 +65,8 @@ public class Permissions {
public static boolean canBuild(@NotNull Player player, @NotNull Location location) {
return queryWorldGuard(player, location, true)
&& queryGriefPrevention(player, location, true)
&& queryTowny(player, location, true);
&& queryTowny(player, location, true)
&& queryLands(player, location, true);
}

/**
Expand All @@ -67,7 +78,8 @@ && queryGriefPrevention(player, location, true)
public static boolean canDestroy(@NotNull Player player, @NotNull Location location) {
return queryWorldGuard(player, location, false)
&& queryGriefPrevention(player, location, false)
&& queryTowny(player, location, false);
&& queryTowny(player, location, false)
&& queryLands(player, location, false);
}

private static boolean queryWorldGuard(@NotNull Player player, @NotNull Location location, boolean isBuild) {
Expand Down Expand Up @@ -122,4 +134,18 @@ private static boolean queryTowny(@NotNull Player player, @NotNull Location loca
TownyPermission.ActionType type = isBuild ? TownyPermission.ActionType.BUILD : TownyPermission.ActionType.DESTROY;
return PlayerCacheUtil.getCachePermission(player, location, material, type);
}

private static boolean queryLands(@NotNull Player player, @NotNull Location location, boolean isBuild) {
if (landsApi == null) {
return true;
}
LandWorld landWorld = landsApi.getWorld(location.getWorld());
if (landWorld == null) {
return true;
}
RoleFlag flag = isBuild ?
me.angeschossen.lands.api.flags.type.Flags.BLOCK_PLACE :
me.angeschossen.lands.api.flags.type.Flags.BLOCK_BREAK;
return landWorld.hasRoleFlag(player.getUniqueId(), location, flag);
}
}

0 comments on commit 8a97f07

Please sign in to comment.