public function __construct(PluginBase $owner) { $path = $owner->getDataFolder() . "stats.sqlite3"; $this->database = new \SQLite3($path); $sql = "CREATE TABLE IF NOT EXISTS Scores (\n\t\t\tplayer TEXT NOT NULL,\n\t\t\ttype TEXT NOT NULL,\n\t\t\tcount INTEGER NOT NULL,\n\t\t\tPRIMARY KEY (player,type)\n\t\t)"; $this->database->exec($sql); }
public function __construct(Plugin $plugin, $xfg) { $this->owner = $plugin; $this->keepers = []; $cfg = (new Config($plugin->getDataFolder() . "shops.yml", Config::YAML))->getAll(); $this->state = []; foreach ($cfg as $i => $j) { $this->keepers[$i] = []; if (isset($j["messages"])) { $this->keepers[$i]["messages"] = $j["messages"]; } else { $this->keepers[$i]["messages"] = []; } $this->keepers[$i]["attack"] = isset($j["attack"]) ? $j["attack"] : 5; $this->keepers[$i]["slim"] = isset($j["slim"]) ? $j["slim"] : false; $this->keepers[$i]["displayName"] = isset($j["display"]) ? $j["display"] : "default"; // Load the skin in memory if (is_file($plugin->getDataFolder() . $j["skin"])) { $this->keepers[$i]["skin"] = zlib_decode(file_get_contents($plugin->getDataFolder() . $j["skin"])); } else { $this->keepers[$i]["skin"] = null; } if (isset($cfg[$i]["msgs"])) { $this->keepers[$i]["msgs"] = $cfg[$i]["msgs"]; } $items = isset($cfg[$i]["items"]) && $cfg[$i]["items"] ? $cfg[$i]["items"] : ["IRON_SWORD,2", "APPLE,10,1"]; $this->keepers[$i]["items"] = []; foreach ($items as $n) { $t = explode(",", $n); if (count($t) < 2 || count($t) > 3) { $plugin->getLogger()->error(mc::_("Item error: %1%", $n)); continue; } $item = Item::fromString(array_shift($t)); if ($item->getId() == Item::AIR) { $plugin->getLogger()->error(mc::_("Unknown Item error: %1%", $n)); continue; } $price = intval(array_pop($t)); if ($price <= 0) { $plugin->getLogger()->error(mc::_("Invalid price: %1%", $n)); continue; } if (count($t)) { $qty = intval($t[0]); if ($qty <= 0 || $qty >= $item->getMaxStackSize()) { $plugin->getLogger()->error(mc::_("Bad quantity: %1%", $n)); continue; } $item->setCount($qty); } echo "Item: " . $item->getId() . "," . $item->getCount() . "\n"; //##DEBUG $this->keepers[$i]["items"][implode(":", [$item->getId(), $item->getDamage()])] = [$item, $price]; } if (count($this->keepers[$i]["items"])) { continue; } $plugin->getLogger()->error(mc::_("ShopKeep %1% disabled!", $i)); unset($this->keepers[$i]); continue; } if (count($this->keepers) == 0) { $plugin->getLogger()->error(mc::_("No shopkeepers found!")); $this->keepers = null; return; } Entity::registerEntity(TraderNpc::class, true); $this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner); $this->owner->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($this->owner, [$this, "spamPlayers"], [$xfg["range"], $xfg["freq"]]), $xfg["ticks"]); }