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

Need some help

Discussion in 'Development' started by str0nix, Sep 27, 2020.

  1. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Greetings,

    I'm writing a plugin which allow players destroy certain blocks in worlds.
    In the first world players allowed to destroy only the oak, birch and pine logs. The code works fine.
    I just copied the code and wanted to do the same with ores too for another world, but it doesn't work and I don't know why. Hope somene could help.
    PHP:
    public function blockBreakOnWoodWorld(BlockBreakEvent $event){

            
    $wood = array("17""17:1""17:2");
            
    $block $event->getBlock();
            
    $player $event->getPlayer();

            
    // WoodWorld
            
    if(!$player->hasPermission("protection.bypass")){
                if(
    $event->getPlayer()->getLevel()->getName() === "woodworld"){
                    if(
    $block->getId() != $wood[0] && $wood[1] && $wood[2]){
                        
    $event->setCancelled();
                    }

                    if(
    $event->isCancelled()){
                        
    $player->sendMessage("You can't destroy this block!");
                    }
                }
            }
        }
    PHP:
    public function blockBreakOnMinerWorld(BlockBreakEvent $event){

            
    $fem = array("1""3""13""14""15""16""21""73""56");
            
    $block $event->getBlock();
            
    $player $event->getPlayer();

            
    // MinerWorld
            
    if(!$player->hasPermission("protection.bypass")){
                if(
    $event->getPlayer()->getLevel()->getName() === "minerworld"){
                    if(
    $block->getId() != $fem[0] && $fem[1] && $fem[2] && $fem[3] && $fem[4] && $fem[5] && $fem[6] && $fem[7] && $fem[8]){
                        
    $event->setCancelled();
                    }

                    if(
    $event->isCancelled()){
                        
    $player->sendMessage("You can't destroy this block!");
                    }
                }
            }
        }
     
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    PHP:
    public function onBreak(BlockBreakEvent $e){
    $player $e->getPlayer();
    $b $e->getBlock();

    $allowedBlocksIds = [1313];////write OTHERS IDs

    if(!in_array($b->getId(), $allowedBlocksIds)){
           
    $e->setCancelled();
      } 
    }
     
    Primus likes this.
  3. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    I’m going to try this, thank you very much!
     
  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.