I'm trying to make a plugin which sends a inventory but it doesn't seem to work, can any of you help. Heres the code Code: <?php namespace Karanpatel567; use pocketmine\block\Block; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\event\Listener; use pocketmine\Player; use pocketmine\utils\TextFormat as c; use pocketmine\math\Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\StringTag; use pocketmine\plugin\PluginBase; use pocketmine\tile\Chest; use pocketmine\tile\Tile; class main extends PluginBase implements Listener{ public function onEnable(){ $this->getLogger()->Info(c::GREEN. "addWindow by Karan enabled!"); $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function addWindow(Player $player){ $block = Block::get(54); $player->getLevel()->setBlock(new Vector3($player->x, $player->y - 2, $player->z), $block, true, true); $nbt = new CompoundTag("", [ new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", floor($player->x)), new IntTag("y", floor($player->y) - 2), new IntTag("z", floor($player->z)) ]); $nbt->Items->setTagType(NBT::TAG_Compound); $tile = Tile::createTile("Chest", $player->getLevel()->getChunk($player->getX() >> 4, $player->getZ() >> 4), $nbt); $player->addWindow($tile->getInventory()); } public function onCommand(CommandSender $sender, Command $cmd, $labels, array $args){ if(strtolower($cmd->getName()) == "addwindow"){ if($sender->hasPermission("addwindow.command")){ $sender->sendMessage(c::YELLOW. "Sending Inventory! Please be patient."); $this->sendInventory($sender); } } } public function onDisable(){ $this->getLogger()->Info(c::RED. "addWindow by Karan disabled!"); } } and heres the error when executing the command, I cant seem to figure out whats wrong. Code: [Server thread/CRITICAL]: Unhandled exception executing command 'addwindow' in addwindow: Call to undefined method Karanpatel567\main::sendInventory() [14:04:36] [Server thread/CRITICAL]: Error: "Call to undefined method Karanpatel567\main::sendInventory()" (EXCEPTION) in "/addWindow/src/Karanpatel567/main" at line 44
Actually the code is PHP: $this->sendInventory($sender); but I get what you were saying. @Karanpatel567 Your main class doesn't have a function called sendInventory() so the undefined method error is what you get. This question should be in the facepalm section. Also, ask about generic php issues on stackoverflow as this forum is only to aid with PocketMine's API.
No worries now guys, i have fixed the code and now is running very well. Thank you all for you suggestions they really helped!
You have to do "floor()" in both setBlock and the tags, by chance, it maybe done wrong by system and your block placed at 16, your making tile at 15