I want to create a plugin that send to to all the player have the permission fd.view and op when a player break an diamond ore except member that have fd.bypass. Can anyone help me and how to learn Pmmp API ?
Handle BlockBreakEvent (Check if the block is a Diamond Ore and if the player has the permission return), do a loop to get all the online players, check if they are op/have the permission, send a message to them. To learn the PMMP API, you can look through the github (https://github.com/pmmp/PocketMine-MP) or use the pretty outdated wiki.
The best way to learn is through trial and error. Learn basic PHP then look at other PMMP plugins for examples.
To broadcast a message to all online players having a specific permission, you can use: PHP: /** @var Server $server */$server->broadcast("Your message", "fd.bypass");
I'll not write you the code, but I'll give you some reference to get started 1) Listen to \pocketmine\event\player\BlockBreakEvent, add to use \pocketmine\block\Block 2) To check if a player has permission: Player->hasPermission() 3) To give operator status to a player: Player->setOp() 4) Check if Item->getId() is equal to DIAMOND_ORE / 56 Everything can be found on the PocketMine repository, just use the search bar. Many questions are already answered, I'd suggest to double check before creating a thread.
I write a code here Code: <?php namespace FoundDiamond; use pocketmine\event\block\BlockBreakEvent; use pocketmine\item\Item; use pocketmine\block\Block; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\plugin\PluginManager; use pocketmine\Plugin; use pocketmine\Level; class FoundDiamond extends PluginBase implements Listener{ public function __construct(string $name){ parent::__construct( $name, "%fd.broadcaster", "%fd.bypass", "%fd.toggle" } public function onLoad(){ $this->getLogger()->info("FoundDiamond is loading..."); } public function onEnable(){ $this->getLogger()->info("FoundDiamond is loaded !"); $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->ores=array(56); $this->ingot=array 56 => 264); } public function onDisable(){ $this->getLogger()->info("FoundDiamond is disabled !"); } public function onBreakBlock(\pocketmine\event\player\BlockBreakEvent $event){ $player = $event->getPlayer(); $block = $event->getBlock(); $item = $event->getItem()->getId(); foreach($this->ores as $ore){ if($player->hasPermission("fd.broadcaster"){ if($block->getId() === $ore && !$event->isCancelled()){ $server->broadcast("$player vient de miner 1 diamant", "fd.bypass"
y Yes I tried to start it but I get error : " Console Log [36m[00:08:55] [m[37m[Server thread/INFO]: Loading FoundDiamond v1[m [36m[00:08:55] [m[31m[Server thread/CRITICAL]: ParseError: "syntax error, unexpected '||' (T_BOOLEAN_OR), expecting :: (T_PAAMAYIM_NEKUDOTAYIM)" (EXCEPTION) in "FoundDiamond_v1.phar/src/FoundDiamond/FoundDiamond" at line 42[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #0 (): BaseClassLoader->loadClass(string FoundDiamond\FoundDiamond)[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #1 (): spl_autoload_call(string FoundDiamond\FoundDiamond)[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #2 src/pocketmine/plugin/PharPluginLoader(63): class_exists(string FoundDiamond\FoundDiamond, boolean 1)[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #3 src/pocketmine/plugin/PluginManager(161): pocketmine\plugin\PharPluginLoader->loadPlugin(string phar:///home/gsp_1586/g4.hmserv.eu-19132/plugins/FoundDiamond_v1.phar)[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #4 src/pocketmine/plugin/PluginManager(305): pocketmine\plugin\PluginManager->loadPlugin(string /home/gsp_1586/g4.hmserv.eu-19132/plugins/FoundDiamond_v1.phar, array Array())[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #5 src/pocketmine/Server(1656): pocketmine\plugin\PluginManager->loadPlugins(string /home/gsp_1586/g4.hmserv.eu-19132/plugins/)[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #6 src/pocketmine/PocketMine(553): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string /home/gsp_1586/g4.hmserv.eu-19132/, string /home/gsp_1586/g4.hmserv.eu-19132/plugins/)[m [36m[00:08:55] [m[37m[Server thread/DEBUG]: #7 /home/gsp_1586/g4.hmserv.eu-19132/PocketMine-MP.phar(1): require(string phar:///home/gsp_1586/g4.hmserv.eu-19132/PocketMine-MP.phar/src/pocketmine/PocketMine.php)[m [36m[00:08:55] [m[31m[Server thread/CRITICAL]: Could not load plugin 'FoundDiamond'[m " My code : Code: <?php namespace FoundDiamond; use pocketmine\event\block\BlockBreakEvent; use pocketmine\item\Item; use pocketmine\block\Block; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\plugin\PluginManager; use pocketmine\Plugin; use pocketmine\Level; class FoundDiamond extends PluginBase implements Listener{ public function __construct(string $name){ parent::__construct( $name, "%fd.broadcaster", "%fd.bypass", "%fd.toggle"); } public function onLoad(){ $this->getLogger()->info("FoundDiamond is loading..."); } public function onEnable(){ $this->getLogger()->info("FoundDiamond is loaded !"); $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->ores = array(56); $this->ingot = array (56 => 264); } public function onDisable(){ $this->getLogger()->info("FoundDiamond is disabled !"); } public function onBreakBlock(\pocketmine\event\block\BlockBreakEvent $event){ $player = $event->getPlayer(); $block = $event->getBlock(); $item = $event->getItem()->getId(); foreach($this->array() as $ore || $this->getServer()->getOnlinePlayers() as $player){ if($player->hasPermission("fd.broadcaster") || $player->isOp()){ if ($block->getId() === $ore && !$event->isCancelled()){ if (!empty($server)) { $server->broadcast("$player vient de miner 1 diamant !"); } } } }