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(130, 8, 124));if($block->getX() == 130 && $block->getY() == 8 && $block->getZ() == 124 && $block->getLevel() == $this->getServer()->getDefaultLevel()) { $event->setCancelled();$chest->getInventory()->open($player); sleep(4);$chest->close(); }}
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.
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.
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?
PHP: //After you open the chest: $this->getServer()->getScheduler()->scheduleDelayedTask(new ChestCloseTask($this, $player, $chest), 4 * 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.
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.
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".
Never tried on PocketMine, but this might help: https://bukkit.org/threads/opening-chest-animation.298757/