Invild limit

Discussion in 'Development' started by sdsd16, Jan 3, 2019.

  1. sdsd16

    sdsd16 Spider Jockey

    Messages:
    35
    GitHub:
    Danding1314
    use pocketmine\event\inventory\InventoryOpenEvent;

    public function onInventoryOpen(InventoryOpenEvent $event){
    $inventory = $event->getInventory();
    $player = $event->getPlayer();

    if($inventory instanceof ChestInventory or $inventory instanceof FurnaceInventory){
    if($player->isCreative()){
    $event->setCancelled(true);
    $player->sendMessage("[Limit]>>>Don't do it !");
    }
    }

    When people open the chest who gamemode is creative can't trigger this event! please give me help QWQ
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    689
    GitHub:
    xXNiceYT
    Why dont u use interact check if block is chest than block it
     
  3. sdsd16

    sdsd16 Spider Jockey

    Messages:
    35
    GitHub:
    Danding1314
    i want block creative player use chest
     
  4. Destroyer57

    Destroyer57 Zombie

    Messages:
    220
    Why do u make 2 if statements when you can use the and operator
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,525
    GitHub:
    muqsit
    Did you import the ChestInventory and FurnaceInventory classes?
    PHP:
    use pocketmine\inventory\ChestInventory;
    use 
    pocketmine\inventory\FurnaceInventory;
     
    corytortoise and sdsd16 like this.
  6. sdsd16

    sdsd16 Spider Jockey

    Messages:
    35
    GitHub:
    Danding1314
    i forgot it XD sorry
     
  7. corytortoise

    corytortoise Skeleton

    Messages:
    842
    GitHub:
    corytortoise
    Fewer lines of code ≠ better. OP's example is plenty readable, and there would likely be no noticeable difference in how the plugin runs.
     
  8. Destroyer57

    Destroyer57 Zombie

    Messages:
    220
    i know but i still asked
     
  9. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    712
    GitHub:
    awzaw
    There are a few possible reasons your code isn't working - but the code snippet you posted isn't enough: for example, did you register the plugin to handle events?
    Please post the full code, or a link to the plugin on github.
     
    corytortoise likes this.

Share This Page

  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.