Hello coders, i have a seconds class calles SenListener. In this task i extends the Plugin Base But i cant call on this class the $this->getServer() methode. Im using the server::getInstance() methode, can somebody tell my whi this does not working? -Sensej
SenListener won't have $this->getServer(), I recommend you pass the server into the listener when it's created.
so you mean on my main class PHP: $this->server = $this->getServer(); To the Listener PHP: public function __construct(mainclass $plugin) { $this->plugin = $plugin; }and call them this->plugin->server ?
$this->getOwner()->getServer(). The beat method. All things you can do as $this->blah() in $this->getServer() should be done as $this->getOwner()->blah() in a PluginTask. Note that it must be a public function. And $this->blah properties (@Dinokiller, you win) should be accessed with the same way $this->getOwner()->blah, except they must be public, again.
Get this Error PHP: Fatal error: Call to undefined method Senplay\SenListener::getOwner() in C:\Server\SenServer\plugins\Senplay\src\Senplay\SenListener.php on line 35
@LDX Nope the Economy Plugin is not not the Main Plugin. I use for the main class this: PHP: public function __construct(Senplay $plugin) { $this->main = $plugin; $this->economy = $this->getOwner()->getPluginManager()->getPlugin("Economy"); }
$this->getOwner() returns your main class, so the server object is $this->getOwner()->getServer(). Edit: remember to pass owner parameter to parent constructor.
PHP: My Code<?phpnamespace SenPlay;use pocketmine\event\Listener;use pocketmine\event\player\PlayerChatEvent;use pocketmine\event\block\BlockBreakEvent;use pocketmine\Player; use pocketmine\level\Position; use pocketmine\math\Vector3;use pocketmine\level\Level;use pocketmine\block\Block; use pocketmine\scheduler\PluginTask;use pocketmine\item\Item;use pocketmine\server; class SenListener extends PluginTask implements Listener{ public function __construct(SenPlay $plugin) { $this->main = $plugin; $this->economy = $this->getOwner()->getServer()->getPluginManager()->getPlugin("Economy"); } /* My Events */}
Sorry found my Mistake.... @PEMapModder is it better to use PHP: $this->main->getServer()->...; or PHP: server::getInstance()->...; PS: I need the fastest methode
I think what @PEMapModder is trying to tell you is Code: public function __construct(SenPlay $plugin) { parent::__construct($plugin); //parent constructor $this->economy = $this->getOwner()->getServer()->getPluginManager()->getPlugin("Economy"); } That's supposed to set the owner, I believe. Correct me if I'm wrong, anyone.