So this code: PHP: public function getData(){ return $this->data; } public function onPlayerJoin(PlayerJoinEvent $ev){ //line 809 $player = $ev->getPlayer(); $name = $player->getName(); $event->setJoinMessage("");} give me this error: Code: ParseError: "syntax error, unexpected 'public function onPlayerJoin' (T_STRING), expecting function (T_FUNCTION)" (EXCEPTION) in "/FactionCore/src/VCraft/FactionsCore/Main" at line 809 help?
First of all, use PHP: [PHP] for php and Code: [CODE] for your code. And I think the issue is that you wrote onPlayerJoin, it should be onJoin if my memory is good
Function name can be anything (with exceptions). There is no standard for how to name your listening functions. But I mostly name them like this PHP: function get_func_name(Event $event): string { return "on".substr($class = array_reverse(explode("\\", get_class($event)))[0], 0, strpos($class, "Event"));}
Ok PHP: public function onChat(PlayerChatEvent $event){ $player = $event->getPlayer(); if(isset($this->chat[strtolower($player->getName())])){ foreach(Server::getInstance()->getOnlinePlayers() as $players){ if($players->hasPermission("staff.chat")){ $players->sendMessage(C::RED."(!) STAFF: ".C::DARK_AQUA."{$player->getDisplayName()}: §f{$event->getMessage()}"); $event->setCancelled(true); } } } } public function welcomeTitle($p){ $p->sendTitle(C::RED."Welcome",C::DARK_AQUA."enjoy your stay"); } public function getData(){ return $this->data; } public function on_Player_Join(PlayerJoinEvent $ev){ $player = $ev->getPlayer(); $name = $player->getName(); $event->setJoinMessage(""); }
It appears that the "public function onPlayerJoin" is being read as a string and not a function, but that seems wrong. I suggest examining that section of the plugin very carefully. Maybe you will find a stray quotation mark or something that is causing the issue. Also, this is more of a PHP issue than a Pocketmine issue, so you may have more luck by looking on StackOverflow or similar websites.
Your code is PHP: $event->setJoinMessage(""); If you're trying to hide the join message you should be using PHP: $e->setJoinMessage("");
He's using T-Spoon, so it is actually sendTitle(), but obviously you didn't know so it isn't your fault
Any convention that is clear enough to prevent name collision is OK. For example something that specifies that it is an event handler, and for that event. Therefore conventionally we use the prefixes like "on", "event", "e_", etc., and a simple verb or noun-verb clause to specify the event so that different events won't accidentally have the same name. A simpler way of naming is to type random words by telling your cat to jump on your keyboard.