mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-06 03:31:10 +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 {
|
try {
|
||||||
var player = serv.initEntity('player', null, serv.overworld, new Vec3(0,0,0));
|
var player = serv.initEntity('player', null, serv.overworld, new Vec3(0,0,0));
|
||||||
player._client=client;
|
player._client=client;
|
||||||
|
|
||||||
|
player.profileProperties=player._client.profile ? player._client.profile.properties : [];
|
||||||
player.commands = new Command({});
|
player.commands = new Command({});
|
||||||
Object.keys(plugins)
|
Object.keys(plugins)
|
||||||
.filter(pluginName => plugins[pluginName].player!=undefined)
|
.filter(pluginName => plugins[pluginName].player!=undefined)
|
||||||
|
|
@ -95,8 +97,6 @@ module.exports.player=function(player,serv)
|
||||||
|
|
||||||
function fillTabList()
|
function fillTabList()
|
||||||
{
|
{
|
||||||
player.profileProperties=player._client.profile ? player._client.profile.properties : [];
|
|
||||||
|
|
||||||
player._writeOthers('player_info',{
|
player._writeOthers('player_info',{
|
||||||
action: 0,
|
action: 0,
|
||||||
data: [{
|
data: [{
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ module.exports.player = (player, serv) => {
|
||||||
if(!(player_from = serv.getPlayer(args[0])))
|
if(!(player_from = serv.getPlayer(args[0])))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
let x = getPos(args[0], 'x', player_from);
|
let x = getPos(args[1], 'x', player_from);
|
||||||
let y = getPos(args[1], 'y', player_from);
|
let y = getPos(args[2], 'y', player_from);
|
||||||
let z = getPos(args[2], 'z', player_from);
|
let z = getPos(args[3], 'z', player_from);
|
||||||
|
|
||||||
player_from.teleport(new Vec3(x, y, z));
|
player_from.teleport(new Vec3(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,18 @@ var net = require('net');
|
||||||
var mcServer=require("../");
|
var mcServer=require("../");
|
||||||
var settings = require('../config/default-settings');
|
var settings = require('../config/default-settings');
|
||||||
var mineflayer = require("mineflayer");
|
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() {
|
describe("Server with mineflayer connection", function() {
|
||||||
var bot;
|
var bot;
|
||||||
|
var bot2;
|
||||||
var serv;
|
var serv;
|
||||||
var player;
|
|
||||||
before(function(done){
|
before(function(done){
|
||||||
var options = settings;
|
var options = settings;
|
||||||
options["online-mode"]=false;
|
options["online-mode"]=false;
|
||||||
|
|
@ -19,16 +25,25 @@ describe("Server with mineflayer connection", function() {
|
||||||
bot = mineflayer.createBot({
|
bot = mineflayer.createBot({
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 25566,
|
port: 25566,
|
||||||
username: "echo"
|
username: "bot"
|
||||||
|
});
|
||||||
|
bot2 = mineflayer.createBot({
|
||||||
|
host: "localhost",
|
||||||
|
port: 25566,
|
||||||
|
username: "bot2"
|
||||||
});
|
});
|
||||||
|
|
||||||
serv.once("newPlayer",function(p){
|
var nbSpawn=0;
|
||||||
player=p;
|
|
||||||
});
|
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");
|
bot.chat("/help");
|
||||||
});
|
});
|
||||||
it("can use /particle",function(done){
|
it("can use /particle",function(done){
|
||||||
bot._client.on('world_particles',function(){
|
bot._client.once('world_particles',function(){
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
bot.chat("/particle 5 10 100 100 100");
|
bot.chat("/particle 5 10 100 100 100");
|
||||||
});
|
});
|
||||||
it("can use /playsound",function(done) {
|
it("can use /playsound",function(done) {
|
||||||
bot.on('soundEffectHeard',function(){
|
bot.once('soundEffectHeard',function(){
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
bot.chat('/playsound ambient.weather.rain');
|
bot.chat('/playsound ambient.weather.rain');
|
||||||
});
|
});
|
||||||
it("can use /summon",function(done) {
|
it("can use /summon",function(done) {
|
||||||
bot.on('entitySpawn',function(entity){
|
var listener=function(entity){
|
||||||
if(entity.name=="EnderDragon")
|
if(entity.name=="EnderDragon") {
|
||||||
|
bot.removeListener('entitySpawn',listener);
|
||||||
done();
|
done();
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
bot.on('entitySpawn',listener);
|
||||||
bot.chat('/summon EnderDragon');
|
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