Skip to content

Commit

Permalink
check flags in wilderness and bypass perms support
Browse files Browse the repository at this point in the history
  • Loading branch information
Angeschossen committed Aug 31, 2023
1 parent aab5fbe commit 92b18d8
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package io.github.bakedlibs.dough.protection.modules;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

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.player.LandPlayer;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import io.github.bakedlibs.dough.protection.Interaction;
import io.github.bakedlibs.dough.protection.ProtectionModule;

import me.angeschossen.lands.api.land.Area;
import me.angeschossen.lands.api.land.LandWorld;

public class LandsProtectionModule implements ProtectionModule {
Expand All @@ -39,14 +39,17 @@ public void load() {

@Override
public boolean hasPermission(OfflinePlayer p, Location l, Interaction action) {
LandWorld landWorld = landsIntegration.getWorld(l.getWorld());

@Nullable LandWorld landWorld = landsIntegration.getWorld(l.getWorld()); // landWorld is used for permission checks, since flags can be toggled in wilderness as well
if (landWorld == null) {
return true;
return true; // this is not a claim world
}

Area area = landWorld.getArea(l);
return area == null || area.hasRoleFlag(p.getUniqueId(), convert(action));
@Nullable LandPlayer landPlayer = landsIntegration.getLandPlayer(p.getUniqueId()); // null if the player is offline
if (landPlayer == null) { // if the player is offline, check against UUID without bypass permissions
return landWorld.hasRoleFlag(p.getUniqueId(), l, convert(action));
} else { // if online, check against online player with bypass permissions
return landWorld.hasRoleFlag(landPlayer, l, convert(action), null, false); // we don't know the block material and don't want to send a denied message
}
}

private @Nonnull RoleFlag convert(@Nonnull Interaction protectableAction) {
Expand All @@ -65,4 +68,4 @@ public boolean hasPermission(OfflinePlayer p, Location l, Interaction action) {
return Flags.INTERACT_VILLAGER;
}
}
}
}

0 comments on commit 92b18d8

Please sign in to comment.