mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-14 12:01:12 +00:00
make /attach use the selectors, fix UserError, check /tp has one target
see http://stackoverflow.com/a/32749533 for UserError
This commit is contained in:
parent
3bea548f82
commit
9366c1b9a7
4 changed files with 32 additions and 12 deletions
|
|
@ -118,7 +118,7 @@ module.exports.player=function(player, serv) {
|
|||
if (res) player.chat('' + res);
|
||||
}
|
||||
catch(err) {
|
||||
if (err instanceof UserError) player.chat('Error: ' + err.toString());
|
||||
if (err instanceof UserError) player.chat('Error: ' + err.message);
|
||||
else setTimeout(() => {throw err;}, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ var path = require('path');
|
|||
var requireIndex = require('requireindex');
|
||||
var plugins = requireIndex(path.join(__dirname,'..', 'plugins'));
|
||||
var Item = require("prismarine-item")(version);
|
||||
var UserError = require('flying-squid').UserError;
|
||||
|
||||
var Vec3 = require("vec3").Vec3;
|
||||
|
||||
|
|
@ -128,19 +129,24 @@ module.exports.player=function(player,serv){
|
|||
player.commands.add({
|
||||
base: 'attach',
|
||||
info: 'attach an entity on an other entity',
|
||||
usage: '/attach <carrierId> <attachedId>',
|
||||
usage: '/attach <carrier> <attached>',
|
||||
op: true,
|
||||
parse(str) {
|
||||
var pars=str.split(' ');
|
||||
if(pars.length!=2)
|
||||
var args=str.split(' ');
|
||||
if(args.length!=2)
|
||||
return false;
|
||||
var [carrierId,attachedId]=pars.map(a => parseInt(a));
|
||||
return {carrierId:carrierId,attachedId:attachedId};
|
||||
|
||||
let carrier = player.selectorString(args[0]);
|
||||
if(carrier.length==0) throw new UserError("one carrier");
|
||||
let attached = player.selectorString(args[1]);
|
||||
if(attached.length==0) throw new UserError("one attached");
|
||||
|
||||
return {carrier:carrier[0],attached:attached[0]};
|
||||
},
|
||||
action({carrierId,attachedId}) {
|
||||
action({carrier,attached}) {
|
||||
var p={
|
||||
entityId:attachedId,
|
||||
vehicleId:carrierId,
|
||||
entityId:attached.id,
|
||||
vehicleId:carrier.id,
|
||||
leash:false
|
||||
};
|
||||
player._client.write('attach_entity',p);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
var Vec3 = require("vec3").Vec3;
|
||||
var UserError = require('flying-squid').UserError;
|
||||
|
||||
module.exports.player = (player, serv) => {
|
||||
|
||||
|
|
@ -14,7 +15,9 @@ module.exports.player = (player, serv) => {
|
|||
action(args) {
|
||||
if(args.length === 2) {
|
||||
let entities_from = player.selectorString(args[0]);
|
||||
let entity_to = player.selectorString(args[1])[0];
|
||||
let entity_to = player.selectorString(args[1]);
|
||||
if(entity_to.length==0) throw new UserError("at least one target");
|
||||
entity_to = entity_to[0];
|
||||
|
||||
entities_from.forEach(e => e.teleport(entity_to.position.scaled(1/32)));
|
||||
} else if(args.length === 3) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,16 @@
|
|||
class UserError extends Error {
|
||||
|
||||
class ExtendableError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
this.message = message;
|
||||
Error.captureStackTrace(this, this.constructor.name)
|
||||
}
|
||||
}
|
||||
|
||||
class UserError extends ExtendableError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserError;
|
||||
Loading…
Reference in a new issue