mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Merge branch 'master' into api3/network
This commit is contained in:
commit
c7fdbea0f0
@ -22,10 +22,8 @@ There are a very wide range of already-written plugins available which you can u
|
||||
### Can I contribute?
|
||||
Yes you can! Contributions are welcomed provided that they comply with our [Contributing Guidelines](CONTRIBUTING.md). Please ensure you read the relevant sections of the guidelines carefully before making a Pull Request or opening an Issue.
|
||||
|
||||
<!-- TODO uncomment this when Jenkins is fixed
|
||||
### Where can I get the latest .phar?
|
||||
Head over to our [official Jenkins server](https://jenkins.pmmp.io/)
|
||||
-->
|
||||
|
||||
## Third-party Libraries/Protocols Used
|
||||
* __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__
|
||||
|
@ -64,6 +64,7 @@ use pocketmine\event\player\PlayerRespawnEvent;
|
||||
use pocketmine\event\player\PlayerToggleFlightEvent;
|
||||
use pocketmine\event\player\PlayerToggleSneakEvent;
|
||||
use pocketmine\event\player\PlayerToggleSprintEvent;
|
||||
use pocketmine\event\player\PlayerTransferEvent;
|
||||
use pocketmine\event\server\DataPacketReceiveEvent;
|
||||
use pocketmine\event\server\DataPacketSendEvent;
|
||||
use pocketmine\event\TextContainer;
|
||||
@ -503,6 +504,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
public function setViewDistance(int $distance){
|
||||
$this->viewDistance = $this->server->getAllowedViewDistance($distance);
|
||||
|
||||
$this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getProperty("chunk-sending.spawn-radius", 4)) ** 2 * M_PI);
|
||||
|
||||
$pk = new ChunkRadiusUpdatedPacket();
|
||||
$pk->radius = $this->viewDistance;
|
||||
$this->dataPacket($pk);
|
||||
@ -3329,6 +3333,31 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$timings->stopTiming();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers a player to another server.
|
||||
*
|
||||
* @param string $address The IP address or hostname of the destination server
|
||||
* @param int $port The destination port, defaults to 19132
|
||||
* @param string $message Message to show in the console when closing the player
|
||||
*
|
||||
* @return bool if transfer was successful.
|
||||
*/
|
||||
public function transfer(string $address, int $port = 19132, string $message = "transfer") : bool{
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerTransferEvent($this, $address, $port, $message));
|
||||
|
||||
if(!$ev->isCancelled()){
|
||||
$pk = new TransferPacket();
|
||||
$pk->address = $ev->getAddress();
|
||||
$pk->port = $ev->getPort();
|
||||
$this->dataPacket($pk);
|
||||
$this->close("", $ev->getMessage(), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks a player from the server
|
||||
*
|
||||
|
@ -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"));
|
||||
|
@ -132,7 +132,7 @@ class TimingsCommand extends VanillaCommand{
|
||||
|
||||
|
||||
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsUpload", ["http://paste.ubuntu.com/" . $matches[1] . "/"]));
|
||||
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead", ["http://timings.aikar.co/?url=" . $matches[1]]));
|
||||
$sender->sendMessage(new TranslationContainer("pocketmine.command.timings.timingsRead", ["http://" . $sender->getServer()->getProperty("timings.host", "mcpetimings.com") . "/?url=" . $matches[1]]));
|
||||
fclose($fileTimings);
|
||||
}else{
|
||||
fclose($fileTimings);
|
||||
|
56
src/pocketmine/command/defaults/TransferServerCommand.php
Normal file
56
src/pocketmine/command/defaults/TransferServerCommand.php
Normal 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;
|
||||
}
|
||||
}
|
66
src/pocketmine/event/player/PlayerTransferEvent.php
Normal file
66
src/pocketmine/event/player/PlayerTransferEvent.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\Player;
|
||||
|
||||
class PlayerTransferEvent extends PlayerEvent implements Cancellable{
|
||||
public static $handlerList = null;
|
||||
|
||||
protected $address;
|
||||
protected $port = 19132;
|
||||
protected $message;
|
||||
|
||||
public function __construct(Player $player, string $address, int $port, string $message){
|
||||
$this->player = $player;
|
||||
$this->address = $address;
|
||||
$this->port = $port;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function getAddress() : string{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
public function setAddress(string $address){
|
||||
$this->address = $address;
|
||||
}
|
||||
|
||||
public function getPort() : int{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
public function setPort(int $port){
|
||||
$this->port = $port;
|
||||
}
|
||||
|
||||
public function getMessage() : string{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function setMessage(string $message){
|
||||
$this->message = $message;
|
||||
}
|
||||
}
|
@ -54,30 +54,26 @@ class CraftingManager{
|
||||
switch($recipe["type"]){
|
||||
case 0:
|
||||
// TODO: handle multiple result items
|
||||
if(count($recipe["output"]) === 1){
|
||||
$first = $recipe["output"][0];
|
||||
$result = new ShapelessRecipe(Item::get($first["id"], $first["damage"], $first["count"], $first["nbt"]));
|
||||
$first = $recipe["output"][0];
|
||||
$result = new ShapelessRecipe(Item::get($first["id"], $first["damage"], $first["count"], $first["nbt"]));
|
||||
|
||||
foreach($recipe["input"] as $ingredient){
|
||||
$result->addIngredient(Item::get($ingredient["id"], $ingredient["damage"], $ingredient["count"], $first["nbt"]));
|
||||
}
|
||||
$this->registerRecipe($result);
|
||||
foreach($recipe["input"] as $ingredient){
|
||||
$result->addIngredient(Item::get($ingredient["id"], $ingredient["damage"], $ingredient["count"], $first["nbt"]));
|
||||
}
|
||||
$this->registerRecipe($result);
|
||||
break;
|
||||
case 1:
|
||||
// TODO: handle multiple result items
|
||||
if(count($recipe["output"]) === 1){
|
||||
$first = $recipe["output"][0];
|
||||
$result = new ShapedRecipe(Item::get($first["id"], $first["damage"], $first["count"], $first["nbt"]), $recipe["height"], $recipe["width"]);
|
||||
$first = $recipe["output"][0];
|
||||
$result = new ShapedRecipe(Item::get($first["id"], $first["damage"], $first["count"], $first["nbt"]), $recipe["height"], $recipe["width"]);
|
||||
|
||||
$shape = array_chunk($recipe["input"], $recipe["width"]);
|
||||
foreach($shape as $y => $row){
|
||||
foreach($row as $x => $ingredient){
|
||||
$result->addIngredient($x, $y, Item::get($ingredient["id"], ($ingredient["damage"] < 0 ? -1 : $ingredient["damage"]), $ingredient["count"], $ingredient["nbt"]));
|
||||
}
|
||||
$shape = array_chunk($recipe["input"], $recipe["width"]);
|
||||
foreach($shape as $y => $row){
|
||||
foreach($row as $x => $ingredient){
|
||||
$result->addIngredient($x, $y, Item::get($ingredient["id"], ($ingredient["damage"] < 0 ? -1 : $ingredient["damage"]), $ingredient["count"], $ingredient["nbt"]));
|
||||
}
|
||||
$this->registerRecipe($result);
|
||||
}
|
||||
$this->registerRecipe($result);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
|
@ -291,7 +291,17 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static function get(int $id, int $meta = 0, int $count = 1, string $tags = "") : Item{
|
||||
/**
|
||||
* Returns an instance of the Item with the specified id, meta, count and NBT.
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param int $count
|
||||
* @param CompoundTag|string $tags
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{
|
||||
try{
|
||||
$class = self::$list[$id];
|
||||
if($class === null){
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 55e8fbae371c8a48f6dd58333903a302ca2371f4
|
||||
Subproject commit 7ac7004e2dde7d3e424aef2514f1eb8b98192ea9
|
@ -157,23 +157,20 @@ class Vector3{
|
||||
}
|
||||
}
|
||||
|
||||
public static function getOppositeSide($side){
|
||||
switch((int) $side){
|
||||
case Vector3::SIDE_DOWN:
|
||||
return Vector3::SIDE_UP;
|
||||
case Vector3::SIDE_UP:
|
||||
return Vector3::SIDE_DOWN;
|
||||
case Vector3::SIDE_NORTH:
|
||||
return Vector3::SIDE_SOUTH;
|
||||
case Vector3::SIDE_SOUTH:
|
||||
return Vector3::SIDE_NORTH;
|
||||
case Vector3::SIDE_WEST:
|
||||
return Vector3::SIDE_EAST;
|
||||
case Vector3::SIDE_EAST:
|
||||
return Vector3::SIDE_WEST;
|
||||
default:
|
||||
return -1;
|
||||
/**
|
||||
* Returns the Vector3 side number opposite the specified one
|
||||
*
|
||||
* @param int $side 0-5 one of the Vector3::SIDE_* constants
|
||||
* @return int
|
||||
*
|
||||
* @throws \InvalidArgumentException if an invalid side is supplied
|
||||
*/
|
||||
public static function getOppositeSide(int $side) : int{
|
||||
if($side >= 0 and $side <= 5){
|
||||
return $side ^ 0x01;
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Invalid side $side given to getOppositeSide");
|
||||
}
|
||||
|
||||
public function distance(Vector3 $pos){
|
||||
|
@ -122,9 +122,10 @@ abstract class DefaultPermissions{
|
||||
self::registerPermission(new Permission(self::ROOT . ".command.timings", "Allows the user to records timings for all plugin events", Permission::DEFAULT_OP), $commands);
|
||||
self::registerPermission(new Permission(self::ROOT . ".command.spawnpoint", "Allows the user to change player's spawnpoint", Permission::DEFAULT_OP), $commands);
|
||||
self::registerPermission(new Permission(self::ROOT . ".command.setworldspawn", "Allows the user to change the world spawn", Permission::DEFAULT_OP), $commands);
|
||||
self::registerPermission(new Permission(self::ROOT . ".command.transferserver", "Allows the user to transfer self to another server", Permission::DEFAULT_OP), $commands);
|
||||
|
||||
$commands->recalculatePermissibles();
|
||||
|
||||
$parent->recalculatePermissibles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +181,10 @@ auto-updater:
|
||||
suggest-channels: true
|
||||
host: www.pocketmine.net
|
||||
|
||||
timings:
|
||||
#Choose the host to use for viewing your timings results.
|
||||
host: mcpetimings.com
|
||||
|
||||
aliases:
|
||||
#Examples:
|
||||
#showtheversion: version
|
||||
|
Loading…
x
Reference in New Issue
Block a user