I have a plugin called "GroupJoin", it works like this: - You determine via configuration which groups could announce their entry on the server, for example: Owner: "Owner {player} has joined in the game" (plugin is linked directly to PurePerms and PureChat). I would like to make these messages only appear in a world that I determine via configuration, is that possible? Summary: I want incoming messages to work only in a world that I define, not globally. Main Code: <?php declare(strict_types=1); namespace Himbeer\GroupJoin; use _64FF00\PurePerms\PurePerms; use pocketmine\event\Listener; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerQuitEvent; use pocketmine\Player; use pocketmine\plugin\PluginBase; class Main extends PluginBase implements Listener { /** @var bool */ private $hideOther; /** @var string[][] */ private $messages; /** @var PurePerms */ private $purePerms; public function onEnable(): void { $this->saveDefaultConfig(); $this->hideOther = (bool)$this->getConfig()->get("hide-other"); $this->messages = $this->getConfig()->get("groups"); $this->purePerms = $this->getServer()->getPluginManager()->getPlugin("PurePerms"); $this->getServer()->getPluginManager()->registerEvents($this, $this); } private function getGroupNameForPlayer(Player $player): string { $ppGroup = $this->purePerms->getUserDataMgr()->getGroup($player); if ($ppGroup === null) { // This should never happen, if it does, the server owner messed up their PurePerms config // We don't need to log this, PurePerms does that already return ""; } return $ppGroup->getName(); } private function getMessageForPlayer(Player $player, string $type): ?string { $groupName = $this->getGroupNameForPlayer($player); if (!isset($this->messages[$groupName])) { return null; } $messages = $this->messages[$groupName]; if (!isset($messages[$type])) { return null; } return str_replace("{player}", $player->getName(), $messages[$type]); } public function onJoin(PlayerJoinEvent $event) { $message = $this->getMessageForPlayer($event->getPlayer(), "join"); if ($message) { $event->setJoinMessage($message); } else if ($this->hideOther) { $event->setJoinMessage(""); } } public function onQuit(PlayerQuitEvent $event) { $message = $this->getMessageForPlayer($event->getPlayer(), "leave"); if ($message) { $event->setQuitMessage($message); } else if ($this->hideOther) { $event->setQuitMessage(""); } } } Summary: I want incoming messages to work only in a world that I define, not globally. Repository: https://github.com/HimbeersaftLP/GroupJoin
Foreach all players in a world and send message. If there’s a function that does the same thing in PMMP, please let me know.
Also add PHP blocks around your code when you are on the forums, it makes it look neater. Eg: [P HP] // code here [/P HP] Also remove the space on the codeblock.
Why don't you use the PurePerms to assign permission for the announcement? By doing that you have more flexibility.
This is funny. If you want to send players who have the permission "plugin.seeJoin", then something like this could work. PHP: foreach ($this->getServer()->getOnlinePlayers() as $player) { if(!$player->hasPermission("plugin.seeJoin")){continue;} $player->sendMessage(str_replace("{name}",$player->getName(),"§b{name} has joined the server"));} If you want to let players see the player join message if they are on a certain world, then something like this could work. PHP: foreach ($this->getServer()->getOnlinePlayers() as $player) { if(!$player->getPlayer()->getLevel()->getName() == "LevelName"){continue;} $player->sendMessage(str_replace("{name}",$player->getName(),"§b{name} has joined the server"));}
Which part tho? That's "pseudocode" I used Paamayim Nekudotayim aka. double-colon symbol to reference the method in that class, saying that as a disclaimer before anyone cusses me out saying that there aren't such static methods. The ?-> operator is php8 feature, that I used for pseudocode. And because the second argument of broadcastMessage only accepts an array, I used the null coalescing operator ?? TL;DR: I wanted to represent the idea and not write the actual code
I never knew about pseudocode , EG: `$OnlinePlayers ?? []`. I always use `if($OnlinePlayers == []){$data = "" }` instead Thanks for informing me about it! This information is going to my PHP useful slot I'm officially a Baby Zombie, 100th milestone reached!