The plugin I have recently created uses sendMessage to send a message(obviously). However, what I have noticed is that the plugin sends the message twice. I don't even know how to code it so that it repeats like that, so it is not done on purpose. This have never happened with other plugins I have created. The message is sent when the PlayerInteractEvent is triggered. I cannot access my laptop yet, and therefore I cannot provide the code. (I know there must be like 20 other people who had same issue. I tried searching, but it only returned results that contains the word message only. Then I tried searching the word 'twice' and 'sent twice', but it says it is too common. WTF?)
No -_- I get the message back instantly and I tested it multiple times. If it was lag, I would obviously know that.
PHP: public function onPlayerTouch(PlayerInteractEvent $event){ $player = $event->getPlayer(); $block = $event->getBlock(); $name = $event->getPlayer()->getName(); if($block->getID() == 63 || $block->getID() == 68){ $player->sendMessage("Step 1");//This is sent twice $sign = $block->getLevel()->getTile($block); $text = $sign->getText(); if(strtolower($text[0]) === "[checkpoint]"){ $this->cp->setNested($text[1] . "." . $text[2], $name); $this->cp->save(); $player->sendMessage("Step 2!");//This is sent twice switch(substr($text[2], -1)){ case "1": if($text[2] === 11) { $th = "th"; } else { $th = "st"; } break; case "2": if($text[2] === 12) { $th = "th"; } else { $th = "nd"; } break; case "3": if($text[2] === 13) { $th = "th"; } else { $th = "rd"; } break; default: $th = "th"; break; }//My coding style sucks :( $player->sendMessage("You have arrived at the " . $text[2] . $th . " checkpoint in the parkour " . $text[1] . ".");//This is sent twice } } } The message saying step 1 and step 2 was for debug purpose previously. They are being displayed twice too.
If it is lag, doesn't the message have delays? The thing is, that people had similar issue before, but the solution there wasn't suitable for $this. I hosted it locally, the ping is pretty low, yet it still does that. The most important point is that it doesn't happen with other plugins. EDIT: Just found someone with same issue: https://forums.pocketmine.net/threads/playerchatevent-runs-twice.10177/
I thought you meant like, when you type a command like to and it says you have teleported to player at least 5 times. Sorry xD
Hm… I tried your code in my plugin for testing and it was ony sent once. Either your PC is laggy or the client has bad connection.
That's my thread, and I found out what was wrong, an epic fail by me. I had registered events twice by mistake. Check if you have this line on more than one place in the plugin: PHP: $this->getServer()->getPluginManager()->registerEvents($this, $this);
No. If you register more than once, on the same Listener instance, PocketMine will reject it the second time. Any two handlers that belong to the same object (actually, or two objects with the same spl_object_hash) with the same priority and event (forgot if ignore cancelled matters), even if of different method names and/or different instances (but same properties can make them have the same hash), will be recognized as identical event handlers.