Add configurable spawn dimensions
This commit is contained in:
@@ -120,6 +120,9 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
private boolean generateSign = false;
|
||||
private boolean generateSpawn = true;
|
||||
private boolean setWorldSpawn = true;
|
||||
private int spawnSizeX = 1;
|
||||
private int spawnSizeY = 1;
|
||||
private int spawnSizeZ = 1;
|
||||
private Material spawnFloorMaterial = Material.COBBLESTONE;
|
||||
private boolean generateFloorSupports = false;
|
||||
private Material floorSupportMaterial = Material.STONE;
|
||||
@@ -250,6 +253,9 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
}
|
||||
generateSpawn = safeGetBooleanFromConfig(config, "spawn.generate");
|
||||
setWorldSpawn = safeGetBooleanFromConfig(config, "spawn.setAsWorldSpawn");
|
||||
spawnSizeX = optionalIntFromConfig(config, "spawn.sizeX", 1);
|
||||
spawnSizeY = optionalIntFromConfig(config, "spawn.sizeY", 1);
|
||||
spawnSizeZ = optionalIntFromConfig(config, "spawn.sizeZ", 1);
|
||||
spawnFloorMaterial = safeGetMaterialFromConfig(config, "spawn.material");
|
||||
generateWall = safeGetBooleanFromConfig(config, "wall.generate");
|
||||
wallMaterial = safeGetMaterialFromConfig(config, "wall.material");
|
||||
@@ -330,7 +336,8 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
|
||||
_spawnRegion = regionManager.getRegion("Spawn");
|
||||
if (_spawnRegion == null) {
|
||||
_spawnRegion = new ProtectedCuboidRegion("Spawn", getPlotMin(0, 0, 1), getPlotMax(0, 0, 1));
|
||||
Cuboid spawnCuboid = createSpawnCuboid();
|
||||
_spawnRegion = new ProtectedCuboidRegion("Spawn", spawnCuboid.getMin(), spawnCuboid.getMax());
|
||||
_spawnRegion.setPriority(1);
|
||||
_spawnRegion.setFlag(Flags.PVP, StateFlag.State.DENY);
|
||||
_spawnRegion.setFlag(Flags.MOB_DAMAGE, StateFlag.State.DENY);
|
||||
@@ -552,18 +559,18 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
|
||||
if (generateSpawn) {
|
||||
int x = 0;
|
||||
int y = roadLevel;
|
||||
int y = _spawnCuboid.minY;
|
||||
int z = 0;
|
||||
|
||||
// floor
|
||||
for (x = _spawnCuboid.getMinX(); x <= _spawnCuboid.getMaxX(); x++) {
|
||||
for (z = _spawnCuboid.getMinZ(); z <= _spawnCuboid.getMaxZ(); z++) {
|
||||
for (y = roadLevel + 1; y < world.getMaxHeight(); y++) {
|
||||
for (y = _spawnCuboid.minY + 1; y <= _spawnCuboid.maxY; y++) {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
y = roadLevel;
|
||||
y = _spawnCuboid.minY;
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
block.setType(spawnFloorMaterial);
|
||||
}
|
||||
@@ -574,10 +581,36 @@ public class MetropolisPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
if (setWorldSpawn) {
|
||||
world.setSpawnLocation(_spawnCuboid.getCenterX(), roadLevel + 1, _spawnCuboid.getCenterZ());
|
||||
world.setSpawnLocation(
|
||||
_spawnCuboid.getCenterX(), _spawnCuboid.minY + 1, _spawnCuboid.getCenterZ());
|
||||
}
|
||||
}
|
||||
|
||||
private Cuboid createSpawnCuboid() {
|
||||
Cuboid spawnCuboid =
|
||||
SpawnLayout.bounds(
|
||||
spawnSizeX,
|
||||
spawnSizeY,
|
||||
spawnSizeZ,
|
||||
plotSizeX,
|
||||
plotSizeY,
|
||||
plotSizeZ,
|
||||
roadWidth,
|
||||
roadLevel);
|
||||
if (!SpawnLayout.withinBuildHeight(spawnCuboid, world.getMinHeight(), world.getMaxHeight())) {
|
||||
getLogger()
|
||||
.severe(
|
||||
String.format(
|
||||
"Configured spawn bounds (%d to %d) exceed world build height (%d to %d).",
|
||||
spawnCuboid.minY,
|
||||
spawnCuboid.maxY,
|
||||
world.getMinHeight(),
|
||||
world.getMaxHeight() - 1));
|
||||
throw new IllegalArgumentException("Configured spawn height exceeds world build height.");
|
||||
}
|
||||
return spawnCuboid;
|
||||
}
|
||||
|
||||
private void fillOccupiedPlots() {
|
||||
_occupiedPlots.clear();
|
||||
_ownedPlots.clear();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
public final class SpawnLayout {
|
||||
private SpawnLayout() {}
|
||||
|
||||
public static Cuboid bounds(
|
||||
int sizeX,
|
||||
int sizeY,
|
||||
int sizeZ,
|
||||
int plotSizeX,
|
||||
int plotSizeY,
|
||||
int plotSizeZ,
|
||||
int roadWidth,
|
||||
int roadLevel) {
|
||||
if (sizeX < 1 || sizeY < 1 || sizeZ < 1 || roadWidth < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Spawn multipliers must be positive and road width nonnegative");
|
||||
}
|
||||
|
||||
int gridSizeX = Math.addExact(plotSizeX, roadWidth);
|
||||
int gridSizeZ = Math.addExact(plotSizeZ, roadWidth);
|
||||
int inset = roadWidth / 2;
|
||||
int maxInset = roadWidth - inset;
|
||||
int maxX = Math.subtractExact(Math.multiplyExact(sizeX, gridSizeX) - 1, maxInset);
|
||||
int maxY = Math.addExact(roadLevel, Math.multiplyExact(sizeY, plotSizeY) - 1);
|
||||
int maxZ = Math.subtractExact(Math.multiplyExact(sizeZ, gridSizeZ) - 1, maxInset);
|
||||
|
||||
return new Cuboid(inset, roadLevel, inset, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public static boolean withinBuildHeight(Cuboid cuboid, int minHeight, int maxHeight) {
|
||||
return cuboid.minY >= minHeight && cuboid.maxY < maxHeight;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user