Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Lands support #105

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}