Skip to content

Commit

Permalink
Merge pull request #99 from TheNextLvl-net/mask
Browse files Browse the repository at this point in the history
Refactor region mask initialization for clarity
  • Loading branch information
NonSwag authored Dec 8, 2024
2 parents d7259a3 + 1859d25 commit ecaf7d4
Showing 1 changed file with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionIntersection;
import com.sk89q.worldedit.world.World;
import net.thenextlvl.protect.ProtectPlugin;
import net.thenextlvl.protect.area.Area;
import net.thenextlvl.protect.area.GlobalArea;
Expand All @@ -16,6 +17,7 @@
import org.jspecify.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -54,12 +56,28 @@ public ProtectMaskManager(ProtectPlugin plugin) {
else if (area instanceof GlobalArea) regions.add(GLOBAL);
}

return new FaweMask(new RegionIntersection(player.getWorld(), regions)) {
@Override
public boolean isValid(Player player, MaskType type) {
return areas.stream().allMatch(area -> plugin.protectionService().canEdit(bukkit, area));
}
};
return new RegionMask(bukkit, regions, areas, player.getWorld());
}

private final class RegionMask extends FaweMask {
private final org.bukkit.entity.Player player;
private final Collection<Area> areas;

public RegionMask(
org.bukkit.entity.Player player,
Collection<Region> regions,
Collection<Area> areas,
World world
) {
super(new RegionIntersection(world, regions));
this.player = player;
this.areas = areas;
}

@Override
public boolean isValid(Player ignored, MaskType type) {
return areas.stream().allMatch(area -> plugin.protectionService().canEdit(player, area));
}
}

public List<Area> getAreas(org.bukkit.entity.Player player, boolean whitelist) {
Expand Down

0 comments on commit ecaf7d4

Please sign in to comment.