Avoid saved WorldGuard regions during allocation

This commit is contained in:
2026-09-27 08:24:03 -07:00
parent 60c3d41e50
commit 99f6195542
5 changed files with 118 additions and 2 deletions

View File

@@ -90,6 +90,7 @@ public class MetropolisPlugin extends JavaPlugin {
private HashMap<UUID, UserOverride> _userOverrides;
private List<HomePermissionOverride> _permissionOverrides;
private HashMap<UUID, Integer> _currentHomes;
private List<Cuboid> _savedWorldGuardBounds = List.of();
private PlayerJoinListener _playerJoinListener = null;
@@ -891,7 +892,7 @@ public class MetropolisPlugin extends JavaPlugin {
return true;
}
return false;
return WorldGuardRegionOccupancy.overlapsAny(cuboid, _savedWorldGuardBounds);
}
private boolean areBlocksOccupied(int row, int col, int i) {
@@ -911,6 +912,8 @@ public class MetropolisPlugin extends JavaPlugin {
}
private Cuboid findNextUnownedHomeRegion(int plotMultiplier) {
refreshSavedWorldGuardBounds();
int row = 0;
int col = 0;
int ring = 0;
@@ -995,6 +998,11 @@ public class MetropolisPlugin extends JavaPlugin {
return null;
}
private void refreshSavedWorldGuardBounds() {
_savedWorldGuardBounds =
WorldGuardRegionOccupancy.boundsToAvoid(regionManager.getRegions().values());
}
private boolean isAvailableSupportedPlot(int row, int col, int plotMultiplier, int level) {
return !areBlocksOccupied(row, col, plotMultiplier, level)
&& PlotLevelSupport.hasCompleteSupport(

View File

@@ -0,0 +1,44 @@
/*
This file is part of Metropolis.
Metropolis is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Metropolis is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
*/
package com.majinnaibu.bukkitplugins.metropolis;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public final class WorldGuardRegionOccupancy {
private WorldGuardRegionOccupancy() {}
public static List<Cuboid> boundsToAvoid(Collection<ProtectedRegion> regions) {
List<Cuboid> bounds = new ArrayList<>();
for (ProtectedRegion region : regions) {
String id = region.getId();
if (id.equalsIgnoreCase("city") || id.equalsIgnoreCase("__global__")) {
continue;
}
bounds.add(new Cuboid(region.getMinimumPoint(), region.getMaximumPoint()));
}
return List.copyOf(bounds);
}
public static boolean overlapsAny(Cuboid candidate, Collection<Cuboid> occupiedBounds) {
return occupiedBounds.stream().anyMatch(candidate::intersects);
}
}