The shop only works for IOS and Win 10 players. Android does not work PHP: public function openShop(Player $player){ $chestBlock = new \pocketmine\block\Chest(); $player->getLevel()->setBlock(new Vector3($player->getFloorX(), $player->getFloorY() - 4, $player->getFloorZ()), $chestBlock, true, true); $nbt = new CompoundTag("", [ new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $player->getFloorX()), new IntTag("y", $player->getFloorY() - 4), new IntTag("z", $player->getFloorZ()) ]); $nbt->Items->setTagType(NBT::TAG_Compound); $tile = Tile::createTile("Chest", $player->getLevel(), $nbt); if($tile instanceof Chest) { $config = new Config($this->getDataFolder() . "shop.yml", Config::YAML); $all = $config->get("Shop"); $tile->getInventory()->clearAll(); for ($i = 0; $i < count($all); $i+=2) { $slot = $i / 2; $tile->getInventory()->setItem($slot, Item::get($all[$i], 0, 1)); } $tile->getInventory()->setItem($tile->getInventory()->getSize()-1, Item::get(Item::WOOL, 14, 1)); $player->addWindow($tile->getInventory()); } } public function createVillager($x, $y, $z, Level $level){ $x += 0.5; $z += 0.5; $nbt = new CompoundTag; $nbt->Pos = new ListTag("Pos", [ new DoubleTag("", $x), new DoubleTag("", $y), new DoubleTag("", $z) ]); $nbt->Rotation = new ListTag("Rotation", [ new FloatTag("", 0), new FloatTag("", 0) ]); $nbt->Health = new ShortTag("Health", 20); $nbt->CustomName = new StringTag("CustomName", TextFormat::GOLD."SHOP"); $nbt->CustomNameVisible = new ByteTag("CustomNameVisible", 1); $level->loadChunk($x >> 4, $z >> 4); $villager = Entity::createEntity("Villager", $level->getChunk($x >> 4, $y >> 4), $nbt); $villager->spawnToAll();public function onTransaction(InventoryTransactionEvent $event) { $trans = $event->getTransaction()-> getActions(); $inv = $event->getTransaction()->getInventories(); $player = null; $chestBlock = null; foreach ($trans as $t) { foreach ($inv as $inventory) { $chest = $inventory->getHolder(); if ($chest instanceof Chest) { $chestBlock = $chest->getBlock(); $transaction = $t; } if ($chest instanceof Player) { $player = $chest; } } } if ($player != null && $chestBlock != null && isset($transaction)) { if($this->inArena($player)) { $config = new Config($this->getDataFolder() . "shop.yml", Config::YAML); $all = $config->get("Shop"); //Test if(in_array($transaction->getTargetItem()->getId(), $all)){ $this->isShopping[$player->getName()] = "ja"; } $arena = $this->getArena($player); $chestTile = $player->getLevel()->getTile($chestBlock); if ($chestTile instanceof Chest) { $TargetItemID = $transaction->getTargetItem()->getId(); $TargetItemDamage = $transaction->getTargetItem()->getDamage(); $TargetItem = $transaction->getTargetItem(); $inventoryTrans = $chestTile->getInventory(); if($this->isShopping[$player->getName()] != "ja") { $zahl = 0; for ($i = 0; $i < count($all); $i += 2) { if ($TargetItemID == $all[$i]) { $zahl++; } } if($zahl == count($all)){ $this->isShopping[$player->getName()] = "ja"; } } if($this->isShopping[$player->getName()] != "ja") { $secondslot = $inventoryTrans->getItem(1)->getId(); if ($secondslot == Item::IRON_INGOT || $secondslot == Item::GOLD_INGOT || $secondslot == Item::BRICK) { $this->isShopping[$player->getName()] = "ja"; } } if($this->isShopping[$player->getName()] == "ja"){ if ($TargetItemID == Item::WOOL && $TargetItemDamage == 14) { $event->setCancelled(true); $config = new Config($this->getDataFolder() . "shop.yml", Config::YAML); $all = $config->get("Shop"); $chestTile->getInventory()->clearAll(); for ($i = 0; $i < count($all); $i = $i + 2) { $slot = $i / 2; $chestTile->getInventory()->setItem($slot, Item::get($all[$i], 0, 1)); } } $TransactionSlot = 0; for ($i = 0; $i < $inventoryTrans->getSize(); $i++) { if ($inventoryTrans->getItem($i)->getId() == $TargetItemID) { $TransactionSlot = $i; break; } } $secondslot = $inventoryTrans->getItem(1)->getId(); if ($TransactionSlot % 2 != 0 && ($secondslot == Item::IRON_INGOT || $secondslot == Item::GOLD_INGOT || $secondslot == Item::BRICK)) { $event->setCancelled(true); } if ($TargetItemID == Item::IRON_INGOT || $TargetItemID == Item::GOLD_INGOT || $TargetItemID == Item::BRICK) { $event->setCancelled(true); } if ($TransactionSlot % 2 == 0 && ($secondslot == Item::IRON_INGOT || $secondslot == Item::GOLD_INGOT || $secondslot == Item::BRICK)) { $iCost = $inventoryTrans->getItem($TransactionSlot + 1)->getId(); $aCost = $inventoryTrans->getItem($TransactionSlot + 1)->getCount(); $aoI = $player->getInventory()->all(Item::get($iCost)); $yourmoney = 0; foreach ($aoI as $currently) { $yourmoney += $currently->getCount(); } if ($yourmoney >= $aCost) { for ($i = 0; $i < $player->getInventory()->getMaxStackSize(); $i++) { if ($player->getInventory()->getItem($i)->getId() == $iCost) { $itemToRemove = $player->getInventory()->getItem($i); if ($itemToRemove->getCount() <= 1) { $player->getInventory()->clear($i); } else { $player->getInventory()->setItem($i, Item::get($iCost, 0, $itemToRemove->getCount() - $aCost)); } break; } } $player->getInventory()->addItem(clone Item::get($inventoryTrans->getItem($TransactionSlot)->getId(), $inventoryTrans->getItem($TransactionSlot)->getDamage(), $inventoryTrans->getItem($TransactionSlot)->getCount())); } $event->setCancelled(true); } if ($secondslot != Item::BRICK && $secondslot != Item::IRON_INGOT && $secondslot != Item::GOLD_INGOT) { $event->setCancelled(true); $config = new Config($this->getDataFolder() . "shop.yml", Config::YAML); $all = $config->get("Shop"); for ($i = 0; $i < count($all); $i += 2) { if ($TargetItemID == $all[$i]) { $chestTile->getInventory()->clearAll(); $suball = $all[$i + 1]; $slot = 0; for ($j = 0; $j < count($suball); $j++) { $chestTile->getInventory()->setItem($slot, Item::get($suball[$j][0], 0, $suball[$j][1])); $slot++; $chestTile->getInventory()->setItem($slot, Item::get($suball[$j][2], 0, $suball[$j][3])); $slot++; } break; } } $chestTile->getInventory()->setItem($chestTile->getInventory()->getSize() - 1, Item::get(Item::WOOL, 14, 1)); } } } } } } }
Last time I checked this wasn't a code correction service. If you want help you need to tell us how its broken or post an error.