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

Solved Is it possible to cancel player changing slot?

Discussion in 'Development' started by MulkiGT, Jun 18, 2020.

  1. MulkiGT

    MulkiGT Silverfish

    Messages:
    18
    GitHub:
    babosapple
    I have a attempt for this butit failed, and i dont know whats going on. I search for this problem around the internet, but i still didnt get it
    here's my code
    PHP:
     public function onInventoryTransaction(InventoryTransactionEvent $event){
            
    $transaction $event->getTransaction();
            
    $player $transaction->getSource();
            
    $action $transaction->getActions();
            if(
    $action instanceof SlotChangeAction){
                
    $event->setCancelled();
             }
         }
    sorry if my code was bad, cuz am new hehe
     
  2. Heisenburger69

    Heisenburger69 Silverfish

    Messages:
    16
    GitHub:
    heisenburger69
    Based off what I can see getActions() returns an
    array of actions, so checking if an array is an instance of SlotChangeAction will always result in false.
    You can var_dump($action) to see what it is and how to achieve your goal
     
    MulkiGT likes this.
  3. MulkiGT

    MulkiGT Silverfish

    Messages:
    18
    GitHub:
    babosapple
    so how's var_dump do and how can i use it?
    also, can i use other method to achieve my goal than this? so if i failed i can use other method
     
    Last edited: Jun 18, 2020
  4. MulkiGT

    MulkiGT Silverfish

    Messages:
    18
    GitHub:
    babosapple
    ups i was fixing my own problem UwU
    PHP:
    public function noInvMove(InventoryTransactionEvent $event){
            if(
    $this->getServer()->getLevelByName("world")->getPlayers()){
             
    $event->setCancelled();
            }
        }
    UwU, well i didnt even expain all in the thried yet but ok UwU
     
  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.