pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP
https://pmmp.io
GNU Lesser General Public License v3.0
3.27k stars 1.54k forks source link

BlockUpdateEvent doesn't cancelled when block is "Water Block" #3334

Closed alvin0319 closed 4 years ago

alvin0319 commented 4 years ago

Issue description

Steps to reproduce the issue

  1. Join the game.
  2. Get water block with command "/give [playerName] 8 1"
  3. Place the Water Block.

Youtube Link

OS and versions

Plugins

<?php
/**
 * @name DIsableBlockTIck
 * @author alvin0319
 * @main DisableBlockTick\DisableBlockTick
 * @version 1.0.0
 * @api 3.0.0
 */
declare(strict_types=1);
namespace DisableBlockTick;

use pocketmine\block\BlockIds;
use pocketmine\event\block\BlockUpdateEvent;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;

class DisableBlockTick extends PluginBase implements Listener{

    public function onEnable() : void{
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }

    public function onBlockUpdate(BlockUpdateEvent $event){
        $block = $event->getBlock();

        if(in_array($block->getId(), [
            BlockIds::GRASS, BlockIds::WATER, BlockIds::STILL_WATER, BlockIds::FLOWING_WATER
        ])){
            $event->setCancelled();
            $this->getLogger()->info("Cancelled Block Update: " . $block);
        }
    }
}

Crashdump, backtrace or other files

matcracker commented 4 years ago

You need to use BlockSpreadEvent.

support[bot] commented 4 years ago

Thanks, but this issue tracker is not intended for support requests. Please read the guidelines on submitting an issue.

Docs | Discord | Forums

alvin0319 commented 4 years ago

but it works on 4.0.0

dktapps commented 4 years ago

This is because of a behavioural change in the internals. It wasn't backported due to potential disruption to functionality.

You should use BlockSpreadEvent as suggested above.