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

eventOnBreakingSnow canceling - help

Discussion in 'Development' started by Lorak9904, Apr 22, 2017.

  1. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    Hi, can u guys help me, with canceling breaking snow with shovel and gaining snowballs? I want to disable this function. I might have some idea, but first, i would like to hear your advices and maybe see examples of code.
     
  2. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Something like this? Players cannot break snow with shovels:
    PHP:
    public function onBreak(BlockBreakEvent $event) {
        
    $block $event->getBlock();
        
    $blockhold $event->getItem();
        if(
    $blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) {
            if(
    $block->getId() === 78 || $block->getId() === 80) {
                
    $event->setCancelled();
            }
        }
    }
     
  3. Lorak9904

    Lorak9904 Witch

    Messages:
    58

    PHP:


    namespace NoSnowballs;

    use 
    pocketmine\plugin\PluginBase as PluginBase;
    use 
    pocketmine\event\Listener as Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\block\Air;
    use 
    pocketmine\block\Snow;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\Item;


    class 
    Main extends PluginBase implements Listener{
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);  
            
    $this->getServer()->getLogger()->info(TextFormat::GREEN "Bezsniezek");
        }


    public function 
    onBreak(BlockBreakEvent $event) {
     
        
    $block $event->getBlock();
        
    $blockhold $event->getItem();
        if(
    $blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) {
            if(
    $block->getId() === 78 || $block->getId() === 80) {
                
    $event->setCancelled();
            }
        }
    }
    [\
    PHP]
    Now i get this error:
    ParseError: "syntax error, unexpected variable (T_VARIABLE), expecting function (T_FUNCTION)" (EXCEPTION) in "myzip:///SnowballsCancel.zip#SnowballsCancel/src/NoSnowballs/Main" at line 17
     
  4. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Use its:
    PHP:
    namespace NoSnowballs;

    use 
    pocketmine\plugin\PluginBase as PluginBase;
    use 
    pocketmine\event\Listener as Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\block\Air;
    use 
    pocketmine\block\Snow;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\Item;


    class 
    Main extends PluginBase implements Listener{
      public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
            
    $this->getServer()->getLogger()->info(TextFormat::GREEN "Bezsniezek");
        }


    public function 
    onBreak(BlockBreakEvent $event) {
     
        
    $block $event->getBlock();
        
    $blockhold $event->getItem();
        if(
    $blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) {
            if(
    $block->getId() === 78 || $block->getId() === 80) {
                
    $event->setCancelled();
              }
          }
      }
    }
    }
    If you want the snow to break, but do not drop the snowballs, use this:
    PHP:
    public function onBreak(BlockBreakEvent $event) {

        
    $block $event->getBlock();
        
    $blockhold $event->getItem();
        if(
    $blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) {
            if(
    $block->getId() === 78 || $block->getId() === 80) {
                
    $event->setCancelled();
                
    $event->setDrops([]);
              }
          }
      }
     
  5. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    ParseError: "syntax error, unexpected '{'" (EXCEPTION) in "myzip:///SnowballsCancel.zip#SnowballsCancel/src/NoSnowballs/Main" at line 16
     
  6. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    There's an extra bracket :p

    Try this:
    PHP:
    <?php

    namespace NoSnowballs;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\block\BlockBreakEvent;

    class 
    Main extends PluginBase implements Listener
    {
        public function 
    onEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info(TextFormat::GREEN "Bezsniezek");
        }


        public function 
    onBreak(BlockBreakEvent $event)
        {

            
    $block $event->getBlock();
            
    $blockhold $event->getItem();
            if (
    $blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) {
                if (
    $block->getId() === 78 || $block->getId() === 80) {
                    
    $event->setCancelled();
                }
            }
        }
    }
     
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Syntax errors are entirely unrelated to PocketMine. I suggest you search on sites like StackOverflow for those. You'll likely get a better explanation.
     
    jasonwynn10 likes this.
  8. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    Ehh thats strange.. It should work, but still:

    ParseError: "syntax error, unexpected '{'" (EXCEPTION) in "myzip:///SnowballsCancel.zip#SnowballsCancel/src/NoSnowballs/Main" at line 11
     
  9. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    On line 11 shouldn't it be onEnable); at the end?
     
  10. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    also remove this "$this->getServer()->getLogger()->info(TextFormat::GREEN . "Bezsniezek");" line because it's pointless
     
  11. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    Still, the same error... Nothing has changed
     
  12. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    This is why we use a good IDE.
     
    Teamblocket likes this.
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Can you send the entire thing you are currrently using?
     
  14. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    Entire thing? U mean code...?
    PHP:
    <?php

    namespace NoSnowballs;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\block\BlockBreakEvent;

    class 
    Main extends PluginBase implements Listener
    {
        public function 
    onEnable();
        {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }


        public function 
    onBreak(BlockBreakEvent $event)
        {

            
    $block $event->getBlock();
            
    $blockhold $event->getItem();
            if (
    $blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) {
                if (
    $block->getId() === 78 || $block->getId() === 80) {
                    
    $event->setCancelled();
                }
            }
        }
    }
    [\
    PHP
     
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Remove the ; (semicolon) after onEnable()
     
  16. Lorak9904

    Lorak9904 Witch

    Messages:
    58
    It doesnt change anything
     
  17. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    it does! or at least it SHOULD
     
  18. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Then send what you are using now.
     
  19. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Here, should fix your useless syntax problems.
    PHP:
    use pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\plugin\PluginBase;
    class 
    Main extends PluginBase implements Listener{
            public function 
    onEnable(){
                    
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            }


            public function 
    onBreak(BlockBreakEvent $event){
            
                    
    $block $event->getBlock();
                    
    $blockhold $event->getItem();
                    if (
    $blockhold->getId() === 256 || $blockhold->getId() === 269 || $blockhold->getId() === 273 || $blockhold->getId() === 277 || $blockhold->getId() === 284) {
                            if (
    $block->getId() === 78 || $block->getId() === 80) {
                                    
    $event->setCancelled();
                            }
                    }
            }
    }
     
    jasonwynn10 likes this.
  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.