Added spawn on square perimeter

This commit is contained in:
patinok
2012-05-12 20:05:18 +03:00
parent 5ba8954af7
commit 0ade0f99f5
2 changed files with 45 additions and 17 deletions

View File

@@ -75,23 +75,50 @@ public class RandomSpawn extends JavaPlugin{
int xmax = yamlHandler.worlds.getInt(worldName +".spawnarea.x-max", 100); int xmax = yamlHandler.worlds.getInt(worldName +".spawnarea.x-max", 100);
int zmin = yamlHandler.worlds.getInt(worldName +".spawnarea.z-min", -100); int zmin = yamlHandler.worlds.getInt(worldName +".spawnarea.z-min", -100);
int zmax = yamlHandler.worlds.getInt(worldName +".spawnarea.z-max", 100); int zmax = yamlHandler.worlds.getInt(worldName +".spawnarea.z-max", 100);
// Spawn area thickness near border. If 0 spawns whole area
int thickness = yamlHandler.worlds.getInt(worldName +".spawnarea.thickness", 0);
int xrand = 0; int xrand = 0;
int zrand = 0; int zrand = 0;
int y = -1; int y = -1;
do { do {
xrand = xmin + (int) ( Math.random()*(xmax - xmin) + 0.5 ); if (thickness <= 0) {
zrand = zmin + (int) ( Math.random()*(zmax - zmin) + 0.5 ); xrand = xmin + (int) ( Math.random()*(xmax - xmin + 1) );
y = getValidHighestBlock(world, xrand,zrand); zrand = zmin + (int) ( Math.random()*(zmax - zmin + 1) );
}while (y == -1); }
else {
int side = (int) (Math.random() * 4d);
int borderOffset = (int) (Math.random() * (double) thickness);
if (side == 0) {
xrand = xmin + borderOffset;
// Also balancing probability considering thickness
zrand = zmin + (int) ( Math.random() * (zmax - zmin + 1 - 2*thickness) ) + thickness;
}
else if (side == 1) {
xrand = xmax - borderOffset;
zrand = zmin + (int) ( Math.random() * (zmax - zmin + 1 - 2*thickness) ) + thickness;
}
else if (side == 2) {
xrand = xmin + (int) ( Math.random() * (xmax - xmin + 1) );
zrand = zmin + borderOffset;
}
else {
xrand = xmin + (int) ( Math.random() * (xmax - xmin + 1) );
zrand = zmax - borderOffset;
}
logDebug("Choosed side for spawn: " + side + "; x = " + xrand + "; z = " + zrand);
}
y = getValidHighestBlock(world, xrand, zrand);
} while (y == -1);
return new Location( return new Location(
world, world,
Double.parseDouble(Integer.toString(xrand)) + 0.5, Double.parseDouble(Integer.toString(xrand)),
Double.parseDouble(Integer.toString(y)), Double.parseDouble(Integer.toString(y)),
Double.parseDouble(Integer.toString(zrand)) + 0.5 Double.parseDouble(Integer.toString(zrand))
); );
} }
private int getValidHighestBlock(World world, int x, int z) { private int getValidHighestBlock(World world, int x, int z) {

View File

@@ -12,3 +12,4 @@ exampleworld:
x-max: 100 x-max: 100
z-min: -100 z-min: -100
z-max: 100 z-max: 100
thickness: 1