Add per-world spawn limits with fallback to server-wide bukkit.yml settings.

Fixes BUKKIT-1565
This commit is contained in:
Travis Watkins 2012-04-23 19:01:22 -05:00 committed by EvilSeph
parent b7376e0865
commit edfc8ba92f
4 changed files with 81 additions and 1 deletions

View File

@ -93,7 +93,23 @@ public final class SpawnerCreature {
for (int j1 = 0; j1 < j; ++j1) { for (int j1 = 0; j1 < j; ++j1) {
EnumCreatureType enumcreaturetype = aenumcreaturetype[j1]; EnumCreatureType enumcreaturetype = aenumcreaturetype[j1];
if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && world.a(enumcreaturetype.a()) <= enumcreaturetype.b() * b.size() / 256) { // CraftBukkit start - use per-world spawn limits
int limit = 0;
switch(enumcreaturetype) {
case MONSTER:
limit = world.getWorld().getMonsterSpawnLimit();
case CREATURE:
limit = world.getWorld().getAnimalSpawnLimit();
case WATER_CREATURE:
limit = world.getWorld().getWaterAnimalSpawnLimit();
}
if (limit == 0) {
return 0;
}
// CraftBukkit end
if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && world.a(enumcreaturetype.a()) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits
// CraftBukkit start // CraftBukkit start
label108: label108:

View File

@ -142,6 +142,9 @@ public final class CraftServer implements Server {
private final EntityMetadataStore entityMetadata = new EntityMetadataStore(); private final EntityMetadataStore entityMetadata = new EntityMetadataStore();
private final PlayerMetadataStore playerMetadata = new PlayerMetadataStore(); private final PlayerMetadataStore playerMetadata = new PlayerMetadataStore();
private final WorldMetadataStore worldMetadata = new WorldMetadataStore(); private final WorldMetadataStore worldMetadata = new WorldMetadataStore();
private int monsterSpawn = -1;
private int animalSpawn = -1;
private int waterAnimalSpawn = -1;
static { static {
ConfigurationSerialization.registerClass(CraftOfflinePlayer.class); ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
@ -172,6 +175,9 @@ public final class CraftServer implements Server {
configuration.setDefaults(YamlConfiguration.loadConfiguration(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml"))); configuration.setDefaults(YamlConfiguration.loadConfiguration(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml")));
saveConfig(); saveConfig();
((SimplePluginManager) pluginManager).useTimings(configuration.getBoolean("settings.plugin-profiling")); ((SimplePluginManager) pluginManager).useTimings(configuration.getBoolean("settings.plugin-profiling"));
monsterSpawn = configuration.getInt("spawn-limits.monsters");
animalSpawn = configuration.getInt("spawn-limits.animals");
waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
updater = new AutoUpdater(new BukkitDLUpdaterService(configuration.getString("auto-updater.host")), getLogger(), configuration.getString("auto-updater.preferred-channel")); updater = new AutoUpdater(new BukkitDLUpdaterService(configuration.getString("auto-updater.host")), getLogger(), configuration.getString("auto-updater.preferred-channel"));
updater.setEnabled(configuration.getBoolean("auto-updater.enabled")); updater.setEnabled(configuration.getBoolean("auto-updater.enabled"));
@ -493,6 +499,9 @@ public final class CraftServer implements Server {
console.spawnAnimals = config.getBoolean("spawn-animals", console.spawnAnimals); console.spawnAnimals = config.getBoolean("spawn-animals", console.spawnAnimals);
console.pvpMode = config.getBoolean("pvp", console.pvpMode); console.pvpMode = config.getBoolean("pvp", console.pvpMode);
console.allowFlight = config.getBoolean("allow-flight", console.allowFlight); console.allowFlight = config.getBoolean("allow-flight", console.allowFlight);
monsterSpawn = configuration.getInt("spawn-limits.monsters");
animalSpawn = configuration.getInt("spawn-limits.animals");
waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
for (WorldServer world : console.worlds) { for (WorldServer world : console.worlds) {
world.difficulty = difficulty; world.difficulty = difficulty;
@ -1161,4 +1170,16 @@ public final class CraftServer implements Server {
public SimpleCommandMap getCommandMap() { public SimpleCommandMap getCommandMap() {
return commandMap; return commandMap;
} }
public int getMonsterSpawnLimit() {
return monsterSpawn;
}
public int getAnimalSpawnLimit() {
return animalSpawn;
}
public int getWaterAnimalSpawnLimit() {
return waterAnimalSpawn;
}
} }

View File

@ -56,6 +56,9 @@ public class CraftWorld implements World {
private final ChunkGenerator generator; private final ChunkGenerator generator;
private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>(); private final List<BlockPopulator> populators = new ArrayList<BlockPopulator>();
private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this); private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this);
private int monsterSpawn = -1;
private int animalSpawn = -1;
private int waterAnimalSpawn = -1;
private static final Random rand = new Random(); private static final Random rand = new Random();
@ -1119,4 +1122,40 @@ public class CraftWorld implements World {
public void removeMetadata(String metadataKey, Plugin owningPlugin) { public void removeMetadata(String metadataKey, Plugin owningPlugin) {
server.getWorldMetadata().removeMetadata(this, metadataKey, owningPlugin); server.getWorldMetadata().removeMetadata(this, metadataKey, owningPlugin);
} }
public int getMonsterSpawnLimit() {
if (monsterSpawn < 0) {
return server.getMonsterSpawnLimit();
}
return monsterSpawn;
}
public void setMonsterSpawnLimit(int limit) {
monsterSpawn = limit;
}
public int getAnimalSpawnLimit() {
if (animalSpawn < 0) {
return server.getAnimalSpawnLimit();
}
return animalSpawn;
}
public void setAnimalSpawnLimit(int limit) {
animalSpawn = limit;
}
public int getWaterAnimalSpawnLimit() {
if (waterAnimalSpawn < 0) {
return server.getWaterAnimalSpawnLimit();
}
return waterAnimalSpawn;
}
public void setWaterAnimalSpawnLimit(int limit) {
waterAnimalSpawn = limit;
}
} }

View File

@ -23,6 +23,10 @@ settings:
use-exact-login-location: false use-exact-login-location: false
plugin-profiling: false plugin-profiling: false
connection-throttle: 4000 connection-throttle: 4000
spawn-limits:
monsters: 70
animals: 15
water-animals: 5
ticks-per: ticks-per:
animal-spawns: 400 animal-spawns: 400
monster-spawns: 1 monster-spawns: 1