Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.0.0': Call to a member function myMoney() on null on jojoe77777\FormAPI\FormAPI Error: "Call to a member function myMoney() on null" (EXCEPTION) in "plugins/EnchantUI_raw/src/ID/armor/antiknockback" at line 25 PHP: <?phpnamespace ID\armor;use pocketmine\Player;use pocketmine\command\ConsoleCommandSender;use pocketmine\utils\TextFormat;use pocketmine\item\Armor;use EnchantUI\Main;// EconomyAPIuse onebone\economyapi\EconomyAPI;class antiknockback{public $eco; private $plugin; public function __construct(Main $plugin){ $this->plugin = $plugin; } public function init(Player $sender){ $eco = $this->plugin->getServer()->getPluginManager()->getPlugin("EconomyAPI"); $api = $this->plugin->getServer()->getPluginManager()->getPlugin("FormAPI"); $money = $this->eco->myMoney($sender->getName()); $form = $api->createCustomForm(function (Player $sender, array $data){ $result = $data[0]; $player = $sender->getName(); $item = $sender->getInventory()->getItemInHand(); if($result != null){ if ($item instanceof Armor) { if($money >= 5000){ $this->eco->grantMoney($sender->getName(),-5000); $this->plugin->getServer()->dispatchCommand(new ConsoleCommandSender, "ce enchant antiknockback $result $player"); $sender->sendMessage(" $data[1] Enchant thành công!"); return true; }else{ $sender->sendMessage("no money"); } return true; }else{ $sender->sendMessage("Enchant này chỉ có hiệu quả với Giáp"); } } }); $form->setTitle(TextFormat::BLUE . "--= " . TextFormat::RED . "EnchantUI" . TextFormat::BLUE . " =--"); $form->addSlider("Max Level:", 1, 1, -1, -1); #rare $form->addLabel("Giảm lượt knockdown xuống 25% cho mỗi bộ giáp"); ;$form->sendToPlayer($sender); } }
It happens because you are trying to access a class variable which is currently set to null. Replace PHP: $this->eco->myMoney($sender->getName()); with PHP: $eco->myMoney($sender->getName()); They are not the same. With $this->variable you access to a class variable while with $variable you access to a function variable (local). In your case you set the EconomyAPI instance into the function's variable $eco and you left the class variable "$this->eco" null. Keep also in mind that to pass variables inside closures you must specify them with the use construct. In essence you should replace: PHP: function (Player $sender, array $data){ with PHP: function (Player $sender, array $data) use ($money){ Also be careful when you use $this variable inside closures.