public function onBlockTouch(PlayerInteractEvent $event) { if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) { return; } $block = $event->getBlock(); $player = $event->getPlayer(); if (isset($this->touch[$player->getName()])) { // $mergeData[$player->getName()][0] = [(int)$block->getX(), (int)$block->getZ(), $block->getLevel()->getName()]; $this->command->mergePosition($player->getName(), 0, [(int) $block->getX(), (int) $block->getZ(), $block->getLevel()->getFolderName()]); $player->sendMessage("[EconomyProperty] First position has been saved."); $event->setCancelled(true); if ($event->getItem()->canBePlaced()) { $this->placeQueue[$player->getName()] = true; } return; } $info = $this->property->query("SELECT * FROM Property WHERE startX <= {$block->getX()} AND landX >= {$block->getX()} AND startZ <= {$block->getZ()} AND landZ >= {$block->getZ()} AND level = '{$block->getLevel()->getName()}'")->fetchArray(SQLITE3_ASSOC); if (!is_bool($info)) { if (!($info["x"] === $block->getX() and $info["y"] === $block->getY() and $info["z"] === $block->getZ())) { if ($player->hasPermission("economyproperty.property.modify") === false) { $event->setCancelled(true); if ($event->getItem()->canBePlaced()) { $this->placeQueue[$player->getName()] = true; } $player->sendMessage("You don't have permission to modify property area."); return; } else { return; } } $level = $block->getLevel(); $tile = $level->getTile($block); if (!$tile instanceof Sign) { $this->property->exec("DELETE FROM Property WHERE landNum = {$info['landNum']}"); return; } $now = time(); if (isset($this->tap[$player->getName()]) and $this->tap[$player->getName()][0] === $block->x . ":" . $block->y . ":" . $block->z and $now - $this->tap[$player->getName()][1] <= 2) { if (EconomyAPI::getInstance()->myMoney($player) < $info["price"]) { $player->sendMessage("You don't have enough money to buy here."); return; } else { $result = EconomyLand::getInstance()->addLand($player->getName(), $info["startX"], $info["startZ"], $info["landX"], $info["landZ"], $info["level"], $info["rentTime"]); switch ($result) { case EconomyLand::RET_SUCCESS: EconomyAPI::getInstance()->reduceMoney($player, $info["price"], true, "EconomyProperty"); $player->sendMessage("Successfully bought land."); $this->property->exec("DELETE FROM Property WHERE landNum = {$info['landNum']}"); break; case EconomyLand::RET_LAND_OVERLAP: $player->sendMessage("[EconomyProperty] Failed to buy the land because the land is trying to overlap."); return; case EconomyLand::RET_LAND_LIMIT: $player->sendMessage("[EconomyProperty] Failed to buy the land due to land limitation."); return; } } $tile->close(); $level->setBlock($block, new Air()); unset($this->tap[$player->getName()]); } else { $this->tap[$player->getName()] = array($block->x . ":" . $block->y . ":" . $block->z, $now); $player->sendMessage("[EconomyProperty] Are you sure to buy here? Tap again to confirm."); $event->setCancelled(true); if ($event->getItem()->canBePlaced()) { $this->placeQueue[$player->getName()] = true; } } } }
public function registerArea($first, $sec, $level, $price, $expectedY = 64, $rentTime = null, $expectedYaw = 0) { if (!$level instanceof Level) { $level = $this->getServer()->getLevelByName($level); if (!$level instanceof Level) { return false; } } $expectedY = round($expectedY); if ($first[0] > $sec[0]) { $tmp = $first[0]; $first[0] = $sec[0]; $sec[0] = $tmp; } if ($first[1] > $sec[1]) { $tmp = $first[1]; $first[1] = $sec[1]; $sec[1] = $tmp; } if ($this->checkOverlapping($first, $sec, $level)) { return false; } if (EconomyLand::getInstance()->checkOverlap($first[0], $sec[0], $first[1], $sec[1], $level)) { return false; } $price = round($price, 2); $centerx = (int) ($first[0] + round(($sec[0] - $first[0]) / 2)); $centerz = (int) ($first[1] + round(($sec[1] - $first[1]) / 2)); $x = (int) round($sec[0] - $first[0]); $z = (int) round($sec[1] - $first[1]); $y = 0; $diff = 256; $tmpY = 0; $lastBlock = 0; for (; $y < 127; $y++) { $b = $level->getBlock(new Vector3($centerx, $y, $centerz)); $id = $b->getID(); $difference = abs($expectedY - $y); if ($difference > $diff) { // Finding the closest location with player or something $y = $tmpY; break; } else { if ($id === 0 and $lastBlock !== 0 or $b->canBeReplaced()) { $tmpY = $y; $diff = $difference; } } $lastBlock = $id; } if ($y >= 126) { $y = $expectedY; } $meta = floor(($expectedYaw + 180) * 16 / 360 + 0.5) & 0xf; $level->setBlock(new Position($centerx, $y, $centerz, $level), Block::get(Item::SIGN_POST, $meta)); $info = $this->property->query("SELECT seq FROM sqlite_sequence")->fetchArray(SQLITE3_ASSOC); $tile = new Sign($level->getChunk($centerx >> 4, $centerz >> 4, false), new CompoundTag(false, ["id" => new StringTag("id", Tile::SIGN), "x" => new IntTag("x", $centerx), "y" => new IntTag("y", $y), "z" => new IntTag("z", $centerz), "Text1" => new StringTag("Text1", ""), "Text2" => new StringTag("Text2", ""), "Text3" => new StringTag("Text3", ""), "Text4" => new StringTag("Text4", "")])); $tile->setText($rentTime === null ? "[PROPERTY]" : "[RENT]", "Price : {$price}", "Blocks : " . $x * $z * 128, $rentTime === null ? "Property #" . $info["seq"] : "Time : " . $rentTime . "min"); $this->property->exec("INSERT INTO Property (price, x, y, z, level, startX, startZ, landX, landZ" . ($rentTime === null ? "" : ", rentTime") . ") VALUES ({$price}, {$centerx}, {$y}, {$centerz}, '{$level->getName()}', {$first['0']}, {$first['1']}, {$sec['0']}, {$sec['1']}" . ($rentTime === null ? "" : ", {$rentTime}") . ")"); return [$centerx, $y, $centerz]; }