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

Invild limit

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

  1. sdsd16

    sdsd16 Spider Jockey

    Messages:
    41
    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:
    499
    GitHub:
    xXNiceYT
    Why dont u use interact check if block is chest than block it
     
  3. sdsd16

    sdsd16 Spider Jockey

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

    Destroyer57 Zombie

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

    Muqsit Chicken

    Messages:
    1,548
    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:
    41
    GitHub:
    Danding1314
    i forgot it XD sorry
     
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    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:
    275
    i know but i still asked
     
  9. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    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.
  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.