Hi, I'm getting this error since the 1.1 update on PMMP. Code: 2017-06-19 [03:06:31] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'seat v2.1.0': Non-static method pocketmine\Server::broadcastPacket() should not be called statically on seat\seat 2017-06-19 [03:06:31] [Server thread/CRITICAL]: ErrorException: "Non-static method pocketmine\Server::broadcastPacket() should not be called statically" (EXCEPTION) in "/seat_v2.1.0/src/seat/seat" at line 76 This is the full code of the plugin: Spoiler: Code PHP: <?phpnamespace seat;use pocketmine\Server;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\entity\Entity;use pocketmine\math\Vector3;use pocketmine\event\server\DataPacketReceiveEvent;use pocketmine\network\mcpe\protocol\AddEntityPacket;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\network\mcpe\protocol\ProtocolInfo as ProtocolInfo;use pocketmine\network\mcpe\protocol\RemoveEntityPacket;use pocketmine\network\mcpe\protocol\SetEntityLinkPacket;use pocketmine\network\mcpe\protocol\PlayerActionPacket;use pocketmine\Player;class seat extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this);$this->count = 10000;}public function onPacketReceived(DataPacketReceiveEvent $event){$pk = $event->getPacket();switch($pk::NETWORK_ID){case ProtocolInfo::PLAYER_ACTION_PACKET;$player = $event->getPlayer();if(isset($this->counter[$player->getName()])){if($pk->action === 8){$ppk = new SetEntityLinkPacket();$ppk->from = $this->counter[$player->getName()];$ppk->to = 0;$ppk->type = 0;$player->dataPacket($ppk);$pkc = new SetEntityLinkPacket();$pkc->from = $this->counter[$player->getName()];$pkc->to = $player->getId();$pkc->type = 0;$ps=Server::getInstance()->getOnlinePlayers();Server::broadcastPacket($ps,$pkc);$pk0 = new RemoveEntityPacket();$pk0->eid = $this->counter[$player->getName()];$ps=Server::getInstance()->getOnlinePlayers();Server::broadcastPacket($ps,$pk0);unset($this->counter[$player->getName()]);}}}}public function onTouch(PlayerInteractEvent $event){if($event->getBlock()->getID() === 53){$player = $event->getPlayer();$pk = new AddEntityPacket();$this->count = $this->count + 1;$pk->eid= $this->count;$pk->type = 86;$pk->x= $event->getBlock()->x + 0.6;$pk->y = $event->getBlock()->y +1.4;$pk->z = $event->getBlock()->z + 0.5;$pk->speedX = 0;$pk->speedY = 0;$pk->speedZ = 0;$pk->yaw = $player->yaw;$pk->pitch = $player->pitch;$pk->metadata = [ entity::DATA_FLAGS => [ entity::DATA_TYPE_BYTE, 1 << entity::DATA_FLAG_INVISIBLE ], entity::DATA_NAMETAG => [ entity::DATA_TYPE_STRING, ], entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG => [ entity::DATA_TYPE_BYTE, 1 ], Entity::DATA_FLAG_NO_AI => [ Entity::DATA_TYPE_BYTE, 1 ] ];$ps=Server::getInstance()->getOnlinePlayers();Server::broadcastPacket($ps,$pk);$ppk = new SetEntityLinkPacket();$ppk->from = $this->count;$ppk->to = 0;$ppk->type = 2;$player->dataPacket($ppk);$pkc = new SetEntityLinkPacket();$pkc->from = $this->count;$pkc->to = $player->getId();$pkc->type = 2;$ps=Server::getInstance()->getOnlinePlayers();Server::broadcastPacket($ps,$pkc);$this->counter[$player->getName()] = $this->count;}}} What can I do to fix this?
There were a lot more issues with that code then the ones you were having... PHP: <?phpnamespace seat;use pocketmine\entity\Entity;use pocketmine\Server;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\server\DataPacketReceiveEvent;use pocketmine\network\mcpe\protocol\AddEntityPacket;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\network\mcpe\protocol\ProtocolInfo;use pocketmine\network\mcpe\protocol\RemoveEntityPacket;use pocketmine\network\mcpe\protocol\SetEntityLinkPacket;class seat extends PluginBase implements Listener{ public $counter = []; public $count = 0; public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->count = 10000; } public function onPacketReceived(DataPacketReceiveEvent $event){ $pk = $event->getPacket(); switch($pk::NETWORK_ID){ case ProtocolInfo::PLAYER_ACTION_PACKET; $player = $event->getPlayer(); if(isset($this->counter[$player->getName()])){ if($pk->action === 8){$ppk = new SetEntityLinkPacket(); $ppk->from = $this->counter[$player->getName()]; $ppk->to = 0; $ppk->type = 0; $player->dataPacket($ppk); $pkc = new SetEntityLinkPacket(); $pkc->from = $this->counter[$player->getName()]; $pkc->to = $player->getId(); $pkc->type = 0; $ps=Server::getInstance()->getOnlinePlayers(); Server::getInstance()->broadcastPacket($ps,$pkc); $pk0 = new RemoveEntityPacket(); $pk0->entityUniqueId = $this->counter[$player->getName()]; $ps=Server::getInstance()->getOnlinePlayers(); Server::getInstance()->broadcastPacket($ps,$pk0); unset($this->counter[$player->getName()]); } } } } public function onTouch(PlayerInteractEvent $event){ if($event->getBlock()->getID() === 53){ $player = $event->getPlayer(); $pk = new AddEntityPacket(); $this->count = $this->count + 1; $pk->entityRuntimeId=$this->count; $pk->type = 86;$pk->x= $event->getBlock()->x + 0.6;$pk->y = $event->getBlock()->y +1.4;$pk->z = $event->getBlock()->z + 0.5; $pk->speedX = 0;$pk->speedY = 0;$pk->speedZ = 0; $pk->yaw = $player->yaw; $pk->pitch = $player->pitch; $pk->metadata = [ entity::DATA_FLAGS => [ entity::DATA_TYPE_BYTE, 1 << entity::DATA_FLAG_INVISIBLE ], entity::DATA_NAMETAG => [ entity::DATA_TYPE_STRING, ], entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG => [ entity::DATA_TYPE_BYTE, 1 ], Entity::DATA_FLAG_NO_AI => [ Entity::DATA_TYPE_BYTE, 1 ] ]; $ps=Server::getInstance()->getOnlinePlayers(); Server::getInstance()->broadcastPacket($ps,$pk); $ppk = new SetEntityLinkPacket(); $ppk->from = $this->count; $ppk->to = 0; $ppk->type = 2;$player->dataPacket($ppk); $pkc = new SetEntityLinkPacket(); $pkc->from = $this->count; $pkc->to = $player->getId();$pkc->type = 2; $ps=Server::getInstance()->getOnlinePlayers(); Server::getInstance()->broadcastPacket($ps,$pkc); $this->counter[$player->getName()] = $this->count; } }}
For some reason I'm getting this error Code: [16:19:15] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'seat v2.1.0': Undefined offset: 1 on seat\seat [16:19:15] [Server thread/CRITICAL]: ErrorException: "Undefined offset: 1" (EXCEPTION) in "/src/pocketmine/network/mcpe/protocol/DataPacket" at line 187
@Kabluinc Don't just copy/paste the code people kindly give you... Try to understand it too, and correct it if necessary.
I'm not quite sure what is wrong. If there was a quote of which line there was an error in, in console, id have a better understanding. But due to it relating to "/src/pocketmine/network/mcpe/protocol/DataPacket" I'm a bit lost.
Many reported errors have root causes that are not shown in console, unless you enable debug... and even then :-/ But if you code in a good IDE a lot of these kind of errors will be obvious, and you might even get pop-ups to help you fix them! Once syntax errors and typos are fixed, then you can start to narrow down the problem to find which line causes it, and why.
This is the full debug output in console with debug level set to 2 in pocketmine.yml Code: [16:58:46] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'seat v2.1.0': Undefined offset: 1 on seat\seat [16:58:46] [Server thread/CRITICAL]: ErrorException: "Undefined offset: 1" (EXCEPTION) in "/src/pocketmine/network/mcpe/protocol/DataPacket" at line 187 [16:58:46] [Server thread/DEBUG]: #0 /src/pocketmine/network/mcpe/protocol/DataPacket(187): pocketmine\{closure}(integer 8, string Undefined offset: 1, string C:\Users\Gamer27832 server\Desktop\New folder (3)\src\pocketmine\network\mcpe\protocol\DataPacket.php, integer 187, array Array()) [16:58:46] [Server thread/DEBUG]: #1 /src/pocketmine/network/mcpe/protocol/AddEntityPacket(104): pocketmine\network\mcpe\protocol\DataPacket->putEntityMetadata(array Array()) [16:58:46] [Server thread/DEBUG]: #2 /src/pocketmine/Server(1793): pocketmine\network\mcpe\protocol\AddEntityPacket->encode(boolean) [16:58:46] [Server thread/DEBUG]: #3 /plugins/seat_v2.1.0/src/seat/seat(76): pocketmine\Server->broadcastPacket(array Array(), pocketmine\network\mcpe\protocol\AddEntityPacket object) [16:58:46] [Server thread/DEBUG]: #4 /src/pocketmine/plugin/MethodEventExecutor(38): seat\seat->onTouch(pocketmine\event\player\PlayerInteractEvent object) [16:58:46] [Server thread/DEBUG]: #5 /src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(seat\seat object, pocketmine\event\player\PlayerInteractEvent object) [16:58:46] [Server thread/DEBUG]: #6 /src/pocketmine/plugin/PluginManager(685): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\player\PlayerInteractEvent object) [16:58:46] [Server thread/DEBUG]: #7 /src/pocketmine/level/Level(1725): pocketmine\plugin\PluginManager->callEvent(pocketmine\event\player\PlayerInteractEvent object) [16:58:46] [Server thread/DEBUG]: #8 /src/pocketmine/Player(2452): pocketmine\level\Level->useItemOn(pocketmine\math\Vector3 object, pocketmine\item\ItemBlock object, integer 1, double 0.6131, double 0.5, double 0.7726, pocketmine\Player object, boolean 1) [16:58:46] [Server thread/DEBUG]: #9 /src/pocketmine/network/mcpe/protocol/UseItemPacket(71): pocketmine\Player->handleUseItem(pocketmine\network\mcpe\protocol\UseItemPacket object) [16:58:46] [Server thread/DEBUG]: #10 /src/pocketmine/Player(3275): pocketmine\network\mcpe\protocol\UseItemPacket->handle(pocketmine\Player object) [16:58:46] [Server thread/DEBUG]: #11 /src/pocketmine/network/mcpe/protocol/BatchPacket(105): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\UseItemPacket object) [16:58:46] [Server thread/DEBUG]: #12 /src/pocketmine/Player(3275): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\Player object) [16:58:46] [Server thread/DEBUG]: #13 /src/pocketmine/network/mcpe/RakLibInterface(138): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object) [16:58:46] [Server thread/DEBUG]: #14 /src/raklib/server/ServerHandler(92): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.0.70:52939, raklib\protocol\EncapsulatedPacket object, integer 0) [16:58:46] [Server thread/DEBUG]: #15 /src/pocketmine/network/mcpe/RakLibInterface(79): raklib\server\ServerHandler->handlePacket(boolean) [16:58:46] [Server thread/DEBUG]: #16 /src/pocketmine/network/Network(174): pocketmine\network\mcpe\RakLibInterface->process(boolean) [16:58:46] [Server thread/DEBUG]: #17 /src/pocketmine/Server(2415): pocketmine\network\Network->processInterfaces(boolean) [16:58:46] [Server thread/DEBUG]: #18 /src/pocketmine/Server(2192): pocketmine\Server->tick(boolean) [16:58:46] [Server thread/DEBUG]: #19 /src/pocketmine/Server(2074): pocketmine\Server->tickProcessor(boolean) [16:58:46] [Server thread/DEBUG]: #20 /src/pocketmine/Server(1656): pocketmine\Server->start(boolean) [16:58:46] [Server thread/DEBUG]: #21 /src/pocketmine/PocketMine(504): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\, string C:\, string C:\plugins\) sadly I'm not that experienced to understand the root of this problem ;-; It all 'worked' before 1.1
You need capital 'E's on every 'entity', and the structure of your metadata should be like this - an array of arrays with the type, value. You got the first one right but the other 3 the wrong way around : PHP: $pk->metadata = [Entity::DATA_FLAGS => [Entity::DATA_TYPE_LONG, 1 << Entity::DATA_FLAG_IMMOBILE],... [more of these: type, value]];
Would this be correct? PHP: $pk->metadata = [Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE, 1 << Entity::DATA_FLAG_INVISIBLE],[Entity::DATA_TYPE_STRING << Entity::DATA_NAMETAG] , [Entity::DATA_TYPE_BYTE,1 << Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG], [Entity::DATA_TYPE_BYTE,1 << Entity::DATA_FLAG_NO_AI]];