have a options["max-entities"], fix #222

This commit is contained in:
Romain Beaumont 2016-03-14 21:13:52 +01:00
parent 6f36e7c450
commit fed2208809
2 changed files with 6 additions and 5 deletions

View file

@ -22,5 +22,6 @@
"header":"Flying squid", "header":"Flying squid",
"footer":"Test server" "footer":"Test server"
}, },
"everybody-op":true "everybody-op":true,
"max-entities":100
} }

View file

@ -73,14 +73,14 @@ module.exports.server=function(serv,options) {
}; };
module.exports.player=function(player,serv){ module.exports.player=function(player,serv,options){
player.commands.add({ player.commands.add({
base: 'summon', base: 'summon',
info: 'Summon an entity', info: 'Summon an entity',
usage: '/summon <entity_name>', usage: '/summon <entity_name>',
op: true, op: true,
action(name) { action(name) {
if(Object.keys(serv.entities).length>100) if(Object.keys(serv.entities).length>options["max-entities"])
throw new UserError("Too many mobs !"); throw new UserError("Too many mobs !");
const entity=entitiesByName[name]; const entity=entitiesByName[name];
if(!entity) { if(!entity) {
@ -108,7 +108,7 @@ module.exports.player=function(player,serv){
return {number:args[0],name:args[1]}; return {number:args[0],name:args[1]};
}, },
action({number,name}) { action({number,name}) {
if(Object.keys(serv.entities).length>100-number) if(Object.keys(serv.entities).length>options["max-entities"]-number)
throw new UserError("Too many mobs !"); throw new UserError("Too many mobs !");
const entity=entitiesByName[name]; const entity=entitiesByName[name];
if(!entity) { if(!entity) {
@ -143,7 +143,7 @@ module.exports.player=function(player,serv){
.filter(entity => !!entity); .filter(entity => !!entity);
}, },
action(entityTypes) { action(entityTypes) {
if(Object.keys(serv.entities).length>100-entityTypes.length) if(Object.keys(serv.entities).length>options["max-entities"]-entityTypes.length)
throw new UserError("Too many mobs !"); throw new UserError("Too many mobs !");
entityTypes.map(entity => { entityTypes.map(entity => {
if(entity.type=="mob") serv.spawnMob(entity.id, player.world, player.position.scaled(1/32), { if(entity.type=="mob") serv.spawnMob(entity.id, player.world, player.position.scaled(1/32), {