From 15f098074a95d73bb2721fa551f8ca1be8e42a15 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 3 Mar 2017 17:33:30 +0000 Subject: [PATCH 01/11] Fixed batched packets being encoded twice --- src/pocketmine/network/RakLibInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 600003369..ef4c6333a 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -196,6 +196,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $pk = null; if(!$packet->isEncoded){ $packet->encode(); + $packet->isEncoded = true; }elseif(!$needACK){ if(!isset($packet->__encapsulatedPacket)){ $packet->__encapsulatedPacket = new CachedEncapsulatedPacket; From 663cb514e218f7f5253eaaa4424f22a846d79b1e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 4 Mar 2017 15:03:53 +0000 Subject: [PATCH 02/11] Fixed missing Cake recipe TODO: add support for multiple crafting recipe result items --- src/pocketmine/inventory/CraftingManager.php | 28 +++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index af0c56665..65476f7a5 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -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: From 4ee8d1458424c7264f08b3398ee3a82e75c865f4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 4 Mar 2017 18:22:31 +0000 Subject: [PATCH 03/11] Added API for transferring players to other servers (#355) * Added API method `Player->transfer()` and PlayerTransferEvent --- src/pocketmine/Player.php | 27 ++++++++ src/pocketmine/command/SimpleCommandMap.php | 2 + .../defaults/TransferServerCommand.php | 56 ++++++++++++++++ .../event/player/PlayerTransferEvent.php | 66 +++++++++++++++++++ src/pocketmine/lang/locale | 2 +- 5 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/pocketmine/command/defaults/TransferServerCommand.php create mode 100644 src/pocketmine/event/player/PlayerTransferEvent.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 827ab813e..1de4e297a 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.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; @@ -127,6 +128,7 @@ use pocketmine\network\protocol\SetTimePacket; use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\TakeItemEntityPacket; use pocketmine\network\protocol\TextPacket; +use pocketmine\network\protocol\TransferPacket; use pocketmine\network\protocol\UpdateAttributesPacket; use pocketmine\network\protocol\UpdateBlockPacket; use pocketmine\network\SourceInterface; @@ -2987,6 +2989,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 * diff --git a/src/pocketmine/command/SimpleCommandMap.php b/src/pocketmine/command/SimpleCommandMap.php index 6d356ea2d..c1b54a2bd 100644 --- a/src/pocketmine/command/SimpleCommandMap.php +++ b/src/pocketmine/command/SimpleCommandMap.php @@ -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")); diff --git a/src/pocketmine/command/defaults/TransferServerCommand.php b/src/pocketmine/command/defaults/TransferServerCommand.php new file mode 100644 index 000000000..b87fccc6e --- /dev/null +++ b/src/pocketmine/command/defaults/TransferServerCommand.php @@ -0,0 +1,56 @@ +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; + } +} \ No newline at end of file diff --git a/src/pocketmine/event/player/PlayerTransferEvent.php b/src/pocketmine/event/player/PlayerTransferEvent.php new file mode 100644 index 000000000..f361f43d1 --- /dev/null +++ b/src/pocketmine/event/player/PlayerTransferEvent.php @@ -0,0 +1,66 @@ +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; + } +} \ No newline at end of file diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index 3499fe4a6..7ac7004e2 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit 3499fe4a6a1973cc965396f184eb01c52de79aa4 +Subproject commit 7ac7004e2dde7d3e424aef2514f1eb8b98192ea9 From 0a8bd72e1145f6b3bab308e92eb4b3e77a937e2c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 4 Mar 2017 22:35:38 +0000 Subject: [PATCH 04/11] New Jenkins server is up This reverts commit 68998bac48a2b934edb9b03d13ca6508091b3327. --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 9c5e0f86a..0623a0329 100644 --- a/README.md +++ b/README.md @@ -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. - ## Third-party Libraries/Protocols Used * __[PHP Sockets](http://php.net/manual/en/book.sockets.php)__ From e33eb0ddb609c169e1cd4f83776c73daf5236436 Mon Sep 17 00:00:00 2001 From: SOFe Date: Sun, 5 Mar 2017 18:03:59 +0800 Subject: [PATCH 05/11] Fixed missing permission registration in in #355 (#396) --- src/pocketmine/permission/DefaultPermissions.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/permission/DefaultPermissions.php b/src/pocketmine/permission/DefaultPermissions.php index b4bcebe7f..b1aa2f682 100644 --- a/src/pocketmine/permission/DefaultPermissions.php +++ b/src/pocketmine/permission/DefaultPermissions.php @@ -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(); } -} \ No newline at end of file +} From c569fd86b143cf44025e76e6a9b76319249bd814 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 5 Mar 2017 11:30:12 +0000 Subject: [PATCH 06/11] Simplified Vector3::getOppositeSide() (#377) * Simplified Vector3::getOppositeSide() * Throw exception on bad input values * @throws doc --- src/pocketmine/math/Vector3.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index 32a92ebda..36801282a 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -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){ From d6d3184e37062998bb482384c4c984ab3662064f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 6 Mar 2017 11:35:57 +0000 Subject: [PATCH 07/11] Fixed players can't join if spawn-radius is higher than the player's view distance TODO: use this properly instead of calculating a count --- src/pocketmine/Player.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1de4e297a..788633f71 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -429,6 +429,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")) ** 2 * M_PI; + $pk = new ChunkRadiusUpdatedPacket(); $pk->radius = $this->viewDistance; $this->dataPacket($pk); From f204422432ae9a8ebd6efa4b5c79b2d828a84295 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 6 Mar 2017 11:40:28 +0000 Subject: [PATCH 08/11] Fixed precedence issue --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 788633f71..30a9ae805 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -430,7 +430,7 @@ 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")) ** 2 * M_PI; + $this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getProperty("chunk-sending.spawn-radius")) ** 2 * M_PI); $pk = new ChunkRadiusUpdatedPacket(); $pk->radius = $this->viewDistance; From fc5fa0144245ab42ee6a74a757f9363a9c004c95 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 6 Mar 2017 19:45:49 +0000 Subject: [PATCH 09/11] Removed type-hint silently breaking use of CompoundTags in Item::get() --- src/pocketmine/item/Item.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 4c3f4658d..cdef7b45b 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -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){ From 554816b8b636de46e56cdc5410d52b4fae995642 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 7 Mar 2017 09:24:32 +0000 Subject: [PATCH 10/11] Added configuration option to pocketmine.yml to allow changing timings host, added new host mcpetimings.com --- src/pocketmine/command/defaults/TimingsCommand.php | 2 +- src/pocketmine/resources/pocketmine.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/command/defaults/TimingsCommand.php b/src/pocketmine/command/defaults/TimingsCommand.php index 718d887c3..4c59b5522 100644 --- a/src/pocketmine/command/defaults/TimingsCommand.php +++ b/src/pocketmine/command/defaults/TimingsCommand.php @@ -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); diff --git a/src/pocketmine/resources/pocketmine.yml b/src/pocketmine/resources/pocketmine.yml index 3adaaa1ff..9b8df9222 100644 --- a/src/pocketmine/resources/pocketmine.yml +++ b/src/pocketmine/resources/pocketmine.yml @@ -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 From 93896977d0ba5cf23748b8c4a7e108daa196ce8b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 7 Mar 2017 10:18:58 +0000 Subject: [PATCH 11/11] Add default --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 30a9ae805..dac5c89e5 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -430,7 +430,7 @@ 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")) ** 2 * M_PI); + $this->spawnThreshold = (int) (min($this->viewDistance, $this->server->getProperty("chunk-sending.spawn-radius", 4)) ** 2 * M_PI); $pk = new ChunkRadiusUpdatedPacket(); $pk->radius = $this->viewDistance;