gries/mcontrol

控制运行中的Minecraft服务器用的PHP库

v0.1.1-beta 2014-01-12 18:56 UTC

This package is auto-updated.

Last update: 2024-09-16 21:27:14 UTC


README

MControl是一个通过rcon协议控制Minecraft服务器的库。

SensioLabsInsight

Build Status

安装

MControl可以通过Composer安装。

{
    "require": {
        "gries/MControl": "dev-master"
    },
     "minimum-stability": "dev"
}

基本用法

use gries\MControl\Server\Commander;
use gries\MControl\Server\Rcon\RconManager;

// create a RconConnection
$rcon = new RconManager('localhost', 25575, 'p4ssw0rd');

// create a Commander
$commander = new Commander($rcon);

// set the server-time
$commander->setTime('12000');

// listPlayers
$players = $commander->listPlayers(); // -> array('playerx', 'playery');

// teleport one player to another
$commander->teleport(array('playerx', 'playery'));

// locate a player
$location = $commander->locate('playerx');  // -> array('x' => 157, 'y' => 50, 'z' => -54);

// execute a raw command
$response = $commander->raw('my custom command string');

构建结构

....
use gries\MControl\Builder\Block;
use gries\MControl\Builder\Structure;
use gries\MControl\Server\StructureBuilder;
...

// create a structure-builder
$structureBuilder = new StructureBuilder($commander);

// create a new structure
$structure = new Structure();

// add some blocks
// in this case build a sand tower that is five blocks high
for ($i = 0; $i < 5; $i++)
{
    $structure->createBlock('sand', array('x' => 1, 'y' => $i, 'z' => 1));
}

// add a row of 3 sand blocks on the Y axis
// starting on 1:1:1
$structure->addRow('y', 'sand', 3);

// build it on the server
$structureBuilder->build($structure);

将图像转换为结构

要将图像转换为结构,需要PHP的imagick扩展。

以下示例将构建一个5块高的结构,由空气和树叶组成。每个黑色像素将是树叶,每个白色像素将是空气。结构将放置在x -> 33,z -> 19。

结果可以在以下视频中查看: https://vimeo.com/79598411

$converter = new ImageToStructureConverter();
$converter->setBlackBlockType('leaves');
$converter->setWhiteBlockType('air');

$image     = new Imagick('test.png');
$structure = $converter->convert($image, 5);
$structureBuilder->build($structure,
    array('x' => '-33',
          'y' => '3',
          'z' => '19')
);

保存结构以供后续使用

您可以使用StructureRepository持久化结构以供以后使用。目前此仓库默认使用sqlite数据库存储数据,此行为可以通过创建自定义EntityManager并传递给StructureRepositoryFactory来轻松更改。

// bootstrap doctrine
$entityManager = require_once __DIR__ . '/bootstrap.php';

// create a repository
$factory = new StructureRepositoryFactory();
$repository = $factory->create($entityManager);

// create a new structure
$structure = new Structure();
$structure->createBlock('iron', array('x' => 1, 'y' => 1, 'z' => 1));
$structure->setName('greatness');

// save it to the database
$repository->add($structure);

// get it from the database
$repository->getByName('greatness');

目前为Commander提供了以下命令

  • 列出玩家
  • 定位玩家
  • 传送
  • 给予
  • 设置天气
  • 设置时间
  • 设置方块
  • 原始

运行测试

bin/phpspec run

贡献!

请通过github issues提供反馈/功能请求/错误报告。或者直接发送pull-request :)

作者

许可

有关完整的版权和许可信息,请查看与源代码一起分发的LICENSE文件。