From e78292da593ed55cad420e396943fd79ff78094a Mon Sep 17 00:00:00 2001 From: FoxWorn3365 Date: Mon, 24 Jul 2023 01:30:13 +0200 Subject: [PATCH] Just forgot to remove InvMenu LibSkin seems to not be an available virion so i need to include it in the code rn --- .poggit.yml | 5 +- src/Himbeer/LibSkin/LibSkin.php | 34 +++ src/Himbeer/LibSkin/SkinConverter.php | 106 ++++++++ src/Himbeer/LibSkin/SkinGatherer.php | 128 ++++++++++ src/muqsit/invmenu/InvMenu.php | 178 -------------- src/muqsit/invmenu/InvMenuEventHandler.php | 97 -------- src/muqsit/invmenu/InvMenuHandler.php | 46 ---- .../invmenu/inventory/InvMenuInventory.php | 23 -- .../inventory/SharedInvMenuSynchronizer.php | 32 --- .../inventory/SharedInventoryNotifier.php | 31 --- .../inventory/SharedInventorySynchronizer.php | 28 --- src/muqsit/invmenu/session/InvMenuInfo.php | 17 -- src/muqsit/invmenu/session/PlayerManager.php | 60 ----- src/muqsit/invmenu/session/PlayerSession.php | 98 -------- .../network/NetworkStackLatencyEntry.php | 21 -- .../invmenu/session/network/PlayerNetwork.php | 229 ------------------ .../handler/ClosurePlayerNetworkHandler.php | 22 -- .../network/handler/PlayerNetworkHandler.php | 13 - .../handler/PlayerNetworkHandlerRegistry.php | 39 --- .../DeterministicInvMenuTransaction.php | 60 ----- .../transaction/InvMenuTransaction.php | 43 ---- .../transaction/InvMenuTransactionResult.php | 39 --- .../transaction/SimpleInvMenuTransaction.php | 57 ----- .../invmenu/type/ActorFixedInvMenuType.php | 44 ---- .../type/BlockActorFixedInvMenuType.php | 54 ----- .../invmenu/type/BlockFixedInvMenuType.php | 41 ---- ...ublePairableBlockActorFixedInvMenuType.php | 70 ------ src/muqsit/invmenu/type/FixedInvMenuType.php | 18 -- src/muqsit/invmenu/type/InvMenuType.php | 17 -- src/muqsit/invmenu/type/InvMenuTypeIds.php | 12 - .../invmenu/type/InvMenuTypeRegistry.php | 72 ------ .../type/graphic/ActorInvMenuGraphic.php | 71 ------ .../type/graphic/BlockActorInvMenuGraphic.php | 70 ------ .../type/graphic/BlockInvMenuGraphic.php | 59 ----- .../invmenu/type/graphic/InvMenuGraphic.php | 28 --- .../type/graphic/MultiBlockInvMenuGraphic.php | 65 ----- .../type/graphic/PositionedInvMenuGraphic.php | 12 - .../ActorInvMenuGraphicNetworkTranslator.php | 22 -- .../BlockInvMenuGraphicNetworkTranslator.php | 33 --- .../InvMenuGraphicNetworkTranslator.php | 14 -- .../MultiInvMenuGraphicNetworkTranslator.php | 25 -- ...dowTypeInvMenuGraphicNetworkTranslator.php | 20 -- .../invmenu/type/util/InvMenuTypeBuilders.php | 29 --- .../invmenu/type/util/InvMenuTypeHelper.php | 52 ---- .../builder/ActorFixedInvMenuTypeBuilder.php | 38 --- .../builder/ActorInvMenuTypeBuilderTrait.php | 45 ---- ...imationDurationInvMenuTypeBuilderTrait.php | 19 -- .../BlockActorFixedInvMenuTypeBuilder.php | 35 --- .../builder/BlockFixedInvMenuTypeBuilder.php | 22 -- .../builder/BlockInvMenuTypeBuilderTrait.php | 22 -- ...rableBlockActorFixedInvMenuTypeBuilder.php | 35 --- .../builder/FixedInvMenuTypeBuilderTrait.php | 21 -- ...orkTranslatableInvMenuTypeBuilderTrait.php | 37 --- .../type/util/builder/InvMenuTypeBuilder.php | 12 - 54 files changed, 269 insertions(+), 2251 deletions(-) create mode 100644 src/Himbeer/LibSkin/LibSkin.php create mode 100644 src/Himbeer/LibSkin/SkinConverter.php create mode 100644 src/Himbeer/LibSkin/SkinGatherer.php delete mode 100644 src/muqsit/invmenu/InvMenu.php delete mode 100644 src/muqsit/invmenu/InvMenuEventHandler.php delete mode 100644 src/muqsit/invmenu/InvMenuHandler.php delete mode 100644 src/muqsit/invmenu/inventory/InvMenuInventory.php delete mode 100644 src/muqsit/invmenu/inventory/SharedInvMenuSynchronizer.php delete mode 100644 src/muqsit/invmenu/inventory/SharedInventoryNotifier.php delete mode 100644 src/muqsit/invmenu/inventory/SharedInventorySynchronizer.php delete mode 100644 src/muqsit/invmenu/session/InvMenuInfo.php delete mode 100644 src/muqsit/invmenu/session/PlayerManager.php delete mode 100644 src/muqsit/invmenu/session/PlayerSession.php delete mode 100644 src/muqsit/invmenu/session/network/NetworkStackLatencyEntry.php delete mode 100644 src/muqsit/invmenu/session/network/PlayerNetwork.php delete mode 100644 src/muqsit/invmenu/session/network/handler/ClosurePlayerNetworkHandler.php delete mode 100644 src/muqsit/invmenu/session/network/handler/PlayerNetworkHandler.php delete mode 100644 src/muqsit/invmenu/session/network/handler/PlayerNetworkHandlerRegistry.php delete mode 100644 src/muqsit/invmenu/transaction/DeterministicInvMenuTransaction.php delete mode 100644 src/muqsit/invmenu/transaction/InvMenuTransaction.php delete mode 100644 src/muqsit/invmenu/transaction/InvMenuTransactionResult.php delete mode 100644 src/muqsit/invmenu/transaction/SimpleInvMenuTransaction.php delete mode 100644 src/muqsit/invmenu/type/ActorFixedInvMenuType.php delete mode 100644 src/muqsit/invmenu/type/BlockActorFixedInvMenuType.php delete mode 100644 src/muqsit/invmenu/type/BlockFixedInvMenuType.php delete mode 100644 src/muqsit/invmenu/type/DoublePairableBlockActorFixedInvMenuType.php delete mode 100644 src/muqsit/invmenu/type/FixedInvMenuType.php delete mode 100644 src/muqsit/invmenu/type/InvMenuType.php delete mode 100644 src/muqsit/invmenu/type/InvMenuTypeIds.php delete mode 100644 src/muqsit/invmenu/type/InvMenuTypeRegistry.php delete mode 100644 src/muqsit/invmenu/type/graphic/ActorInvMenuGraphic.php delete mode 100644 src/muqsit/invmenu/type/graphic/BlockActorInvMenuGraphic.php delete mode 100644 src/muqsit/invmenu/type/graphic/BlockInvMenuGraphic.php delete mode 100644 src/muqsit/invmenu/type/graphic/InvMenuGraphic.php delete mode 100644 src/muqsit/invmenu/type/graphic/MultiBlockInvMenuGraphic.php delete mode 100644 src/muqsit/invmenu/type/graphic/PositionedInvMenuGraphic.php delete mode 100644 src/muqsit/invmenu/type/graphic/network/ActorInvMenuGraphicNetworkTranslator.php delete mode 100644 src/muqsit/invmenu/type/graphic/network/BlockInvMenuGraphicNetworkTranslator.php delete mode 100644 src/muqsit/invmenu/type/graphic/network/InvMenuGraphicNetworkTranslator.php delete mode 100644 src/muqsit/invmenu/type/graphic/network/MultiInvMenuGraphicNetworkTranslator.php delete mode 100644 src/muqsit/invmenu/type/graphic/network/WindowTypeInvMenuGraphicNetworkTranslator.php delete mode 100644 src/muqsit/invmenu/type/util/InvMenuTypeBuilders.php delete mode 100644 src/muqsit/invmenu/type/util/InvMenuTypeHelper.php delete mode 100644 src/muqsit/invmenu/type/util/builder/ActorFixedInvMenuTypeBuilder.php delete mode 100644 src/muqsit/invmenu/type/util/builder/ActorInvMenuTypeBuilderTrait.php delete mode 100644 src/muqsit/invmenu/type/util/builder/AnimationDurationInvMenuTypeBuilderTrait.php delete mode 100644 src/muqsit/invmenu/type/util/builder/BlockActorFixedInvMenuTypeBuilder.php delete mode 100644 src/muqsit/invmenu/type/util/builder/BlockFixedInvMenuTypeBuilder.php delete mode 100644 src/muqsit/invmenu/type/util/builder/BlockInvMenuTypeBuilderTrait.php delete mode 100644 src/muqsit/invmenu/type/util/builder/DoublePairableBlockActorFixedInvMenuTypeBuilder.php delete mode 100644 src/muqsit/invmenu/type/util/builder/FixedInvMenuTypeBuilderTrait.php delete mode 100644 src/muqsit/invmenu/type/util/builder/GraphicNetworkTranslatableInvMenuTypeBuilderTrait.php delete mode 100644 src/muqsit/invmenu/type/util/builder/InvMenuTypeBuilder.php diff --git a/.poggit.yml b/.poggit.yml index cf90bc8..12b3e00 100644 --- a/.poggit.yml +++ b/.poggit.yml @@ -8,7 +8,4 @@ projects: libs: - src: muqsit/InvMenu/InvMenu version: ^4.6.1 - branch: pm5 - - src: Himbeer/LibSkin/LibSkin - version: ^2.0.0 - branch: master \ No newline at end of file + branch: pm5 \ No newline at end of file diff --git a/src/Himbeer/LibSkin/LibSkin.php b/src/Himbeer/LibSkin/LibSkin.php new file mode 100644 index 0000000..2ec4c36 --- /dev/null +++ b/src/Himbeer/LibSkin/LibSkin.php @@ -0,0 +1,34 @@ + 64, + 64 * 64 * 4 => 64, + 128 * 128 * 4 => 128 + ]; + + public const SKIN_HEIGHT_MAP = [ + 64 * 32 * 4 => 32, + 64 * 64 * 4 => 64, + 128 * 128 * 4 => 128 + ]; + + public static function validateSize(int $size) { + if (!in_array($size, self::ACCEPTED_SKIN_SIZES)) { + throw new Exception("Invalid skin size"); + } + } +} \ No newline at end of file diff --git a/src/Himbeer/LibSkin/SkinConverter.php b/src/Himbeer/LibSkin/SkinConverter.php new file mode 100644 index 0000000..48ce54d --- /dev/null +++ b/src/Himbeer/LibSkin/SkinConverter.php @@ -0,0 +1,106 @@ +> 24) & 0xff; + $r = ($rgba >> 16) & 0xff; + $g = ($rgba >> 8) & 0xff; + $b = $rgba & 0xff; + $skinData .= chr($r) . chr($g) . chr($b) . chr(~(($a << 1) | ($a >> 6)) & 0xff); + } + } + if ($destroyImage) imagedestroy($image); + return $skinData; + } +} diff --git a/src/Himbeer/LibSkin/SkinGatherer.php b/src/Himbeer/LibSkin/SkinGatherer.php new file mode 100644 index 0000000..2bb8ee3 --- /dev/null +++ b/src/Himbeer/LibSkin/SkinGatherer.php @@ -0,0 +1,128 @@ +getOfflinePlayerData($playerName); + if ($namedTag === null) { + return null; + } + $skinTag = $namedTag->getCompoundTag("Skin"); + if ($skinTag === null) { + return null; + } + $skinData = $skinTag->getByteArray("Data"); + return $skinData; + } + + /** + * @param string $userName + * @param callable $callback A function which gets called when the request is finished, with the first argument being the skin data (or null) and the second the success/error state + * + * @throws Exception + */ + public static function getJavaEditionSkinData(string $userName, callable $callback) { + self::getJavaEditionSkinUrl($userName, function($skinUrl, $state) use ($callback) { + $callback($skinUrl === null ? null : SkinConverter::imageToSkinDataFromPngPath($skinUrl), $state); + }); + } + + /** + * @param string $userName Java Edition player name + * @param callable $callback A function which gets called when the request is finished, with the first argument being the URL (or null) and the second the success/error state + */ + public static function getJavaEditionSkinUrl(string $userName, callable $callback) { + self::asyncHttpGetRequest("https://api.mojang.com/users/profiles/minecraft/{$userName}", function(InternetRequestResult|null $response) use ($callback) { + if ($response === null) { + $callback(null, self::MCJE_STATE_ERR_UNKNOWN); + return; + } + $body = $response->getBody(); + if ($body === "") { + if ($response->getCode() === 204) { // Status Code 204: No Content + $callback(null, self::MCJE_STATE_ERR_PLAYER_NOT_FOUND); + } else { + $callback(null, self::MCJE_STATE_ERR_UNKNOWN); + } + return; + } + $data = json_decode($body, true); + if ($data === null || !isset($data["id"])) { + $callback(null, self::MCJE_STATE_ERR_UNKNOWN); + return; + } + self::asyncHttpGetRequest("https://sessionserver.mojang.com/session/minecraft/profile/{$data["id"]}", function(InternetRequestResult|null $response) use ($callback) { + if ($response === null) { + $callback(null, self::MCJE_STATE_ERR_UNKNOWN); + return; + } + $body = $response->getBody(); + if ($body === "") { + $callback(null, self::MCJE_STATE_ERR_UNKNOWN); + return; + } + $data = json_decode($body, true); + if ($data === null || !isset($data["properties"][0]["name"]) || $data["properties"][0]["name"] !== "textures") { + if (isset($data["error"]) && $data["error"] === "TooManyRequestsException") { + $callback(null, self::MCJE_STATE_ERR_TOO_MANY_REQUESTS); + } else { + $callback(null, self::MCJE_STATE_ERR_UNKNOWN); + } + return; + } + if (isset($data["properties"][0]["value"]) && ($b64dec = base64_decode($data["properties"][0]["value"]))) { + $textureInfo = json_decode($b64dec, true); + if ($textureInfo !== null && isset($textureInfo["textures"]["SKIN"]["url"])) { + $skinUrl = $textureInfo["textures"]["SKIN"]["url"]; + $callback($skinUrl, self::MCJE_STATE_SUCCESS); + return; + } + } + $callback(null, self::MCJE_STATE_ERR_UNKNOWN); + }); + }); + } + + /** + * @param string $url + * @param callable $callback + */ + private static function asyncHttpGetRequest(string $url, callable $callback) { + /** + * @param InternetRequestResult[] $results + * + * @return void + */ + $bulkCurlTaskCallback = function(array $results) use ($callback) { + if (isset($results[0]) && !$results[0] instanceof InternetException) { + $callback($results[0]); + } else { + $callback(null); + } + }; + $task = new BulkCurlTask([ + new BulkCurlTaskOperation($url) + ], $bulkCurlTaskCallback); + Server::getInstance()->getAsyncPool()->submitTask($task); + } +} \ No newline at end of file diff --git a/src/muqsit/invmenu/InvMenu.php b/src/muqsit/invmenu/InvMenu.php deleted file mode 100644 index 27b77a7..0000000 --- a/src/muqsit/invmenu/InvMenu.php +++ /dev/null @@ -1,178 +0,0 @@ -get($identifier), ...$args); - } - - /** - * @param (Closure(DeterministicInvMenuTransaction) : void)|null $listener - * @return Closure(InvMenuTransaction) : InvMenuTransactionResult - */ - public static function readonly(?Closure $listener = null) : Closure{ - return static function(InvMenuTransaction $transaction) use($listener) : InvMenuTransactionResult{ - $result = $transaction->discard(); - if($listener !== null){ - $listener(new DeterministicInvMenuTransaction($transaction, $result)); - } - return $result; - }; - } - - protected InvMenuType $type; - protected ?string $name = null; - protected ?Closure $listener = null; - protected ?Closure $inventory_close_listener = null; - protected Inventory $inventory; - protected ?SharedInvMenuSynchronizer $synchronizer = null; - - public function __construct(InvMenuType $type, ?Inventory $custom_inventory = null){ - if(!InvMenuHandler::isRegistered()){ - throw new LogicException("Tried creating menu before calling " . InvMenuHandler::class . "::register()"); - } - $this->type = $type; - $this->inventory = $this->type->createInventory(); - $this->setInventory($custom_inventory); - } - - public function getType() : InvMenuType{ - return $this->type; - } - - public function getName() : ?string{ - return $this->name; - } - - public function setName(?string $name) : self{ - $this->name = $name; - return $this; - } - - /** - * @param (Closure(InvMenuTransaction) : InvMenuTransactionResult)|null $listener - * @return self - */ - public function setListener(?Closure $listener) : self{ - $this->listener = $listener; - return $this; - } - - /** - * @param (Closure(Player, Inventory) : void)|null $listener - * @return self - */ - public function setInventoryCloseListener(?Closure $listener) : self{ - $this->inventory_close_listener = $listener; - return $this; - } - - /** - * @param Player $player - * @param string|null $name - * @param (Closure(bool) : void)|null $callback - */ - final public function send(Player $player, ?string $name = null, ?Closure $callback = null) : void{ - $player->removeCurrentWindow(); - - $session = InvMenuHandler::getPlayerManager()->get($player); - $network = $session->getNetwork(); - - // Avoid players from spamming InvMenu::send() and other similar - // requests and filling up queued tasks in memory. - // It would be better if this check were implemented by plugins, - // however I suppose it is more convenient if done within InvMenu... - if($network->getPending() >= 8){ - $network->dropPending(); - }else{ - $network->dropPendingOfType(PlayerNetwork::DELAY_TYPE_OPERATION); - } - - $network->waitUntil(PlayerNetwork::DELAY_TYPE_OPERATION, 0, function(bool $success) use($player, $session, $name, $callback) : bool{ - if(!$success){ - if($callback !== null){ - $callback(false); - } - return false; - } - - $graphic = $this->type->createGraphic($this, $player); - if($graphic !== null){ - $session->setCurrentMenu(new InvMenuInfo($this, $graphic, $name), static function(bool $success) use($callback) : void{ - if($callback !== null){ - $callback($success); - } - }); - }else{ - if($callback !== null){ - $callback(false); - } - } - return false; - }); - } - - public function getInventory() : Inventory{ - return $this->inventory; - } - - public function setInventory(?Inventory $custom_inventory) : void{ - if($this->synchronizer !== null){ - $this->synchronizer->destroy(); - $this->synchronizer = null; - } - - if($custom_inventory !== null){ - $this->synchronizer = new SharedInvMenuSynchronizer($this, $custom_inventory); - } - } - - /** - * @internal use InvMenu::send() instead. - * - * @param Player $player - * @return bool - */ - public function sendInventory(Player $player) : bool{ - return $player->setCurrentWindow($this->getInventory()); - } - - public function handleInventoryTransaction(Player $player, Item $out, Item $in, SlotChangeAction $action, InventoryTransaction $transaction) : InvMenuTransactionResult{ - $inv_menu_txn = new SimpleInvMenuTransaction($player, $out, $in, $action, $transaction); - return $this->listener !== null ? ($this->listener)($inv_menu_txn) : $inv_menu_txn->continue(); - } - - public function onClose(Player $player) : void{ - if($this->inventory_close_listener !== null){ - ($this->inventory_close_listener)($player, $this->getInventory()); - } - - InvMenuHandler::getPlayerManager()->get($player)->removeCurrentMenu(); - } -} diff --git a/src/muqsit/invmenu/InvMenuEventHandler.php b/src/muqsit/invmenu/InvMenuEventHandler.php deleted file mode 100644 index 5de6be4..0000000 --- a/src/muqsit/invmenu/InvMenuEventHandler.php +++ /dev/null @@ -1,97 +0,0 @@ -getPacket(); - if($packet instanceof NetworkStackLatencyPacket){ - $player = $event->getOrigin()->getPlayer(); - if($player !== null){ - $this->player_manager->getNullable($player)?->getNetwork()->notify($packet->timestamp); - } - } - } - - /** - * @param InventoryCloseEvent $event - * @priority MONITOR - */ - public function onInventoryClose(InventoryCloseEvent $event) : void{ - $player = $event->getPlayer(); - $session = $this->player_manager->getNullable($player); - if($session === null){ - return; - } - - $current = $session->getCurrent(); - if($current !== null && $event->getInventory() === $current->menu->getInventory()){ - $current->menu->onClose($player); - } - $session->getNetwork()->waitUntil(PlayerNetwork::DELAY_TYPE_ANIMATION_WAIT, 325, static fn(bool $success) : bool => false); - } - - /** - * @param InventoryTransactionEvent $event - * @priority NORMAL - */ - public function onInventoryTransaction(InventoryTransactionEvent $event) : void{ - $transaction = $event->getTransaction(); - $player = $transaction->getSource(); - - $player_instance = $this->player_manager->get($player); - $current = $player_instance->getCurrent(); - if($current === null){ - return; - } - - $inventory = $current->menu->getInventory(); - $network_stack_callbacks = []; - foreach($transaction->getActions() as $action){ - if(!($action instanceof SlotChangeAction) || $action->getInventory() !== $inventory){ - continue; - } - - $result = $current->menu->handleInventoryTransaction($player, $action->getSourceItem(), $action->getTargetItem(), $action, $transaction); - $network_stack_callback = $result->getPostTransactionCallback(); - if($network_stack_callback !== null){ - $network_stack_callbacks[] = $network_stack_callback; - } - if($result->isCancelled()){ - $event->cancel(); - break; - } - } - - if(count($network_stack_callbacks) > 0){ - $player_instance->getNetwork()->wait(PlayerNetwork::DELAY_TYPE_ANIMATION_WAIT, static function(bool $success) use($player, $network_stack_callbacks) : bool{ - if($success){ - foreach($network_stack_callbacks as $callback){ - $callback($player); - } - } - return false; - }); - } - } -} diff --git a/src/muqsit/invmenu/InvMenuHandler.php b/src/muqsit/invmenu/InvMenuHandler.php deleted file mode 100644 index 9c5cc9a..0000000 --- a/src/muqsit/invmenu/InvMenuHandler.php +++ /dev/null @@ -1,46 +0,0 @@ -getName()} attempted to register " . self::class . " twice."); - } - - self::$registrant = $plugin; - self::$type_registry = new InvMenuTypeRegistry(); - self::$player_manager = new PlayerManager(self::getRegistrant()); - Server::getInstance()->getPluginManager()->registerEvents(new InvMenuEventHandler(self::getPlayerManager()), $plugin); - } - - public static function isRegistered() : bool{ - return self::$registrant instanceof Plugin; - } - - public static function getRegistrant() : Plugin{ - return self::$registrant ?? throw new LogicException("Cannot obtain registrant before registration"); - } - - public static function getTypeRegistry() : InvMenuTypeRegistry{ - return self::$type_registry; - } - - public static function getPlayerManager() : PlayerManager{ - return self::$player_manager; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/inventory/InvMenuInventory.php b/src/muqsit/invmenu/inventory/InvMenuInventory.php deleted file mode 100644 index d13b1fa..0000000 --- a/src/muqsit/invmenu/inventory/InvMenuInventory.php +++ /dev/null @@ -1,23 +0,0 @@ -holder = new Position(0, 0, 0, null); - } - - public function getHolder() : Position{ - return $this->holder; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/inventory/SharedInvMenuSynchronizer.php b/src/muqsit/invmenu/inventory/SharedInvMenuSynchronizer.php deleted file mode 100644 index 3f7aaf7..0000000 --- a/src/muqsit/invmenu/inventory/SharedInvMenuSynchronizer.php +++ /dev/null @@ -1,32 +0,0 @@ -inventory = $inventory; - - $menu_inventory = $menu->getInventory(); - $this->synchronizer = new SharedInventorySynchronizer($menu_inventory); - $inventory->getListeners()->add($this->synchronizer); - - $this->notifier = new SharedInventoryNotifier($this->inventory, $this->synchronizer); - $menu_inventory->setContents($inventory->getContents()); - $menu_inventory->getListeners()->add($this->notifier); - } - - public function destroy() : void{ - $this->synchronizer->getSynchronizingInventory()->getListeners()->remove($this->notifier); - $this->inventory->getListeners()->remove($this->synchronizer); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/inventory/SharedInventoryNotifier.php b/src/muqsit/invmenu/inventory/SharedInventoryNotifier.php deleted file mode 100644 index dab01fe..0000000 --- a/src/muqsit/invmenu/inventory/SharedInventoryNotifier.php +++ /dev/null @@ -1,31 +0,0 @@ -inventory->getListeners()->remove($this->synchronizer); - $this->inventory->setContents($inventory->getContents()); - $this->inventory->getListeners()->add($this->synchronizer); - } - - public function onSlotChange(Inventory $inventory, int $slot, Item $old_item) : void{ - if($slot < $inventory->getSize()){ - $this->inventory->getListeners()->remove($this->synchronizer); - $this->inventory->setItem($slot, $inventory->getItem($slot)); - $this->inventory->getListeners()->add($this->synchronizer); - } - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/inventory/SharedInventorySynchronizer.php b/src/muqsit/invmenu/inventory/SharedInventorySynchronizer.php deleted file mode 100644 index 1b6ba6d..0000000 --- a/src/muqsit/invmenu/inventory/SharedInventorySynchronizer.php +++ /dev/null @@ -1,28 +0,0 @@ -inventory; - } - - public function onContentChange(Inventory $inventory, array $old_contents) : void{ - $this->inventory->setContents($inventory->getContents()); - } - - public function onSlotChange(Inventory $inventory, int $slot, Item $old_item) : void{ - $this->inventory->setItem($slot, $inventory->getItem($slot)); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/session/InvMenuInfo.php b/src/muqsit/invmenu/session/InvMenuInfo.php deleted file mode 100644 index e5ff2c0..0000000 --- a/src/muqsit/invmenu/session/InvMenuInfo.php +++ /dev/null @@ -1,17 +0,0 @@ -network_handler_registry = new PlayerNetworkHandlerRegistry(); - - $plugin_manager = Server::getInstance()->getPluginManager(); - $plugin_manager->registerEvent(PlayerLoginEvent::class, function(PlayerLoginEvent $event) : void{ - $this->create($event->getPlayer()); - }, EventPriority::MONITOR, $registrant); - $plugin_manager->registerEvent(PlayerQuitEvent::class, function(PlayerQuitEvent $event) : void{ - $this->destroy($event->getPlayer()); - }, EventPriority::MONITOR, $registrant); - } - - private function create(Player $player) : void{ - $this->sessions[$player->getId()] = new PlayerSession($player, new PlayerNetwork( - $player->getNetworkSession(), - $this->network_handler_registry->get($player->getPlayerInfo()->getExtraData()["DeviceOS"] ?? -1) - )); - } - - private function destroy(Player $player) : void{ - if(isset($this->sessions[$player_id = $player->getId()])){ - $this->sessions[$player_id]->finalize(); - unset($this->sessions[$player_id]); - } - } - - public function get(Player $player) : PlayerSession{ - return $this->sessions[$player->getId()]; - } - - public function getNullable(Player $player) : ?PlayerSession{ - return $this->sessions[$player->getId()] ?? null; - } - - public function getNetworkHandlerRegistry() : PlayerNetworkHandlerRegistry{ - return $this->network_handler_registry; - } -} diff --git a/src/muqsit/invmenu/session/PlayerSession.php b/src/muqsit/invmenu/session/PlayerSession.php deleted file mode 100644 index 73440d7..0000000 --- a/src/muqsit/invmenu/session/PlayerSession.php +++ /dev/null @@ -1,98 +0,0 @@ -current !== null){ - $this->current->graphic->remove($this->player); - $this->player->removeCurrentWindow(); - } - $this->network->finalize(); - } - - public function getCurrent() : ?InvMenuInfo{ - return $this->current; - } - - /** - * @internal use InvMenu::send() instead. - * - * @param InvMenuInfo|null $current - * @param (Closure(bool) : void)|null $callback - */ - public function setCurrentMenu(?InvMenuInfo $current, ?Closure $callback = null) : void{ - if($this->current !== null){ - $this->current->graphic->remove($this->player); - } - - $this->current = $current; - - if($this->current !== null){ - $current_id = spl_object_id($this->current); - $this->current->graphic->send($this->player, $this->current->graphic_name); - $this->network->waitUntil(PlayerNetwork::DELAY_TYPE_OPERATION, $this->current->graphic->getAnimationDuration(), function(bool $success) use($callback, $current_id) : bool{ - $current = $this->current; - if($current !== null && spl_object_id($current) === $current_id){ - if($success){ - $this->network->onBeforeSendMenu($this, $current); - $result = $current->graphic->sendInventory($this->player, $current->menu->getInventory()); - if($result){ - if($callback !== null){ - $callback(true); - } - return false; - } - } - - $this->removeCurrentMenu(); - } - if($callback !== null){ - $callback(false); - } - return false; - }); - }else{ - $this->network->wait(PlayerNetwork::DELAY_TYPE_ANIMATION_WAIT, static function(bool $success) use($callback) : bool{ - if($callback !== null){ - $callback($success); - } - return false; - }); - } - } - - public function getNetwork() : PlayerNetwork{ - return $this->network; - } - - /** - * @internal use Player::removeCurrentWindow() instead - * @return bool - */ - public function removeCurrentMenu() : bool{ - if($this->current !== null){ - $this->setCurrentMenu(null); - return true; - } - return false; - } -} diff --git a/src/muqsit/invmenu/session/network/NetworkStackLatencyEntry.php b/src/muqsit/invmenu/session/network/NetworkStackLatencyEntry.php deleted file mode 100644 index 4405f58..0000000 --- a/src/muqsit/invmenu/session/network/NetworkStackLatencyEntry.php +++ /dev/null @@ -1,21 +0,0 @@ -timestamp = $timestamp; - $this->then = $then; - $this->network_timestamp = $network_timestamp ?? $timestamp; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/session/network/PlayerNetwork.php b/src/muqsit/invmenu/session/network/PlayerNetwork.php deleted file mode 100644 index 40726ae..0000000 --- a/src/muqsit/invmenu/session/network/PlayerNetwork.php +++ /dev/null @@ -1,229 +0,0 @@ -|null) */ - private Closure $container_open_callback; - - private ?NetworkStackLatencyEntry $current = null; - private int $graphic_wait_duration = 200; - - /** @var SplQueue */ - private SplQueue $queue; - - /** @var array */ - private array $entry_types = []; - - public function __construct( - private NetworkSession $network_session, - private PlayerNetworkHandler $handler - ){ - $this->queue = new SplQueue(); - $this->nullifyContainerOpenCallback(); - } - - public function finalize() : void{ - $this->dropPending(); - $this->network_session->getInvManager()?->getContainerOpenCallbacks()->remove($this->container_open_callback); - $this->nullifyContainerOpenCallback(); - } - - public function getGraphicWaitDuration() : int{ - return $this->graphic_wait_duration; - } - - /** - * Duration (in milliseconds) to wait between sending the graphic (block) - * and sending the inventory. - * - * @param int $graphic_wait_duration - */ - public function setGraphicWaitDuration(int $graphic_wait_duration) : void{ - if($graphic_wait_duration < 0){ - throw new InvalidArgumentException("graphic_wait_duration must be >= 0, got {$graphic_wait_duration}"); - } - - $this->graphic_wait_duration = $graphic_wait_duration; - } - - public function getPending() : int{ - return $this->queue->count(); - } - - public function dropPending() : void{ - foreach($this->queue as $entry){ - ($entry->then)(false); - } - $this->queue = new SplQueue(); - $this->entry_types = []; - $this->setCurrent(null); - } - - /** - * @param self::DELAY_TYPE_* $type - */ - public function dropPendingOfType(int $type) : void{ - $previous = $this->queue; - $this->queue = new SplQueue(); - foreach($previous as $entry){ - if($this->entry_types[$id = spl_object_id($entry)] === $type){ - ($entry->then)(false); - unset($this->entry_types[$id]); - }else{ - $this->queue->enqueue($entry); - } - } - } - - /** - * @param self::DELAY_TYPE_* $type - * @param Closure(bool) : bool $then - */ - public function wait(int $type, Closure $then) : void{ - $entry = $this->handler->createNetworkStackLatencyEntry($then); - if($this->current !== null){ - $this->queue->enqueue($entry); - $this->entry_types[spl_object_id($entry)] = $type; - }else{ - $this->setCurrent($entry); - } - } - - /** - * Waits at least $wait_ms before calling $then(true). - * - * @param self::DELAY_TYPE_* $type - * @param int $wait_ms - * @param Closure(bool) : bool $then - */ - public function waitUntil(int $type, int $wait_ms, Closure $then) : void{ - if($wait_ms <= 0 && $this->queue->isEmpty()){ - $then(true); - return; - } - - $elapsed_ms = 0.0; - $this->wait($type, function(bool $success) use($wait_ms, $then, &$elapsed_ms) : bool{ - if($this->current === null){ - $then(false); - return false; - } - - $elapsed_ms += (microtime(true) * 1000) - $this->current->sent_at; - if(!$success || $elapsed_ms >= $wait_ms){ - $then($success); - return false; - } - - return true; - }); - } - - private function setCurrent(?NetworkStackLatencyEntry $entry) : void{ - if($this->current !== null){ - $this->processCurrent(false); - } - - $this->current = $entry; - if($entry !== null){ - unset($this->entry_types[spl_object_id($entry)]); - if($this->network_session->sendDataPacket(NetworkStackLatencyPacket::create($entry->network_timestamp, true))){ - $entry->sent_at = microtime(true) * 1000; - }else{ - $this->processCurrent(false); - } - } - } - - private function processCurrent(bool $success) : void{ - if($this->current !== null){ - $current = $this->current; - $repeat = ($current->then)($success); - $this->current = null; - if($repeat && $success){ - $this->setCurrent($current); - }elseif(!$this->queue->isEmpty()){ - $this->setCurrent($this->queue->dequeue()); - } - } - } - - public function notify(int $timestamp) : void{ - if($this->current !== null && $timestamp === $this->current->timestamp){ - $this->processCurrent(true); - } - } - - public function onBeforeSendMenu(PlayerSession $session, InvMenuInfo $info) : void{ - $translator = $info->graphic->getNetworkTranslator(); - if($translator === null){ - return; - } - - $callbacks = $this->network_session->getInvManager()?->getContainerOpenCallbacks(); - if($callbacks === null){ - return; - } - - $callbacks->remove($this->container_open_callback); - - // Take priority over other container open callbacks. - // PocketMine's default container open callback disallows any BlockInventory - // from having a custom callback - $previous = $callbacks->toArray(); - $callbacks->clear(); - $callbacks->add($this->container_open_callback = function(int $window_id, Inventory $inventory) use($info, $session, $translator, $previous, $callbacks) : ?array{ - $callbacks->remove($this->container_open_callback); - $this->nullifyContainerOpenCallback(); - if($inventory === $info->menu->getInventory()){ - $packets = null; - foreach($previous as $callback){ - $packets = $callback($window_id, $inventory); - if($packets !== null){ - break; - } - } - - $packets ??= [ContainerOpenPacket::blockInv( - $window_id, - WindowTypes::CONTAINER, - $inventory instanceof BlockInventory ? BlockPosition::fromVector3($inventory->getHolder()) : new BlockPosition(0, 0, 0) - )]; - - foreach($packets as $packet){ - if($packet instanceof ContainerOpenPacket){ - $translator->translate($session, $info, $packet); - } - } - return $packets; - } - return null; - }, ...$previous); - } - - private function nullifyContainerOpenCallback() : void{ - $this->container_open_callback = static fn(int $window_id, Inventory $inventory) : ?array => null; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/session/network/handler/ClosurePlayerNetworkHandler.php b/src/muqsit/invmenu/session/network/handler/ClosurePlayerNetworkHandler.php deleted file mode 100644 index 0e5e0c1..0000000 --- a/src/muqsit/invmenu/session/network/handler/ClosurePlayerNetworkHandler.php +++ /dev/null @@ -1,22 +0,0 @@ -creator)($then); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/session/network/handler/PlayerNetworkHandler.php b/src/muqsit/invmenu/session/network/handler/PlayerNetworkHandler.php deleted file mode 100644 index fc38d87..0000000 --- a/src/muqsit/invmenu/session/network/handler/PlayerNetworkHandler.php +++ /dev/null @@ -1,13 +0,0 @@ -registerDefault(new ClosurePlayerNetworkHandler(static function(Closure $then) : NetworkStackLatencyEntry{ - return new NetworkStackLatencyEntry(mt_rand() * 1000 /* TODO: remove this hack */, $then); - })); - $this->register(DeviceOS::PLAYSTATION, new ClosurePlayerNetworkHandler(static function(Closure $then) : NetworkStackLatencyEntry{ - $timestamp = mt_rand(); - return new NetworkStackLatencyEntry($timestamp, $then, $timestamp * 1000); - })); - } - - public function registerDefault(PlayerNetworkHandler $handler) : void{ - $this->default = $handler; - } - - public function register(int $os_id, PlayerNetworkHandler $handler) : void{ - $this->game_os_handlers[$os_id] = $handler; - } - - public function get(int $os_id) : PlayerNetworkHandler{ - return $this->game_os_handlers[$os_id] ?? $this->default; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/transaction/DeterministicInvMenuTransaction.php b/src/muqsit/invmenu/transaction/DeterministicInvMenuTransaction.php deleted file mode 100644 index 91c3a5e..0000000 --- a/src/muqsit/invmenu/transaction/DeterministicInvMenuTransaction.php +++ /dev/null @@ -1,60 +0,0 @@ -result->then($callback); - } - - public function getPlayer() : Player{ - return $this->inner->getPlayer(); - } - - public function getOut() : Item{ - return $this->inner->getOut(); - } - - public function getIn() : Item{ - return $this->inner->getIn(); - } - - public function getItemClicked() : Item{ - return $this->inner->getItemClicked(); - } - - public function getItemClickedWith() : Item{ - return $this->inner->getItemClickedWith(); - } - - public function getAction() : SlotChangeAction{ - return $this->inner->getAction(); - } - - public function getTransaction() : InventoryTransaction{ - return $this->inner->getTransaction(); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/transaction/InvMenuTransaction.php b/src/muqsit/invmenu/transaction/InvMenuTransaction.php deleted file mode 100644 index 7db7694..0000000 --- a/src/muqsit/invmenu/transaction/InvMenuTransaction.php +++ /dev/null @@ -1,43 +0,0 @@ -cancelled; - } - - /** - * Notify when we have escaped from the event stack trace and the - * client's network stack trace. - * Useful for sending forms and other stuff that cant be sent right - * after closing inventory. - * - * @param (Closure(\pocketmine\player\Player) : void)|null $callback - * @return self - */ - public function then(?Closure $callback) : self{ - $this->post_transaction_callback = $callback; - return $this; - } - - public function getPostTransactionCallback() : ?Closure{ - return $this->post_transaction_callback; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/transaction/SimpleInvMenuTransaction.php b/src/muqsit/invmenu/transaction/SimpleInvMenuTransaction.php deleted file mode 100644 index 97b8d4c..0000000 --- a/src/muqsit/invmenu/transaction/SimpleInvMenuTransaction.php +++ /dev/null @@ -1,57 +0,0 @@ -player; - } - - public function getOut() : Item{ - return $this->out; - } - - public function getIn() : Item{ - return $this->in; - } - - public function getItemClicked() : Item{ - return $this->getOut(); - } - - public function getItemClickedWith() : Item{ - return $this->getIn(); - } - - public function getAction() : SlotChangeAction{ - return $this->action; - } - - public function getTransaction() : InventoryTransaction{ - return $this->transaction; - } - - public function continue() : InvMenuTransactionResult{ - return new InvMenuTransactionResult(false); - } - - public function discard() : InvMenuTransactionResult{ - return new InvMenuTransactionResult(true); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/ActorFixedInvMenuType.php b/src/muqsit/invmenu/type/ActorFixedInvMenuType.php deleted file mode 100644 index ec3212b..0000000 --- a/src/muqsit/invmenu/type/ActorFixedInvMenuType.php +++ /dev/null @@ -1,44 +0,0 @@ - $actor_metadata - * @param int $size - * @param InvMenuGraphicNetworkTranslator|null $network_translator - */ - public function __construct( - private string $actor_identifier, - private int $actor_runtime_identifier, - private array $actor_metadata, - private int $size, - private ?InvMenuGraphicNetworkTranslator $network_translator = null - ){} - - public function getSize() : int{ - return $this->size; - } - - public function createGraphic(InvMenu $menu, Player $player) : ?InvMenuGraphic{ - return new ActorInvMenuGraphic($this->actor_identifier, $this->actor_runtime_identifier, $this->actor_metadata, $this->network_translator); - } - - public function createInventory() : Inventory{ - return new InvMenuInventory($this->size); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/BlockActorFixedInvMenuType.php b/src/muqsit/invmenu/type/BlockActorFixedInvMenuType.php deleted file mode 100644 index 388e054..0000000 --- a/src/muqsit/invmenu/type/BlockActorFixedInvMenuType.php +++ /dev/null @@ -1,54 +0,0 @@ -size; - } - - public function createGraphic(InvMenu $menu, Player $player) : ?InvMenuGraphic{ - $position = $player->getPosition(); - $origin = $position->addVector(InvMenuTypeHelper::getBehindPositionOffset($player))->floor(); - if(!InvMenuTypeHelper::isValidYCoordinate($origin->y)){ - return null; - } - - $graphics = [new BlockActorInvMenuGraphic($this->block, $origin, BlockActorInvMenuGraphic::createTile($this->tile_id, $menu->getName()), $this->network_translator, $this->animation_duration)]; - foreach(InvMenuTypeHelper::findConnectedBlocks("Chest", $position->getWorld(), $origin, Facing::HORIZONTAL) as $side){ - $graphics[] = new BlockInvMenuGraphic(VanillaBlocks::BARRIER(), $side); - } - - return count($graphics) > 1 ? new MultiBlockInvMenuGraphic($graphics) : $graphics[0]; - } - - public function createInventory() : Inventory{ - return new InvMenuInventory($this->size); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/BlockFixedInvMenuType.php b/src/muqsit/invmenu/type/BlockFixedInvMenuType.php deleted file mode 100644 index 1c19159..0000000 --- a/src/muqsit/invmenu/type/BlockFixedInvMenuType.php +++ /dev/null @@ -1,41 +0,0 @@ -size; - } - - public function createGraphic(InvMenu $menu, Player $player) : ?InvMenuGraphic{ - $origin = $player->getPosition()->addVector(InvMenuTypeHelper::getBehindPositionOffset($player))->floor(); - if(!InvMenuTypeHelper::isValidYCoordinate($origin->y)){ - return null; - } - - return new BlockInvMenuGraphic($this->block, $origin, $this->network_translator); - } - - public function createInventory() : Inventory{ - return new InvMenuInventory($this->size); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/DoublePairableBlockActorFixedInvMenuType.php b/src/muqsit/invmenu/type/DoublePairableBlockActorFixedInvMenuType.php deleted file mode 100644 index 8b36f70..0000000 --- a/src/muqsit/invmenu/type/DoublePairableBlockActorFixedInvMenuType.php +++ /dev/null @@ -1,70 +0,0 @@ -size; - } - - public function createGraphic(InvMenu $menu, Player $player) : ?InvMenuGraphic{ - $position = $player->getPosition(); - $origin = $position->addVector(InvMenuTypeHelper::getBehindPositionOffset($player))->floor(); - if(!InvMenuTypeHelper::isValidYCoordinate($origin->y)){ - return null; - } - - $graphics = []; - $menu_name = $menu->getName(); - $world = $position->getWorld(); - foreach([ - [$origin, $origin->east(), [Facing::NORTH, Facing::SOUTH, Facing::WEST]], - [$origin->east(), $origin, [Facing::NORTH, Facing::SOUTH, Facing::EAST]] - ] as [$origin_pos, $pair_pos, $connected_sides]){ - $graphics[] = new BlockActorInvMenuGraphic( - $this->block, - $origin_pos, - BlockActorInvMenuGraphic::createTile($this->tile_id, $menu_name) - ->setInt(Chest::TAG_PAIRX, $pair_pos->x) - ->setInt(Chest::TAG_PAIRZ, $pair_pos->z), - $this->network_translator, - $this->animation_duration - ); - foreach(InvMenuTypeHelper::findConnectedBlocks("Chest", $world, $origin_pos, $connected_sides) as $side){ - $graphics[] = new BlockInvMenuGraphic(VanillaBlocks::BARRIER(), $side); - } - } - - return count($graphics) > 1 ? new MultiBlockInvMenuGraphic($graphics) : $graphics[0]; - } - - public function createInventory() : Inventory{ - return new InvMenuInventory($this->size); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/FixedInvMenuType.php b/src/muqsit/invmenu/type/FixedInvMenuType.php deleted file mode 100644 index 7f6a5cc..0000000 --- a/src/muqsit/invmenu/type/FixedInvMenuType.php +++ /dev/null @@ -1,18 +0,0 @@ - */ - private array $types = []; - - /** @var array */ - private array $identifiers = []; - - public function __construct(){ - $this->register(InvMenuTypeIds::TYPE_CHEST, InvMenuTypeBuilders::BLOCK_ACTOR_FIXED() - ->setBlock(VanillaBlocks::CHEST()) - ->setSize(27) - ->setBlockActorId("Chest") - ->build()); - - $this->register(InvMenuTypeIds::TYPE_DOUBLE_CHEST, InvMenuTypeBuilders::DOUBLE_PAIRABLE_BLOCK_ACTOR_FIXED() - ->setBlock(VanillaBlocks::CHEST()) - ->setSize(54) - ->setBlockActorId("Chest") - ->setAnimationDuration(75) - ->build()); - - $this->register(InvMenuTypeIds::TYPE_HOPPER, InvMenuTypeBuilders::BLOCK_ACTOR_FIXED() - ->setBlock(VanillaBlocks::HOPPER()) - ->setSize(5) - ->setBlockActorId("Hopper") - ->setNetworkWindowType(WindowTypes::HOPPER) - ->build()); - } - - public function register(string $identifier, InvMenuType $type) : void{ - if(isset($this->types[$identifier])){ - unset($this->identifiers[spl_object_id($this->types[$identifier])], $this->types[$identifier]); - } - - $this->types[$identifier] = $type; - $this->identifiers[spl_object_id($type)] = $identifier; - } - - public function exists(string $identifier) : bool{ - return isset($this->types[$identifier]); - } - - public function get(string $identifier) : InvMenuType{ - return $this->types[$identifier]; - } - - public function getIdentifier(InvMenuType $type) : string{ - return $this->identifiers[spl_object_id($type)]; - } - - public function getOrNull(string $identifier) : ?InvMenuType{ - return $this->types[$identifier] ?? null; - } - - /** - * @return array - */ - public function getAll() : array{ - return $this->types; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/ActorInvMenuGraphic.php b/src/muqsit/invmenu/type/graphic/ActorInvMenuGraphic.php deleted file mode 100644 index 4af2950..0000000 --- a/src/muqsit/invmenu/type/graphic/ActorInvMenuGraphic.php +++ /dev/null @@ -1,71 +0,0 @@ - $actor_metadata - * @param InvMenuGraphicNetworkTranslator|null $network_translator - * @param int $animation_duration - */ - public function __construct( - private string $actor_identifier, - private int $actor_runtime_identifier, - private array $actor_metadata, - private ?InvMenuGraphicNetworkTranslator $network_translator = null, - private int $animation_duration = 0 - ){} - - public function send(Player $player, ?string $name) : void{ - $metadata = $this->actor_metadata; - if($name !== null){ - $metadata[EntityMetadataProperties::NAMETAG] = new StringMetadataProperty($name); - } - $player->getNetworkSession()->sendDataPacket(AddActorPacket::create( - $this->actor_runtime_identifier, - $this->actor_runtime_identifier, - $this->actor_identifier, - $player->getPosition()->asVector3(), - null, - 0.0, - 0.0, - 0.0, - 0.0, - [], - $metadata, - new PropertySyncData([], []), - [] - )); - } - - public function sendInventory(Player $player, Inventory $inventory) : bool{ - return $player->setCurrentWindow($inventory); - } - - public function remove(Player $player) : void{ - $player->getNetworkSession()->sendDataPacket(RemoveActorPacket::create($this->actor_runtime_identifier)); - } - - public function getNetworkTranslator() : ?InvMenuGraphicNetworkTranslator{ - return $this->network_translator; - } - - public function getAnimationDuration() : int{ - return $this->animation_duration; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/BlockActorInvMenuGraphic.php b/src/muqsit/invmenu/type/graphic/BlockActorInvMenuGraphic.php deleted file mode 100644 index 0619065..0000000 --- a/src/muqsit/invmenu/type/graphic/BlockActorInvMenuGraphic.php +++ /dev/null @@ -1,70 +0,0 @@ -setString(Tile::TAG_ID, $tile_id); - if($name !== null){ - $tag->setString(Nameable::TAG_CUSTOM_NAME, $name); - } - return $tag; - } - - private BlockInvMenuGraphic $block_graphic; - private Vector3 $position; - private CompoundTag $tile; - private ?InvMenuGraphicNetworkTranslator $network_translator; - private int $animation_duration; - - public function __construct(Block $block, Vector3 $position, CompoundTag $tile, ?InvMenuGraphicNetworkTranslator $network_translator = null, int $animation_duration = 0){ - $this->block_graphic = new BlockInvMenuGraphic($block, $position); - $this->position = $position; - $this->tile = $tile; - $this->network_translator = $network_translator; - $this->animation_duration = $animation_duration; - } - - public function getPosition() : Vector3{ - return $this->position; - } - - public function send(Player $player, ?string $name) : void{ - $this->block_graphic->send($player, $name); - if($name !== null){ - $this->tile->setString(Nameable::TAG_CUSTOM_NAME, $name); - } - $player->getNetworkSession()->sendDataPacket(BlockActorDataPacket::create(BlockPosition::fromVector3($this->position), new CacheableNbt($this->tile))); - } - - public function sendInventory(Player $player, Inventory $inventory) : bool{ - return $player->setCurrentWindow($inventory); - } - - public function remove(Player $player) : void{ - $this->block_graphic->remove($player); - } - - public function getNetworkTranslator() : ?InvMenuGraphicNetworkTranslator{ - return $this->network_translator; - } - - public function getAnimationDuration() : int{ - return $this->animation_duration; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/BlockInvMenuGraphic.php b/src/muqsit/invmenu/type/graphic/BlockInvMenuGraphic.php deleted file mode 100644 index 2e35029..0000000 --- a/src/muqsit/invmenu/type/graphic/BlockInvMenuGraphic.php +++ /dev/null @@ -1,59 +0,0 @@ -position; - } - - public function send(Player $player, ?string $name) : void{ - $player->getNetworkSession()->sendDataPacket(UpdateBlockPacket::create(BlockPosition::fromVector3($this->position), RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::DATA_LAYER_NORMAL)); - } - - public function sendInventory(Player $player, Inventory $inventory) : bool{ - return $player->setCurrentWindow($inventory); - } - - public function remove(Player $player) : void{ - $network = $player->getNetworkSession(); - $world = $player->getWorld(); - $runtime_block_mapping = RuntimeBlockMapping::getInstance(); - $block = $world->getBlockAt($this->position->x, $this->position->y, $this->position->z); - $network->sendDataPacket(UpdateBlockPacket::create(BlockPosition::fromVector3($this->position), $runtime_block_mapping->toRuntimeId($block->getFullId()), UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::DATA_LAYER_NORMAL), true); - - $tile = $world->getTileAt($this->position->x, $this->position->y, $this->position->z); - if($tile instanceof Spawnable){ - $network->sendDataPacket(BlockActorDataPacket::create(BlockPosition::fromVector3($this->position), $tile->getSerializedSpawnCompound()), true); - } - } - - public function getNetworkTranslator() : ?InvMenuGraphicNetworkTranslator{ - return $this->network_translator; - } - - public function getAnimationDuration() : int{ - return $this->animation_duration; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/InvMenuGraphic.php b/src/muqsit/invmenu/type/graphic/InvMenuGraphic.php deleted file mode 100644 index 8c263d7..0000000 --- a/src/muqsit/invmenu/type/graphic/InvMenuGraphic.php +++ /dev/null @@ -1,28 +0,0 @@ -graphics); - if($first === false){ - throw new LogicException("Tried sending inventory from a multi graphic consisting of zero entries"); - } - - return $first; - } - - public function send(Player $player, ?string $name) : void{ - foreach($this->graphics as $graphic){ - $graphic->send($player, $name); - } - } - - public function sendInventory(Player $player, Inventory $inventory) : bool{ - return $this->first()->sendInventory($player, $inventory); - } - - public function remove(Player $player) : void{ - foreach($this->graphics as $graphic){ - $graphic->remove($player); - } - } - - public function getNetworkTranslator() : ?InvMenuGraphicNetworkTranslator{ - return $this->first()->getNetworkTranslator(); - } - - public function getPosition() : Vector3{ - return $this->first()->getPosition(); - } - - public function getAnimationDuration() : int{ - $max = 0; - foreach($this->graphics as $graphic){ - $duration = $graphic->getAnimationDuration(); - if($duration > $max){ - $max = $duration; - } - } - return $max; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/PositionedInvMenuGraphic.php b/src/muqsit/invmenu/type/graphic/PositionedInvMenuGraphic.php deleted file mode 100644 index 8b3c83d..0000000 --- a/src/muqsit/invmenu/type/graphic/PositionedInvMenuGraphic.php +++ /dev/null @@ -1,12 +0,0 @@ -actorUniqueId = $this->actor_runtime_id; - $packet->blockPosition = new BlockPosition(0, 0, 0); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/network/BlockInvMenuGraphicNetworkTranslator.php b/src/muqsit/invmenu/type/graphic/network/BlockInvMenuGraphicNetworkTranslator.php deleted file mode 100644 index 3406800..0000000 --- a/src/muqsit/invmenu/type/graphic/network/BlockInvMenuGraphicNetworkTranslator.php +++ /dev/null @@ -1,33 +0,0 @@ -graphic; - if(!($graphic instanceof PositionedInvMenuGraphic)){ - throw new InvalidArgumentException("Expected " . PositionedInvMenuGraphic::class . ", got " . get_class($graphic)); - } - - $pos = $graphic->getPosition(); - $packet->blockPosition = new BlockPosition((int) $pos->x, (int) $pos->y, (int) $pos->z); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/network/InvMenuGraphicNetworkTranslator.php b/src/muqsit/invmenu/type/graphic/network/InvMenuGraphicNetworkTranslator.php deleted file mode 100644 index 5ead44f..0000000 --- a/src/muqsit/invmenu/type/graphic/network/InvMenuGraphicNetworkTranslator.php +++ /dev/null @@ -1,14 +0,0 @@ -translators as $translator){ - $translator->translate($session, $current, $packet); - } - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/graphic/network/WindowTypeInvMenuGraphicNetworkTranslator.php b/src/muqsit/invmenu/type/graphic/network/WindowTypeInvMenuGraphicNetworkTranslator.php deleted file mode 100644 index 81e7750..0000000 --- a/src/muqsit/invmenu/type/graphic/network/WindowTypeInvMenuGraphicNetworkTranslator.php +++ /dev/null @@ -1,20 +0,0 @@ -windowType = $this->window_type; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/InvMenuTypeBuilders.php b/src/muqsit/invmenu/type/util/InvMenuTypeBuilders.php deleted file mode 100644 index a749a14..0000000 --- a/src/muqsit/invmenu/type/util/InvMenuTypeBuilders.php +++ /dev/null @@ -1,29 +0,0 @@ -getDirectionVector(); - $size = $player->size; - $offset->x *= -(1 + $size->getWidth()); - $offset->y *= -(1 + $size->getHeight()); - $offset->z *= -(1 + $size->getWidth()); - return $offset; - } - - public static function isValidYCoordinate(float $y) : bool{ - return $y >= self::NETWORK_WORLD_Y_MIN && $y <= self::NETWORK_WORLD_Y_MAX; - } - - /** - * @param string $tile_id - * @param World $world - * @param Vector3 $position - * @param list $sides - * @return Generator - */ - public static function findConnectedBlocks(string $tile_id, World $world, Vector3 $position, array $sides) : Generator{ - if($tile_id === "Chest"){ - // setting a single chest at the spot of a pairable chest sends the client a double chest - // https://github.com/Muqsit/InvMenu/issues/207 - foreach($sides as $side){ - $pos = $position->getSide($side); - $tile = $world->getTileAt($pos->x, $pos->y, $pos->z); - if($tile instanceof Chest && $tile->getPair() !== null){ - yield $pos; - } - } - } - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/ActorFixedInvMenuTypeBuilder.php b/src/muqsit/invmenu/type/util/builder/ActorFixedInvMenuTypeBuilder.php deleted file mode 100644 index a43d4f5..0000000 --- a/src/muqsit/invmenu/type/util/builder/ActorFixedInvMenuTypeBuilder.php +++ /dev/null @@ -1,38 +0,0 @@ -getActorMetadata(); - $metadata->setFloat(EntityMetadataProperties::BOUNDING_BOX_HEIGHT, 0.01); - $metadata->setFloat(EntityMetadataProperties::BOUNDING_BOX_WIDTH, 0.01); - $metadata->setGenericFlag(EntityMetadataFlags::INVISIBLE, true); - } - - public function setNetworkWindowType(int $window_type) : self{ - $this->parentSetNetworkWindowType($window_type); - $this->getActorMetadata()->setByte(EntityMetadataProperties::CONTAINER_TYPE, $window_type); - return $this; - } - - public function setSize(int $size) : self{ - $this->parentSetSize($size); - $this->getActorMetadata()->setInt(EntityMetadataProperties::CONTAINER_BASE_SIZE, $size); - return $this; - } - - public function build() : ActorFixedInvMenuType{ - return new ActorFixedInvMenuType($this->getActorIdentifier(), $this->getActorRuntimeIdentifier(), $this->getActorMetadata()->getAll(), $this->getSize(), $this->getGraphicNetworkTranslator()); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/ActorInvMenuTypeBuilderTrait.php b/src/muqsit/invmenu/type/util/builder/ActorInvMenuTypeBuilderTrait.php deleted file mode 100644 index 1face00..0000000 --- a/src/muqsit/invmenu/type/util/builder/ActorInvMenuTypeBuilderTrait.php +++ /dev/null @@ -1,45 +0,0 @@ -actor_runtime_identifier ?? $this->setActorRuntimeIdentifier(Entity::nextRuntimeId())->getActorRuntimeIdentifier(); - } - - public function setActorRuntimeIdentifier(int $actor_runtime_identifier) : self{ - $this->actor_runtime_identifier = $actor_runtime_identifier; - $this->addGraphicNetworkTranslator(new ActorInvMenuGraphicNetworkTranslator($this->actor_runtime_identifier)); - return $this; - } - - public function getActorMetadata() : EntityMetadataCollection{ - return $this->actor_metadata ?? $this->setActorMetadata(new EntityMetadataCollection())->getActorMetadata(); - } - - public function setActorMetadata(EntityMetadataCollection $actor_metadata) : self{ - $this->actor_metadata = $actor_metadata; - return $this; - } - - public function getActorIdentifier() : string{ - return $this->actor_identifier ?? $this->setActorIdentifier(EntityIds::CHEST_MINECART)->getActorIdentifier(); - } - - public function setActorIdentifier(string $actor_identifier) : self{ - $this->actor_identifier = $actor_identifier; - return $this; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/AnimationDurationInvMenuTypeBuilderTrait.php b/src/muqsit/invmenu/type/util/builder/AnimationDurationInvMenuTypeBuilderTrait.php deleted file mode 100644 index e062297..0000000 --- a/src/muqsit/invmenu/type/util/builder/AnimationDurationInvMenuTypeBuilderTrait.php +++ /dev/null @@ -1,19 +0,0 @@ -animation_duration = $animation_duration; - return $this; - } - - protected function getAnimationDuration() : int{ - return $this->animation_duration; - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/BlockActorFixedInvMenuTypeBuilder.php b/src/muqsit/invmenu/type/util/builder/BlockActorFixedInvMenuTypeBuilder.php deleted file mode 100644 index e3cb3fb..0000000 --- a/src/muqsit/invmenu/type/util/builder/BlockActorFixedInvMenuTypeBuilder.php +++ /dev/null @@ -1,35 +0,0 @@ -addGraphicNetworkTranslator(BlockInvMenuGraphicNetworkTranslator::instance()); - } - - public function setBlockActorId(string $block_actor_id) : self{ - $this->block_actor_id = $block_actor_id; - return $this; - } - - private function getBlockActorId() : string{ - return $this->block_actor_id ?? throw new LogicException("No block actor ID was specified"); - } - - public function build() : BlockActorFixedInvMenuType{ - return new BlockActorFixedInvMenuType($this->getBlock(), $this->getSize(), $this->getBlockActorId(), $this->getGraphicNetworkTranslator(), $this->getAnimationDuration()); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/BlockFixedInvMenuTypeBuilder.php b/src/muqsit/invmenu/type/util/builder/BlockFixedInvMenuTypeBuilder.php deleted file mode 100644 index afef7a2..0000000 --- a/src/muqsit/invmenu/type/util/builder/BlockFixedInvMenuTypeBuilder.php +++ /dev/null @@ -1,22 +0,0 @@ -addGraphicNetworkTranslator(BlockInvMenuGraphicNetworkTranslator::instance()); - } - - public function build() : BlockFixedInvMenuType{ - return new BlockFixedInvMenuType($this->getBlock(), $this->getSize(), $this->getGraphicNetworkTranslator()); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/BlockInvMenuTypeBuilderTrait.php b/src/muqsit/invmenu/type/util/builder/BlockInvMenuTypeBuilderTrait.php deleted file mode 100644 index 26ad398..0000000 --- a/src/muqsit/invmenu/type/util/builder/BlockInvMenuTypeBuilderTrait.php +++ /dev/null @@ -1,22 +0,0 @@ -block = $block; - return $this; - } - - protected function getBlock() : Block{ - return $this->block ?? throw new LogicException("No block was provided"); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/DoublePairableBlockActorFixedInvMenuTypeBuilder.php b/src/muqsit/invmenu/type/util/builder/DoublePairableBlockActorFixedInvMenuTypeBuilder.php deleted file mode 100644 index a66dd3a..0000000 --- a/src/muqsit/invmenu/type/util/builder/DoublePairableBlockActorFixedInvMenuTypeBuilder.php +++ /dev/null @@ -1,35 +0,0 @@ -addGraphicNetworkTranslator(BlockInvMenuGraphicNetworkTranslator::instance()); - } - - public function setBlockActorId(string $block_actor_id) : self{ - $this->block_actor_id = $block_actor_id; - return $this; - } - - private function getBlockActorId() : string{ - return $this->block_actor_id ?? throw new LogicException("No block actor ID was specified"); - } - - public function build() : DoublePairableBlockActorFixedInvMenuType{ - return new DoublePairableBlockActorFixedInvMenuType($this->getBlock(), $this->getSize(), $this->getBlockActorId(), $this->getGraphicNetworkTranslator(), $this->getAnimationDuration()); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/FixedInvMenuTypeBuilderTrait.php b/src/muqsit/invmenu/type/util/builder/FixedInvMenuTypeBuilderTrait.php deleted file mode 100644 index a46a26a..0000000 --- a/src/muqsit/invmenu/type/util/builder/FixedInvMenuTypeBuilderTrait.php +++ /dev/null @@ -1,21 +0,0 @@ -size = $size; - return $this; - } - - protected function getSize() : int{ - return $this->size ?? throw new LogicException("No size was provided"); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/GraphicNetworkTranslatableInvMenuTypeBuilderTrait.php b/src/muqsit/invmenu/type/util/builder/GraphicNetworkTranslatableInvMenuTypeBuilderTrait.php deleted file mode 100644 index 31b0d64..0000000 --- a/src/muqsit/invmenu/type/util/builder/GraphicNetworkTranslatableInvMenuTypeBuilderTrait.php +++ /dev/null @@ -1,37 +0,0 @@ -graphic_network_translators[] = $translator; - return $this; - } - - public function setNetworkWindowType(int $window_type) : self{ - $this->addGraphicNetworkTranslator(new WindowTypeInvMenuGraphicNetworkTranslator($window_type)); - return $this; - } - - protected function getGraphicNetworkTranslator() : ?InvMenuGraphicNetworkTranslator{ - if(count($this->graphic_network_translators) === 0){ - return null; - } - - if(count($this->graphic_network_translators) === 1){ - return $this->graphic_network_translators[array_key_first($this->graphic_network_translators)]; - } - - return new MultiInvMenuGraphicNetworkTranslator($this->graphic_network_translators); - } -} \ No newline at end of file diff --git a/src/muqsit/invmenu/type/util/builder/InvMenuTypeBuilder.php b/src/muqsit/invmenu/type/util/builder/InvMenuTypeBuilder.php deleted file mode 100644 index ae07040..0000000 --- a/src/muqsit/invmenu/type/util/builder/InvMenuTypeBuilder.php +++ /dev/null @@ -1,12 +0,0 @@ -