Added API for transferring players to other servers (#355)

* Added API method `Player->transfer()` and PlayerTransferEvent
This commit is contained in:
Dylan K. Taylor
2017-03-04 18:22:31 +00:00
committed by GitHub
parent 663cb514e2
commit 4ee8d14584
5 changed files with 152 additions and 1 deletions

View File

@ -57,6 +57,7 @@ use pocketmine\command\defaults\TeleportCommand;
use pocketmine\command\defaults\TellCommand;
use pocketmine\command\defaults\TimeCommand;
use pocketmine\command\defaults\TimingsCommand;
use pocketmine\command\defaults\TransferServerCommand;
use pocketmine\command\defaults\VanillaCommand;
use pocketmine\command\defaults\VersionCommand;
use pocketmine\command\defaults\WhitelistCommand;
@ -115,6 +116,7 @@ class SimpleCommandMap implements CommandMap{
$this->register("pocketmine", new TimeCommand("time"));
$this->register("pocketmine", new TimingsCommand("timings"));
$this->register("pocketmine", new ReloadCommand("reload"));
$this->register("pocketmine", new TransferServerCommand("transferserver"));
if($this->server->getProperty("debug.commands", false)){
$this->register("pocketmine", new StatusCommand("status"));

View File

@ -0,0 +1,56 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\event\TranslationContainer;
use pocketmine\Player;
class TransferServerCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"%pocketmine.command.transferserver.description",
"%pocketmine.command.transferserver.usage"
);
$this->setPermission("pocketmine.command.transferserver");
}
public function execute(CommandSender $sender, $commandLabel, array $args){
if(count($args) < 1){
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false;
}elseif(!($sender instanceof Player)){
$sender->sendMessage("This command must be executed as a player");
return false;
}
$sender->transfer($args[0], (int) ($args[1] ?? 19132));
return true;
}
}