Fix RegionSystem.GLOBAL_REGION_ID

Improve RegionUtils.forEachInRegion
This commit is contained in:
2026-02-19 21:01:20 +01:00
parent a580087df8
commit 5f1aef6a1e
2 changed files with 10 additions and 7 deletions
@@ -31,10 +31,10 @@ import java.util.stream.Stream;
public interface RegionSystem {
RegionSystem INSTANCE = init();
UUID GLOBAL_REGION_ID = new UUID(0, 0);
RegionSystem INSTANCE = init();
/**
* Loads and initializes the Regions and anything that should be loaded on startup.
*/
@@ -28,6 +28,7 @@ import org.bukkit.entity.Player;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
@UtilityClass
public class RegionUtils {
@@ -58,10 +59,12 @@ public class RegionUtils {
}
public void forEachInRegion(Region region, Consumer<Player> consumer) {
Bukkit.getOnlinePlayers()
.stream()
.filter(player -> region.getArea().inRegion(player.getLocation(), false))
.filter(player -> !region.getType().isGlobal() || Region.getRegion(player.getLocation()).getType().isGlobal())
.forEach(consumer);
Stream<? extends Player> players = Bukkit.getOnlinePlayers().stream();
if (region.getType().isGlobal()) {
players = players.filter(player -> Region.getRegion(player.getLocation()).getType().isGlobal());
} else {
players = players.filter(player -> region.getArea().inRegion(player.getLocation(), false));
}
players.forEach(consumer);
}
}