Error: PHP: 16.06 22:43:59 [Server] Server thread/CRITICAL TypeError: "Argument 2 passed to Zayd\Other\EventHandler::__construct() must be an instance of Zayd\Other\Items, none given, called in phar:///plugins/ComboCore_v2.0.0 (4).phar/src/Zayd/Main.php on line 49" (EXCEPTION) in "/ComboCore_v2.0.0 (4).phar/src/Zayd/Other/EventHandler" at line 36 EventHandler Class: PHP: namespace Zayd\Other;use Zayd\Other\Items;use Zayd\Main;class EventHandler implements Listener { public function __construct(Main $main, Items $items) { $this->main = $main; $this->items = $items; } public function getPrefix(){ return $this->main->prefix; } public function getItems(){ return $this->items; } Items Class: PHP: namespace Zayd\Other;use Zayd\Main;class Items extends Item { public function __construct(Main $main) { $this->main = $main; } Folder Structure: src->Zayd->Other->Items.php src->Zayd->Other->EventHandler.php No idea why this is happening?
Your Items class constructor needs to have the same parameters as the Item class. It also needs a parent constructor call. This has nothing to do with PocketMine API. Learn PHP or put questions like this in the facepalm section.
How are you creating the EventHandler object? Also, your Items class doesn't have a use statement for pocketmine\item\Item.
Actually, only classes that extend another need a parent constructor call Implements implements an interface, which don't have (filled) constructors
where's the main file? you also completely missed the error, Code: class Door {pub func __construct(Owner $owner, Key$key){}} $door = new Door(new Owner("thunder")); your mistake is forgetting to give the "Key" in this example this would result in something like "Argument 2 passed to Door::__construct() must be an instance of Key, none given, called in now here" to fix it just do Code: $door = new Door(new Owner("thunder"),new Key("1337")); in a general sense however you are meant to construct that said object will work
If you weren't creating an instance of that class, you wouldn't be getting that error. Learn about objects if you don't quite understand. Can we see the code in your main class where you register the listener?
PHP: use Zayd\Other\EventHandler;public function onEnable(){$this->getServer()->getPluginManager()->registerEvents(new EventHandler($this), $this);}
You have to have an Items object for the second parameter in "new EventHandler()". This will resolve your error and you will then be able to use it.
I don't quite know what you mean with parenthesis, but I meant something like this: PHP: use Zayd\Other\EventHandler;public function onEnable(){$this->getServer()->getPluginManager()->registerEvents(new EventHandler($this, new Items($this)), $this);} Again: