Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Solved] [New API] Can't cancel Player Move Event

Comments in 'Plugin Development' started by Adaasi, Sep 8, 2014.

  1. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    I'm trying to create a plugin that prevents players from move and place/destroy blocks.
    I can't cancel move event. This is my code:
    PHP:
    public function BlockDestroy(BlockBreakEvent $ev){
                
    $ev->setCancelled(true);

    public function 
    BlockPlace(BlockPlaceEvent $ev){
                
    $ev->setCancelled(true);
    }
    public function 
    PlayerMove(EntityMoveEvent $ev){
                
    $ev->setCancelled(true);
    }
    I don't know why EntityMoveEvent isn't cancelled.
  2. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,196
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
  3. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    Yes I already read the SimpleAuth source code.
    What did I do wrong?
    Last edited: Sep 8, 2014
  4. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    94
    Plugins:
    2
    Minecraft User:
    ekifox
    You add an "use" elements in head of file?
    use pocketmine\event\block\BlockBreakEvent;
    use pocketmine\event\block\BlockPlaceEvent;
    use pocketmine\event\entity\EntityMoveEvent;
  5. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It isn't the problem. If he didn't add the aliases, the plugin will crash.
    Tuff likes this.
  7. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    94
    Plugins:
    2
    Minecraft User:
    ekifox
    public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); }
    Tuff likes this.
  8. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    xFlare and EkiFoX like this.
  9. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    This is onEnable():
    PHP:
     public function onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents(new PManager($this), $this);
        }
  10. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    94
    Plugins:
    2
    Minecraft User:
    ekifox
    But my plugin dont work without registerEvents...
    Tuff likes this.
  11. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    The plugin didn't crash.
    The only problem is that I can't cancel EntityMoveEvent
    Tuff likes this.
  12. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    I already added onEnable
  13. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    94
    Plugins:
    2
    Minecraft User:
    ekifox
    Can you test without "new PManager($this)"? Only $this, $this
  14. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    Can you write me an example?
    Remember that I use 2 class:
    Start.php <- Here there is only onEnable event
    PManager.php <- Here there are all events
  15. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    94
    Plugins:
    2
    Minecraft User:
    ekifox
    If u test from BigBrother - MoveEvent setCancelled will not work.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    His handler is at PManager! Do you know what you're talking about?
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Are you sure when you want to cancel entity move event it is actually called?
  18. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    94
    Plugins:
    2
    Minecraft User:
    ekifox
    I did not see this, sorry =\
  19. Adaasi
    Offline

    Adaasi Active Member

    Joined:
    Aug 14, 2014
    Posts:
    78
    I think yes because BlockPlaceEvent and BlockBreakEvent work.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    When the move event is triggered, make a debug message. That confirms it is not your problem.
    Tuff likes this.

Share This Page

Advertisement