public function validateAPIKey()
 {
     // validate api key
     $votingAPIKey = $this->apiKey;
     $url = "http://minecraftpocket-servers.com/api/?object=servers&element=detail";
     $url .= "&key=" . urlencode($votingAPIKey);
     $response_raw = file_get_contents($url);
     $response = json_decode($response_raw);
     if (json_last_error() != JSON_ERROR_NONE) {
         $err = TextFormat::RED . "Could not validate your minecraftpocket-servers.com API key!";
         $err .= " Server response was '" . TextFormat::YELLOW . $response_raw . "'";
         $err .= TextFormat::YELLOW . " key was " . $votingAPIKey;
         $this->plugin->getLogger()->warning($err);
         $this->validatedKey = false;
         return false;
     }
     if (!isset($response->name)) {
         $err = TextFormat::RED . "Could not validate your minecraftpocket-servers.com API key!";
         $err .= " Server response was '" . TextFormat::YELLOW . $response_raw . "'";
         $this->plugin->getLogger()->warning($err);
         $this->validatedKey = false;
         return false;
     }
     $infoMessage = "Voting enabled for " . $response->name;
     $this->plugin->getLogger()->info(TextFormat::GREEN . $infoMessage);
     $this->validatedKey = true;
     return true;
 }
 public function formatForChannels(Message $message)
 {
     if (is_null($message->sender)) {
         return;
     }
     $player = $message->sender;
     $playersPlot = $this->plugin->getPlotByPosition($player->getPosition());
     if ($playersPlot->id == -1) {
         return;
     }
     $message->server_name = "Plot " . $playersPlot->id;
 }
示例#3
0
 public function __construct(MyPlot $plugin)
 {
     $this->plugin = $plugin;
     $this->db = new SQLite3($plugin->getDataFolder() . "plots.db");
     $this->db->exec("CREATE TABLE IF NOT EXISTS plots\n            (id INTEGER PRIMARY KEY AUTOINCREMENT, level TEXT, X INTEGER, Z INTEGER, name TEXT,\n             owner TEXT, helpers TEXT, biome TEXT)");
     //$this->db->exec("CREATE TABLE IF NOT EXISTS comments (plotID INT, player TEXT, comment TEXT)");
     $this->sqlGetPlot = $this->db->prepare("SELECT id, name, owner, helpers, biome FROM plots WHERE level = :level AND X = :X AND Z = :Z");
     $this->sqlSavePlot = $this->db->prepare("INSERT OR REPLACE INTO plots (id, level, X, Z, name, owner, helpers, biome) VALUES\n            ((select id from plots where level = :level AND X = :X AND Z = :Z),\n             :level, :X, :Z, :name, :owner, :helpers, :biome);");
     $this->sqlSavePlotById = $this->db->prepare("UPDATE plots SET name = :name, owner = :owner, helpers = :helpers, name = :name, biome = :biome WHERE id = :id");
     $this->sqlRemovePlot = $this->db->prepare("DELETE FROM plots WHERE level = :level AND X = :X AND Z = :Z");
     $this->sqlRemovePlotById = $this->db->prepare("DELETE FROM plots WHERE id = :id");
     $this->sqlGetPlotsByOwner = $this->db->prepare("SELECT * FROM plots WHERE owner = :owner");
     $this->sqlGetPlotsByOwnerAndLevel = $this->db->prepare("SELECT * FROM plots WHERE owner = :owner AND level = :level");
     $this->sqlGetExistingXZ = $this->db->prepare("SELECT X, Z FROM plots WHERE (\n                level = :level\n                AND abs(X) >= :min AND abs(X) <= :max\n                AND abs(Z) >= :min AND abs(Z) <= :max\n            )");
 }
示例#4
0
 public function onPlayerMove(PlayerMoveEvent $event)
 {
     if (!$this->plugin->getConfig()->get("ShowPlotPopup", true)) {
         return;
     }
     $levelName = $event->getPlayer()->getLevel()->getName();
     if (!$this->plugin->isLevelLoaded($levelName)) {
         return;
     }
     $plot = $this->plugin->getPlotByPosition($event->getTo());
     if ($plot !== null and $plot !== $this->plugin->getPlotByPosition($event->getFrom())) {
         $plotName = TextFormat::GREEN . $plot;
         $popup = $this->plugin->getLanguage()->translateString("popup", [$plotName]);
         if ($plot->owner != "") {
             $owner = TextFormat::GREEN . $plot->owner;
             $ownerPopup = $this->plugin->getLanguage()->translateString("popup.owner", [$owner]);
             $paddingSize = floor((strlen($popup) - strlen($ownerPopup)) / 2);
             $paddingPopup = str_repeat(" ", max(0, -$paddingSize));
             $paddingOwnerPopup = str_repeat(" ", max(0, $paddingSize));
             $popup = TextFormat::WHITE . $paddingPopup . $popup . "\n" . TextFormat::WHITE . $paddingOwnerPopup . $ownerPopup;
         } else {
             $ownerPopup = $this->plugin->getLanguage()->translateString("popup.available");
             $paddingSize = floor((strlen($popup) - strlen($ownerPopup)) / 2);
             $paddingPopup = str_repeat(" ", max(0, -$paddingSize));
             $paddingOwnerPopup = str_repeat(" ", max(0, $paddingSize));
             $popup = TextFormat::WHITE . $paddingPopup . $popup . "\n" . TextFormat::WHITE . $paddingOwnerPopup . $ownerPopup;
         }
         $event->getPlayer()->sendTip($popup);
     }
 }
示例#5
0
 public function execute(CommandSender $sender, $alias, array $args)
 {
     if (!isset($args[0])) {
         $sender->sendMessage(MyPlot::getInstance()->getLanguage()->get("command.usage"));
         return true;
     }
     $subCommand = strtolower(array_shift($args));
     if (isset($this->subCommands[$subCommand])) {
         $command = $this->subCommands[$subCommand];
     } elseif (isset($this->aliasSubCommands[$subCommand])) {
         $command = $this->aliasSubCommands[$subCommand];
     } else {
         $sender->sendMessage(TextFormat::RED . MyPlot::getInstance()->getLanguage()->get("command.unknown"));
         return true;
     }
     if ($command->canUse($sender)) {
         if (!$command->execute($sender, $args)) {
             $usage = MyPlot::getInstance()->getLanguage()->translateString("subcommand.usage", [$command->getUsage()]);
             $sender->sendMessage($usage);
         }
     } else {
         $sender->sendMessage(TextFormat::RED . MyPlot::getInstance()->getLanguage()->get("command.unknown"));
     }
     return true;
 }
示例#6
0
 /**
  * @param BlockPlaceEvent|BlockBreakEvent|PlayerInteractEvent $event
  */
 private function onEventOnBlock($event)
 {
     $levelName = $event->getBlock()->getLevel()->getName();
     if (!$this->plugin->isLevelLoaded($levelName)) {
         return;
     }
     $plot = $this->plugin->getPlotByPosition($event->getBlock());
     if ($plot !== null) {
         $username = $event->getPlayer()->getName();
         if ($plot->owner == $username or $plot->isHelper($username) or $event->getPlayer()->hasPermission("myplot.admin.build.plot")) {
             return;
         }
     } elseif ($event->getPlayer()->hasPermission("myplot.admin.build.road")) {
         return;
     }
     $event->setCancelled(true);
 }
示例#7
0
 /**
  * @param BlockPlaceEvent|BlockBreakEvent|PlayerInteractEvent $event
  */
 private function onEventOnBlock($event)
 {
     $levelName = $event->getBlock()->getLevel()->getName();
     if (!$this->plugin->isLevelLoaded($levelName)) {
         return;
     }
     $block = $event->getBlock();
     if ($block->x == 0 && $block->y == 0 && $block->z == 0) {
         // not sure what fires these events but they happen all the
         // time. Lets cancel the event and ignore them!
         $event->setCancelled(true);
         return;
     }
     $plot = $this->plugin->getPlotByPosition($block);
     if ($plot == null) {
         // this should never get called because plots have been
         // extended to include the road around in this particular
         // fork of MyPlot
         $event->setCancelled(true);
         return;
     }
     $username = $event->getPlayer()->getName();
     $hasRights = ($plot->owner == $username || $plot->isHelper($username)) && !$plot->locked;
     $hasAdmin = !$plot->locked && $event->getPlayer()->hasPermission("myplot.admin.build.plot");
     // even admins must unlock the plot first, great for preventing accidental damage
     $canPlace = $hasRights || $hasAdmin;
     if (!$canPlace) {
         $event->setCancelled(true);
         $ownerWithLock = $plot->owner == $username && $plot->locked;
         $helperWithLock = $plot->isHelper($username) && $plot->locked;
         if ($ownerWithLock) {
             $msg = "Your plot is locked - you may unlock it with /plot unlock";
         } elseif ($helperWithLock) {
             $msg = "This plot is locked by the owner - for owner info use /plot info";
         } else {
             $msg = "This plot does not belong to you and you are not a helper";
         }
         @$event->getPlayer()->sendMessage($msg);
     }
 }
示例#8
0
 /**
  * @param string   $str
  * @param string[] $params
  *
  * @return string
  */
 protected function translateString($str, array $params = [], $onlyPrefix = null)
 {
     return $this->plugin->getLanguage()->translateString($str, $params, $onlyPrefix);
 }