public function onBlockTouch(PlayerInteractEvent $event) { if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) { return; } $player = $event->getPlayer(); $block = $event->getBlock(); $iusername = strtolower($player->getName()); if (isset($this->queue[$iusername])) { $queue = $this->queue[$iusername]; $item = Item::fromString($queue[0]); $item->setCount($queue[1]); $ev = new ShopCreationEvent($block, $item, $queue[2], $queue[3]); $this->getServer()->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { $player->sendMessage($this->getMessage("shop-create-failed")); unset($this->queue[$iusername]); return; } $result = $this->provider->addShop($block, [$block->getX(), $block->getY(), $block->getZ(), $block->getLevel()->getFolderName(), $item->getID(), $item->getDamage(), $item->getName(), $queue[1], $queue[2], $queue[3]]); if ($result) { if ($queue[3] !== -2) { $pos = $block; if ($queue[3] !== -1) { $pos = $block->getSide($queue[3]); } $this->items[$pos->getLevel()->getFolderName()][] = $dis = new ItemDisplayer($pos, $item, $block); $dis->spawnToAll($pos->getLevel()); } $player->sendMessage($this->getMessage("shop-created")); } else { $player->sendMessage($this->getMessage("shop-already-exist")); } if ($event->getItem()->canBePlaced()) { $this->placeQueue[$iusername] = true; } unset($this->queue[$iusername]); return; } elseif (isset($this->removeQueue[$iusername])) { $shop = $this->provider->getShop($block); foreach ($this->items as $level => $arr) { foreach ($arr as $key => $displayer) { $link = $displayer->getLinked(); if ($link->getX() === $shop[0] and $link->getY() === $shop[1] and $link->getZ() === $shop[2] and $link->getLevel()->getFolderName() === $shop[3]) { $displayer->despawnFromAll(); unset($this->items[$key]); break 2; } } } $this->provider->removeShop($block); unset($this->removeQueue[$iusername]); $player->sendMessage($this->getMessage("shop-removed")); if ($event->getItem()->canBePlaced()) { $this->placeQueue[$iusername] = true; } return; } if (($shop = $this->provider->getShop($block)) !== false) { if ($this->getConfig()->get("enable-double-tap")) { $now = time(); if (isset($this->tap[$iusername]) and $now - $this->tap[$iusername] < 1) { $this->buyItem($player, $shop); unset($this->tap[$iusername]); } else { $this->tap[$iusername] = $now; $player->sendMessage($this->getMessage("tap-again", [$shop[7], $shop[6], $shop[8]])); } } else { $this->buyItem($player, $shop); } if ($event->getItem()->canBePlaced()) { $this->placeQueue[$iusername] = true; } } }