So currently im trying to make a plugin that uses muqsit's library here is my current code: PHP: <?phpnamespace Commands;use pocketmine\plugin\PluginBase;use pocketmine\command\{ Command, CommandSender};use pocketmine\utils\TextFormat as C;use muqsit\invmenu\InvMenu;class ServerSelectorGUI{ /** @var InvMenu */ private $menu; public function __construct(string $name){ $this->menu = InvMenu::create(InvMenu::TYPE_CHEST) ->readonly() ->setName($name) ->setListener([$this, "onServerSelectorTransaction"])//you can call class functions this way ->onInventoryClose(function(Player $player) : void{ $player->sendMessage(TextFormat::GREEN . "You are being transferred..."); }); } public function addServerToList(Item $item, string $address, int $port) : void{ $nbt = $item->getNamedTag(); $nbt->setString("Server", $address . ":" . $port); $item->setNamedTag($nbt); $this->menu->addItem($item); } public function onServerSelectorTransaction(Player $player, Item $itemClickedOn) : bool{ $player->transfer(...explode(":", $itemClickedOn->getNamedTag()->getString("Server", "play.onthefallbackserv.er:19132"))); return true; } public function sendTo(Player $player) : void{ $this->menu->send($player); }}$gui = new ServerSelectorGUI("Server Selector");$gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se", 19132);$gui->addServerToList(Item::get(Item::IRON), "play.onmyserverplea.se", 19133);class Main extends PluginBase{ public function onLoad(): void{ $this->getLogger()->info(C::GREEN . "Loading Commands..."); } public function onEnable(): void{ $this->getLogger()->info(C::YELLOW . "Enabled Commands!"); if(!InvMenuHandler::isRegistered()){ InvMenuHandler::register($this); } } public function onDisable(): void{ $this->getLogger()->info(C::RED . "Commands Disabled!"); } public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{ switch($command){ case "test": $sender->sendMessage("Test works :)"); break; case "transfer": $gui->sendTo($player); break; } return true; }} And I get this error: Code: [Server thread/CRITICAL]: Error: "Class 'muqsit\invmenu\InvMenu' not found" (EXCEPTION) in "plugins/Commands/src/Commands/Main" at line 22 And yes I did install his plugin.
Alright I did all that now it can call the library, but now I get this: Code: [Server thread/CRITICAL]: TypeError: "Argument 1 passed to muqsit\invmenu\InvMenu::onInventoryClose() must be an instance of pocketmine\Player, instance of Closure given, called in /root/mcpe/plugins/Commands/src/Commands/Main.php on line 29" (EXCEPTION) in "/root/mcpe/virions/InvMenu-master/src/muqsit/invmenu/InvMenu" at line 135
https://github.com/Muqsit/InvMenu/blob/master/src/muqsit/invmenu/InvMenu.php#L135 @Muqsit probably done some upgrades. Examples at invmenu's wiki are outdated... You can use setInventoryCloseListener(callable $func) instead.
Ok it just got so much more confusing! Now i need to call a bunch of stuff and its hard to keep up. Can you make a working test file for this please?
Just replace onInventoryClose with setInventoryCloseListener like @GamakCZ said I've just updated the InvMenu wiki
Here is the updated code, I realized that it kept crashing because I did not call pocketmine\item\Item, but now I guess I need to define it??? Code: [14:46:14] [Server thread/CRITICAL]: Error: "Call to undefined method muqsit\invmenu\InvMenu::addItem()" (EXCEPTION) in "plugins/Commands/src/Commands/Main" at line 38 PHP: <?phpnamespace Commands;use pocketmine\plugin\PluginBase;use pocketmine\command\{Command, CommandSender};use pocketmine\utils\TextFormat as C;use muqsit\invmenu\InvMenu;use pocketmine\nbt\tag\{CompoundTag, ListTag, DoubleTag, FloatTag};use muqsit\invmenu\inventories\BaseFakeInventory;use pocketmine\block\Block;use pocketmine\item\Item;class ServerSelectorGUI{/** @var InvMenu */private $menu;public function __construct(string $name){$this->menu = InvMenu::create(InvMenu::TYPE_CHEST)->readonly()->setName($name)->setListener([$this, "onServerSelectorTransaction"])//you can call class functions this way->setInventoryCloseListener(function(Player $player) : void{$player->sendMessage(TextFormat::GREEN . "You are being transferred...");});}public function addServerToList(Item $item, string $address, int $port) : void{$nbt = $item->getNamedTag();$nbt->setString("Server", $address . ":" . $port);$item->setNamedTag($nbt);$this->menu->addItem($item);}public function onServerSelectorTransaction(Player $player, Item $itemClickedOn) : bool{$player->transfer(...explode(":", $itemClickedOn->getNamedTag()->getString("Server", "play.onthefallbackserv.er:19132")));return true;}public function sendTo(Player $player) : void{$this->menu->send($player);}}$gui = new ServerSelectorGUI("Server Selector");$gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se", 19132);$gui->addServerToList(Item::get(Item::IRON), "play.onmyserverplea.se", 19133);class Main extends PluginBase{public function onLoad(): void{$this->getLogger()->info(C::GREEN . "Loading Commands...");}public function onEnable(): void{$this->getLogger()->info(C::YELLOW . "Enabled Commands!");if(!InvMenuHandler::isRegistered()){InvMenuHandler::register($this);}}public function onDisable(): void{$this->getLogger()->info(C::RED . "Commands Disabled!");}public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{switch($command){case "test":$sender->sendMessage("Test works :)");break;case "transfer":$gui->sendTo($player);break;}return true;}}
Alright fixed that and a couple of other things but as usual it creates another problem -_-: Code: [14:58:14] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to Commands\ServerSelectorGUI::sendTo() must be an instance of Commands\Player, instance of pocketmine\Player given, called in /root/mcpe/plugins/Commands/src/Commands/Main.php on line 98" (EXCEPTION) in "plugins/Commands/src/Commands/Main" at line 48 PHP: public function __construct(string $name){$this->menu = InvMenu::create(InvMenu::TYPE_CHEST)->readonly()->setName($name)->setListener([$this, "onServerSelectorTransaction"])//you can call class functions this way->setInventoryCloseListener(function(Player $player) : void{$player->sendMessage(TextFormat::GREEN . "You are being transferred...");});}public function addServerToList(Item $item, string $address, int $port) : void{$nbt = $item->getNamedTag();$nbt->setString("Server", $address . ":" . $port);$item->setNamedTag($nbt);$this->menu->getInventory()->addItem($item);}public function onServerSelectorTransaction(Player $player, Item $itemClickedOn) : bool{$player->transfer(...explode(":", $itemClickedOn->getNamedTag()->getString("Server", "play.onthefallbackserv.er:19132")));return true;}public function sendTo(Player $player) : void{$this->menu->send($player);}}class Main extends PluginBase{public function onLoad(): void{$this->getLogger()->info(C::GREEN . "Loading Commands...");}public function onEnable(): void{$this->getLogger()->info(C::YELLOW . "Enabled Commands!");if(!InvMenuHandler::isRegistered()){InvMenuHandler::register($this);}}public function onDisable(): void{$this->getLogger()->info(C::RED . "Commands Disabled!");}public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool{switch($command){case "test":$sender->sendMessage("Test works :)");break;case "transfer":$player = $sender->getPlayer();$gui = new ServerSelectorGUI("Server Selector");$gui->addServerToList(Item::get(Item::DIAMOND_PICKAXE), "play.onmyserverplea.se", 19132);$gui->addServerToList(Item::get(Item::IRON_INGOT), "play.onmyserverplea.se", 19133);$gui->sendTo($player);break;}return true;}}