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

Solved DataPacketReceiveEvent not cancellable

Comments in 'Plugin Development' started by MyNameIsTriXz, Sep 3, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    My code
    PHP:
    public function onDataPacketReceive(DataPacketReceiveEvent $event){
                
    $packet $event->getPacket();
          
    //var_dump("Class: ".get_class($packet)." pid: ".$packet->pid());


    if($packet->pid() == Info::PLAYER_ACTION_PACKET){

    var_dump("ACTION: ".$packet->action);

    $event->setCancelled();

    var_dump("EVENT: ".($event->isCancelled()));
    var_dump("PACKET");
    var_dump(($packet));

    }

            }


    }
    I expect that it cancels that the block even gets destroyed, but no, it doesnt work anyways, even if I change the coordinates of the packet or set the event cancelled... How can I cancel that event?
    Last edited: Sep 4, 2016
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Why would you want to cancel that?! Just use BlockBrekEvent.
    Extreme_Heat likes this.
  3. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    You should never use data packet receives for stuff like this because all you're doing is adding extra overhead before other unrelated packets can be processed.
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Actually, sometimes packet events are the way to go. I normally use these events for debugging, not for actual functionality.
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    No, I want to use the way where you dont even destroy the block.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Adventure mode is the only solution.
    Primus and MyNameIsTriXz like this.
  7. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Oh thanks

Share This Page

Advertisement