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

Solved SetBlockIdAt onCommand

Discussion in 'Development' started by armagadon159753, Feb 13, 2018.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Code:
    PHP:
    public function onBlock(BlockBreakEvent $event){
            
    $player $event->getPlayer();
            
    $block $event->getBlock()
            
    $x $block->getX();
            
    $y $block->getY();
            
    $z $block->getZ();
            
    //$text = "TEXT HERE";
            //$block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x + 0.5, $y + 3, $z + 0.5), "", $text));
            
    $block->getLevel()->setBlockIdAt($x$y 1$z55);
            
    $player->sendMessage("The chest has been added");
    }

        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool{
            if(
    $sender instanceof Player){
                if(
    $command->getName() == 'addchest'){
                    
    $sender->sendMessage("Break a block");
                    
    //TODO
                
    }
            }
            return 
    true;
        }
    if the player breaks a block after executing the command alord a chest appears.
    but only after executing the command
     
  2. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    Do you mean that it's supposed to do that and doesn't work, or that it does do that but isn't supposed to? Please explain.
     
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Its work but i juste want its work only after executing the command
     
  4. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    you wrote the code so it replaces the block when you break it...
     
    armagadon159753 likes this.
  5. Daniktheboss

    Daniktheboss Baby Zombie

    Messages:
    144
    GitHub:
    daniktheboss
    do this,
    PHP:
    public $block;

    public function 
    onBlock(BlockBreakEvent $event){
            
    $player $event->getPlayer();
            if(!isset(
    $this->block[$player->getName()]) return;
            
    $block $event->getBlock()
            
    $x $block->getX();
            
    $y $block->getY();
            
    $z $block->getZ();
            
    //$text = "TEXT HERE";
            //$block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x + 0.5, $y + 3, $z + 0.5), "", $text));
            
    $block->getLevel()->setBlockIdAt($x$y 1$z55);
            
    $player->sendMessage("The chest has been added");
            unset(
    $this->block[$player->getName()];
    }

        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool{
            if(
    $sender instanceof Player){
                if(
    $command->getName() == 'addchest'){
                    
    $sender->sendMessage("Break a block");
                    
    $this->block[$sender->getName()] = true;
                }
            }
            return 
    true;
        }
     
    armagadon159753 likes this.
  6. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Its work fine Thann 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.