public function onLevelLoad(LevelLoadEvent $event) { if ($event->getLevel()->getProvider()->getGenerator() === "myplot") { $settings = $event->getLevel()->getProvider()->getGeneratorOptions(); if (isset($settings["preset"]) === false or $settings["preset"] === "") { return; } $settings = json_decode($settings["preset"], true); if ($settings === false) { return; } $levelName = $event->getLevel()->getName(); $filePath = $this->plugin->getDataFolder() . "worlds/" . $levelName . ".yml"; $config = $this->plugin->getConfig(); $default = ["RestrictEntityMovement" => $config->getNested("DefaultWorld.RestrictEntityMovement"), "ClaimPrice" => $config->getNested("DefaultWorld.ClaimPrice"), "ClearPrice" => $config->getNested("DefaultWorld.ClearPrice"), "DisposePrice" => $config->getNested("DefaultWorld.DisposePrice"), "ResetPrice" => $config->getNested("DefaultWorld.ResetPrice")]; $config = new Config($filePath, Config::YAML, $default); foreach (array_keys($default) as $key) { $settings[$key] = $config->get($key); } $this->plugin->addLevelSettings($levelName, new PlotLevelSettings($levelName, $settings)); } }
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 )"); }