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

Lands - Bypass Perms #41

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
exclude("org.spongepowered:configurate-hocon")
exclude("com.mojang:brigadier")
}
compileOnly("com.github.angeschossen:LandsAPI:7.0.2")
compileOnly("com.github.angeschossen:LandsAPI:7.10.13")
implementation(platform("com.intellectualsites.bom:bom-1.18.x:1.20"))
compileOnly("com.plotsquared:PlotSquared-Core")
compileOnly("com.plotsquared:PlotSquared-Bukkit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import me.angeschossen.lands.api.LandsIntegration;
import me.angeschossen.lands.api.flags.type.Flags;
import me.angeschossen.lands.api.flags.type.RoleFlag;
import me.angeschossen.lands.api.land.Area;
import me.angeschossen.lands.api.land.Land;
import me.angeschossen.lands.api.land.LandWorld;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand All @@ -27,8 +26,7 @@ public LandsCompat(JavaPlugin mainPlugin, Plugin plugin) {
*/
@Override
public boolean canBuild(Player player, Location target) {
Land land = getLand(target);
return land == null || land.isTrusted(player.getUniqueId()) || hasFlag(target, player, Flags.BLOCK_PLACE);
return hasFlag(target, player, Flags.BLOCK_PLACE);
}

/**
Expand All @@ -38,8 +36,7 @@ public boolean canBuild(Player player, Location target) {
*/
@Override
public boolean canBreak(Player player, Location target) {
Land land = getLand(target);
return land == null || land.isTrusted(player.getUniqueId()) || hasFlag(target, player, Flags.BLOCK_BREAK);
return hasFlag(target, player, Flags.BLOCK_BREAK);
}

/**
Expand All @@ -49,32 +46,30 @@ public boolean canBreak(Player player, Location target) {
*/
@Override
public boolean canInteract(Player player, Location target) {
Land land = getLand(target);
return land == null || land.isTrusted(player.getUniqueId()) || hasFlag(target, player, Flags.INTERACT_GENERAL);
return hasFlag(target, player, Flags.INTERACT_GENERAL);
}

/**
* @param player Player looking to use an item
* @param target Place where the player seeks to use an item at a location
* @return true if he can use the item at the location
*/
@Override
public boolean canUse(Player player, Location target) {
Land land = getLand(target);
return land == null || land.isTrusted(player.getUniqueId()) || hasFlag(target, player, Flags.INTERACT_GENERAL);
}

private Land getLand(Location location) {
Area area = landsIntegration.getArea(location);
if (area == null) return null;
return area.getLand();
}

private Area getArea(Location location) {
return landsIntegration.getArea(location);
return hasFlag(target, player, Flags.INTERACT_GENERAL);
}

/**
* Checks if a player's role has a flag at the given position.
* This does check bypass perms and wilderness flags (/lands admin menu) as well.
*
* @param location Location of interaction
* @param player Player that seeks to do stuff
* @param flag The Lands flag
* @return false if not allowed
*/
private boolean hasFlag(Location location, Player player, RoleFlag flag) {
return getArea(location).hasRoleFlag(player.getUniqueId(), flag);
LandWorld landWorld = landsIntegration.getWorld(location.getWorld());
return landWorld == null || landWorld.hasRoleFlag(landsIntegration.getLandPlayer(player.getUniqueId()), location, flag, null, true);
}

}