Chests

Discussion in 'Development' started by #A6543, Dec 31, 2016.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    Hello. Does someone know how to open a chest without showing the inventory? (And close the chest after sleep(5) )


    And I tried this to open and close a chest automatically. It crashes the server...
    PHP:
    public function onOpen(InventoryOpenEvent $event){

    $player $event->getPlayer();
    $name $player->getName();
    $inventory $event->getInventory();
      
    $block $inventory->getHolder();

    $chest $this->getServer()->getDefaultLevel()->getTile(new Vector3(1308124));

    if(
    $block->getX() == 130 && $block->getY() == && $block->getZ() == 124 && $block->getLevel() == $this->getServer()->getDefaultLevel()) { 
    $event->setCancelled();
    $chest->getInventory()->open($player);
            
    sleep(4);
    $chest->close();
        }
    }
     
    Last edited: Dec 31, 2016
  2. Lambo

    Lambo Spider

    Messages:
    14
    GitHub:
    Lambo16
    Do you mean that you would like to show the opening animation? It seems pointless for a player to open a chest and not see what's in it.
     
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    Yes.
    Do u know how to do that?
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,401
    GitHub:
    HimbeersaftLP
    Error message?
     
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    Code:
    Segmentation fault
     
  6. Reid

    Reid Spider Jockey

    Messages:
    43
    Why would you use sleep never use sleep atleast inside a plugin
     
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Like Reid said, never use sleep() in a plugin. Sleep() will cause the whole server to sleep for 5 seconds, causing... well nothing to happen for 5 seconds.
     
    jasonwynn10 and HimbeersaftLP like this.
  8. #A6543

    #A6543 Zombie

    Messages:
    267
    Oh. What would you use?
     
  9. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,401
    GitHub:
    HimbeersaftLP
    A task, there's a tutorial for that somewhere in this forums
     
    Muqsit and Sandertv like this.
  10. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I believe the best way is to utilize delayed/scheduled tasks. There are plenty of resources around here for learning about them. Perhaps it would be helpful to know what your purpose is? Why do you not want the chest window to open, but you want the animation?
     
    Sandertv likes this.
  11. #A6543

    #A6543 Zombie

    Messages:
    267
    I need it for a reward plugin. Can u give me an example for how to wait 4 seconds?
     
  12. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    PHP:
    //After you open the chest:
       
    $this->getServer()->getScheduler()->scheduleDelayedTask(new ChestCloseTask($this$player$chest), 20);
    You can use this right after you open the chest, but you need to make the task that closes the chest.

    There is probably a better method, so if anyone knows of one, please share it. This is the best way I know of at the moment.
     
  13. #A6543

    #A6543 Zombie

    Messages:
    267
    Ok. How can I import the class?
     
  14. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Importing a class is basic PHP, learn it before you try WRITING plugins in PHP.
     
  15. #A6543

    #A6543 Zombie

    Messages:
    267
    I know how to import classes....

    But what is the path to the class?
     
  16. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    This is turning more into a Plugin Requests thread rather than Plugin Development. These are pretty basic concepts, so check out this website, or view the Plugin Resources section.
     
    Muqsit likes this.
  17. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You can use sleep within plugins, it's just bad practice to use it in the main thread due to it blocking the entire thread. You can use the sleep() function or any other thread blocking/freezing function in AsyncTask's (although I believe this is also bad practice) and your own threads.

    I picked you up in this just incase someone, someday comes reading this thread and thinks "how am I gonna stop this thread for a tick so it isn't constantly working".
     
    0x15f, HimbeersaftLP and Sandertv like this.
  18. #A6543

    #A6543 Zombie

    Messages:
    267
    I imported pocketmine\scheduler\ServerScheduler; . But it doesn't work
     
  19. Lambo

    Lambo Spider

    Messages:
    14
    GitHub:
    Lambo16
  20. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    cant u use $event->setCancelled()? or nah
     

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.