1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

FoundDiamonds plugin

Discussion in 'Development' started by Oniii-Chan, Jan 15, 2018.

  1. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    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 ?
     
  2. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
    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.
     
    kazuya and Remarkabless like this.
  3. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    Thanks but I'm new dev of pmmp and I don't know how to do.
    Can you write me a code ?
     
  4. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    Īe
     
  5. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    The best way to learn is through trial and error. Learn basic PHP then look at other PMMP plugins for examples.
     
    EdwardHamHam, Levi and OnTheVerge like this.
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    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");
     
  7. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    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.
     
    SOFe likes this.
  8. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    Thanks for your help :)
     
    Muqsit likes this.
  9. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    Can anyone write a code for me or explain me how to do ?
     
  10. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    I do this code.
    Anyone can tell me if it's work or not and tell me the solution.
     
  11. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    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"
                         
     
  12. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    It is work ?
     
  13. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    Have you tried? What's the outcome from runnin it?
     
  14. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
  15. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    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 !");
                
                
                            
                        }
                    }
            }
    
    }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.