mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-20 23:11:21 +00:00
Made /help not shit
This commit is contained in:
parent
fe2f220f10
commit
cbb2068454
3 changed files with 41 additions and 24 deletions
|
|
@ -3,6 +3,8 @@ class Command {
|
|||
this.params = params;
|
||||
this.parent = parent;
|
||||
this.hash = parent ? parent.hash : {};
|
||||
this.parentBase = (this.parent && this.parent.base && this.parent.base + ' ') || '';
|
||||
this.base = this.parentBase + (this.params.base || '');
|
||||
|
||||
this.updateHistory();
|
||||
}
|
||||
|
|
@ -44,9 +46,9 @@ class Command {
|
|||
updateHistory() {
|
||||
var all = '(.+?)';
|
||||
|
||||
var list = [this.params.base];
|
||||
var list = [this.base];
|
||||
if(this.params.aliases && this.params.aliases.length) {
|
||||
this.params.aliases.forEach(al => list.unshift(al));
|
||||
this.params.aliases.forEach(al => list.unshift(this.parentBase + al));
|
||||
}
|
||||
|
||||
list.forEach((command) => {
|
||||
|
|
|
|||
|
|
@ -7,29 +7,45 @@ module.exports.player=function(player, serv) {
|
|||
base: 'help',
|
||||
info: 'to show all commands',
|
||||
usage: '/help [command]',
|
||||
action(params) {
|
||||
var c = params[0];
|
||||
parse(str) {
|
||||
var params = str.split(' ');
|
||||
var page = parseInt(params[params.length-1]);
|
||||
var search = '';
|
||||
if (page) {
|
||||
params.pop();
|
||||
}
|
||||
search = params.join(' ');
|
||||
return { search: search, page: (page && page - 1) || 0 };
|
||||
},
|
||||
action({search, page}) {
|
||||
if (page < 0) return 'Page # must be >= 1';
|
||||
var hash = player.commands.hash;
|
||||
|
||||
if(c) {
|
||||
var f=player.commands.find(c);
|
||||
if(f==undefined || f.length==0) return 'Command '+c+' not found';
|
||||
return f[0].params.usage + ' ' + f[0].params.info;
|
||||
var PAGE_LENGTH = 8;
|
||||
|
||||
var found = Object.keys(hash).filter(h => (h + ' ').indexOf((search && search + ' ') || '') == 0);
|
||||
var totalPages = Math.floor(found.length / PAGE_LENGTH);
|
||||
if (found.length > 1 && totalPages < page) {
|
||||
return 'There are only ' + (totalPages + 1) + ' help pages.';
|
||||
}
|
||||
|
||||
if (found.indexOf(search) != -1) {
|
||||
var cmd = hash[search];
|
||||
player.chat('/' + cmd.base + ' -' + ((cmd.params && ' ' + cmd.params.info) || '=-=-=-=-=-=-=-=-'));
|
||||
if (cmd.params && cmd.params.usage) player.chat(cmd.params.usage);
|
||||
} else if (found.length > 1) {
|
||||
player.chat('Help -=-=-=-=-=-=-=-=-');
|
||||
}
|
||||
|
||||
if (found.length == 0) {
|
||||
return 'Could not find any matches';
|
||||
} else {
|
||||
var used = [];
|
||||
for(var key in hash) {
|
||||
if(used.indexOf(hash[key]) > -1) continue;
|
||||
used.push(hash[key]);
|
||||
|
||||
if(hash[key].params.info && (player.op || !hash[key].params.op)) {
|
||||
var str = hash[key].params.usage + ' ' + hash[key].params.info;
|
||||
if(hash[key].params.aliases && hash[key].params.aliases.length) {
|
||||
str += ' (aliases: ' + hash[key].params.aliases.join(', ') + ')';
|
||||
}
|
||||
|
||||
player.chat(str);
|
||||
}
|
||||
found = found.sort();
|
||||
for (var i = PAGE_LENGTH*page; i < Math.min(PAGE_LENGTH*(page + 1), found.length); i++) {
|
||||
var cmd = hash[found[i]];
|
||||
player.chat(cmd.params.base + ': ' + cmd.params.info);
|
||||
}
|
||||
player.chat('--=[Page ' + (page + 1) + ' of ' + (totalPages + 1) + ']=--')
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ module.exports.player=function(player)
|
|||
}
|
||||
|
||||
player._client.on('position', ({x,y,z,onGround} = {}) => {
|
||||
console.log(x,y,z);
|
||||
player.sendPosition((new Vec3(x, y, z)).toFixedPosition(), onGround);
|
||||
});
|
||||
|
||||
|
|
@ -88,13 +87,13 @@ module.exports.entity=function(entity,serv){
|
|||
pitch: entity.pitch,
|
||||
onGround: onGround
|
||||
});
|
||||
else if (diff.distanceTo(new Vec3(0, 0, 0)) != 0) serv._writeNearby('rel_entity_move', {
|
||||
else if (diff.distanceTo(new Vec3(0, 0, 0)) != 0) serv._writeOthersNearby('rel_entity_move', {
|
||||
entityId: entity.id,
|
||||
dX: diff.x,
|
||||
dY: diff.y,
|
||||
dZ: diff.z,
|
||||
onGround: onGround
|
||||
}, entity);
|
||||
});
|
||||
|
||||
entity.position = position;
|
||||
entity.onGround = onGround;
|
||||
|
|
|
|||
Loading…
Reference in a new issue