mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-19 06:21:08 +00:00
fix bug in /tp and add regression tests
This commit is contained in:
parent
b4b90c01ed
commit
ae6d9887fd
3 changed files with 59 additions and 18 deletions
|
|
@ -15,6 +15,8 @@ module.exports.server=function(serv,options)
|
|||
try {
|
||||
var player = serv.initEntity('player', null, serv.overworld, new Vec3(0,0,0));
|
||||
player._client=client;
|
||||
|
||||
player.profileProperties=player._client.profile ? player._client.profile.properties : [];
|
||||
player.commands = new Command({});
|
||||
Object.keys(plugins)
|
||||
.filter(pluginName => plugins[pluginName].player!=undefined)
|
||||
|
|
@ -95,8 +97,6 @@ module.exports.player=function(player,serv)
|
|||
|
||||
function fillTabList()
|
||||
{
|
||||
player.profileProperties=player._client.profile ? player._client.profile.properties : [];
|
||||
|
||||
player._writeOthers('player_info',{
|
||||
action: 0,
|
||||
data: [{
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ module.exports.player = (player, serv) => {
|
|||
if(!(player_from = serv.getPlayer(args[0])))
|
||||
return false;
|
||||
|
||||
let x = getPos(args[0], 'x', player_from);
|
||||
let y = getPos(args[1], 'y', player_from);
|
||||
let z = getPos(args[2], 'z', player_from);
|
||||
let x = getPos(args[1], 'x', player_from);
|
||||
let y = getPos(args[2], 'y', player_from);
|
||||
let z = getPos(args[3], 'z', player_from);
|
||||
|
||||
player_from.teleport(new Vec3(x, y, z));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,18 @@ var net = require('net');
|
|||
var mcServer=require("../");
|
||||
var settings = require('../config/default-settings');
|
||||
var mineflayer = require("mineflayer");
|
||||
var assert = require('chai').assert;
|
||||
var Vec3 = require('vec3').Vec3;
|
||||
|
||||
function assertPosEqual(pos1,pos2) {
|
||||
assert.isBelow(pos1.distanceTo(pos2),0.01);
|
||||
}
|
||||
|
||||
|
||||
describe("Server with mineflayer connection", function() {
|
||||
var bot;
|
||||
var bot2;
|
||||
var serv;
|
||||
var player;
|
||||
before(function(done){
|
||||
var options = settings;
|
||||
options["online-mode"]=false;
|
||||
|
|
@ -19,16 +25,25 @@ describe("Server with mineflayer connection", function() {
|
|||
bot = mineflayer.createBot({
|
||||
host: "localhost",
|
||||
port: 25566,
|
||||
username: "echo"
|
||||
username: "bot"
|
||||
});
|
||||
bot2 = mineflayer.createBot({
|
||||
host: "localhost",
|
||||
port: 25566,
|
||||
username: "bot2"
|
||||
});
|
||||
|
||||
serv.once("newPlayer",function(p){
|
||||
player=p;
|
||||
});
|
||||
var nbSpawn=0;
|
||||
|
||||
function spawn() {
|
||||
nbSpawn++;
|
||||
if(nbSpawn==2)
|
||||
done();
|
||||
}
|
||||
|
||||
bot.on('spawn', spawn);
|
||||
bot2.on('spawn', spawn);
|
||||
|
||||
bot.on('spawn', function() {
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
|
@ -47,23 +62,49 @@ describe("Server with mineflayer connection", function() {
|
|||
bot.chat("/help");
|
||||
});
|
||||
it("can use /particle",function(done){
|
||||
bot._client.on('world_particles',function(){
|
||||
bot._client.once('world_particles',function(){
|
||||
done();
|
||||
});
|
||||
bot.chat("/particle 5 10 100 100 100");
|
||||
});
|
||||
it("can use /playsound",function(done) {
|
||||
bot.on('soundEffectHeard',function(){
|
||||
bot.once('soundEffectHeard',function(){
|
||||
done();
|
||||
});
|
||||
bot.chat('/playsound ambient.weather.rain');
|
||||
});
|
||||
it("can use /summon",function(done) {
|
||||
bot.on('entitySpawn',function(entity){
|
||||
if(entity.name=="EnderDragon")
|
||||
var listener=function(entity){
|
||||
if(entity.name=="EnderDragon") {
|
||||
bot.removeListener('entitySpawn',listener);
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
bot.on('entitySpawn',listener);
|
||||
bot.chat('/summon EnderDragon');
|
||||
});
|
||||
describe("can use /tp",function() {
|
||||
it("can tp myself",function(done) {
|
||||
bot.once('forcedMove', function () {
|
||||
assertPosEqual(bot.entity.position,new Vec3(2, 3, 4));
|
||||
done();
|
||||
});
|
||||
bot.chat('/tp 2 3 4');
|
||||
});
|
||||
it("can tp somebody else",function(done) {
|
||||
bot2.once('forcedMove', function () {
|
||||
assertPosEqual(bot2.entity.position,new Vec3(2, 3, 4));
|
||||
done();
|
||||
});
|
||||
bot.chat('/tp bot2 2 3 4');
|
||||
});
|
||||
it("can tp to somebody else",function(done) {
|
||||
bot2.once('forcedMove', function () {
|
||||
assertPosEqual(bot2.entity.position,bot.entity.position);
|
||||
done();
|
||||
});
|
||||
bot.chat('/tp bot2 bot');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue