Hi, I am making a server core for a while now and everything works, but there is one problem and that is sometimes when player is teleported to another world it throws this error and I don't know why. (The main thing is that it errors only sometimes) Event used: EntityLevelChangeEvent Code: PHP: if($target->getName() === "Lobby"){ $player->setGamemode(2); $player->getInventory()->clearAll(); $player->getArmorInventory()->clearAll(); $this->getScheduler()->scheduleDelayedTask(new class($this, $event->getEntity()) extends Task{ protected $main; public $player; public function __construct(Main $main, CommandSender $player){ $this->main = $main; $this->player = $player; } public function onRun(int $currentTick){ $iron = ItemFactory::get(267, 0, 1); $iron->setCustomName("§l§6Minigames§r§7\n[Use]"); $show = ItemFactory::get(351, 10, 1); $show->setCustomName("§l§7Players §aVisible§r§7\n[Use]"); $lang = ItemFactory::get(345, 0, 1); $lang->setCustomName("§l§7Settings§r§7\n[Use]"); $gadgets = ItemFactory::get(467, 0, 1); $gadgets->setCustomName("§l§9Gadgets§r§7\n[Use]"); $this->player->getInventory()->setItem(0, $iron); $this->player->getInventory()->setItem(4, $gadgets); $this->player->getInventory()->setItem(7, $show); $this->player->getInventory()->setItem(8, $lang); } }, 5 ); }
what do you mean? how are you using $player without obj in onRun function????? what do you want to do? no explain = no help and wtf? if you see 1 sec onRun fuinction you can see he used $player without player obj, why do you asking this question??
I know, it would be normal if it didn't work anytime but it works but sometimes it throws this error, I tried to add player object to the onRun function too, but it did the same thing. I don't know how to explain it properly. It works, the plugin works but sometimes like 2 times a day it throws this error for some reason..
you can ger players in that func like: PHP: foreach(Server::getinstance()->getOnlinePlayers as $player) {//code here} i think you used another files for onRun and for that i used Server::getinstance()
Without the whole code neither you, neither me cannot 100% say that there is a mistake. Also, please do not send code which doesn't work and you didn't test it. I think you need more experience to help people on pmmp forums for example here you have specified Server::getInstance() method wrong and also Server->getOnlinePlayers() is function, NO property as you have said.
i didnt get your target but i said, open your eyes, i said if you created task in another files you should use Server::getInatnce() instead $this->getServer(), you should open you eyes befor POSTING.
also PHP: foreach($this->getServer()->getOnlinePlayers as $player) {} working fine, befor posting upgrade your knowledge bruh LMAO