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

Solved removing a block after 30 seconds

Discussion in 'Development' started by Astro, Nov 21, 2018.

  1. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    i'm having issues with my code and it's the block isn't breaking after 30 seconds

    PHP:
    class EVEvents implements Listener {

        public function 
    __construct(Main $plugin) {
            
    $this->plugin $plugin;
            
    $this->time 30;
        }

        public function 
    onBlockPlace(BlockPlaceEvent $event) {
            
    $Player $event->getPlayer();
            
    $ev $event->getBlock()->getId();
            
    $block $event->getBlock();
            
    $x $block->getX();
            
    $y $block->getY();
            
    $z $block->getZ();

            
    $evdamage $event->getBlock()->getDamage();
            if (
    $ev === 120 || $evdamage === 1) {
                
    $Player->addTitle("§8§l[§5!§8]§r§e Opening an Ender Vault §8§l[§5!§8]""§8§l[§5!§8]§r§7 The ender vault will automatically break after 30 seconds! §8§l[§5!§8]§r");
                
    $block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x 0.5$y 2.5$z 0.5), """§8§l[§5!§8] §r§d Rewards §l§8[§5!§8]§r"));
            }

            
    $timer $this->time--;
            if (
    $timer == 30) {
                
    $ev $event->getBlock()->getId();
                
    $block $event->getBlock();
                if (
    $ev === 120 || $evdamage === 1) {
                    
    $x $block->getX();
                    
    $y $block->getY();
                    
    $z $block->getZ();
                    
    $pos = new Vector3($x$y$z);
                    
    $replacement Item::AIR;
                    
    $level $Player->getLevel();
                    
    $level->setBlock($pos$replacementtrue);
                    
    $block->getLevel()->addParticle(new FloatingTextParticle(new Vector3($x 0.5$y 2.5$z 0.5), """"));
                }
            }
        }
    }
     
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    Best Create the Task in Separate Classes and Place the BlockPlaceEvent Function on Proper Main and When Activated Call the Task That in Time Removes the Block

    in Main.php:
    public function blockPlace(BlockPlaceEvent $ev){
    $b = $ev->getBlock();
    if($b->getId() == 120 and $b->getDamage() == 1){
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new remove($this, $b), 20); //define name to task *remove.php*
    return true;
    }
    }
    inTask :
    public function __construct(Main $pl, $b){
    $this->pl = $pl;
    $this->b = $b;
    }
    public $time = 30;
    public function onRun($tick){
    $this->time--;
    if($this->time == 0){
    $b = $this->b;
    $b->getLevel()->setBlock($b, Block::get(block::AIR));
    $this->getServer()->cancelTask($this->getTaskId());
    }
    }
     
  3. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro

    still doesn't remove the block
     
  4. Astro

    Astro Slime

    Messages:
    78
    GitHub:
    RealAstro
    welp, i guess i have to find another way
     
  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.