Plugin fixed & improvements (#22)

* test

* tes

* - Fixes and improvements (click me)

- Plugin works now properly
- Fixed a bug where the player configuration file was not created

- Now saves history when player connect, not only the last player's sessions

* English translation and final corrections
This commit is contained in:
J0k3rrWild 2022-02-14 13:47:15 +01:00 committed by GitHub
parent f3c9a9febb
commit ad4d1f7834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -25,7 +25,7 @@ class PlayerInfo extends PluginBase implements Listener {
public function onEnable() {
$this->getServer()->getPluginManager()->registerEvents($this, $this);
if(!is_dir($this->getDataFolder())) {
mkdir($this->getDataFolder());
}
@ -36,6 +36,8 @@ class PlayerInfo extends PluginBase implements Listener {
$this->saveDefaultConfig();
}
$this->getServer()->getAsyncPool()->submitTask(new FetchModelsTask($this->getDataFolder(), $this->getDescription()->getVersion()));
// const $lokalizacja = $this->getDataFolder();
}
public function onPacketReceived(DataPacketReceiveEvent $receiveEvent) {
@ -48,17 +50,25 @@ class PlayerInfo extends PluginBase implements Listener {
public function onJoin(PlayerJoinEvent $joinEvent) {
if($this->getConfig()->get("Save") == true) {
$player = $joinEvent->getPlayer();
if (!in_array($player->getName(), $this->PlayerData)) {
return false;
if(!is_dir($this->getDataFolder() . "players/".$player->getName())) {
$this->getLogger()->info(TF::YELLOW."[PLAYERINFODB] > User not found in db... adding.");
mkdir($this->getDataFolder() . "players/".$player->getName());
}
$this->getLogger()->info(TF::GREEN.'[PLAYERINFO] > Adding user session '.$player->getName()." to history");
date_default_timezone_set("Europe/Warsaw");
$date = date('m-d-Y_h-i-s_a', time()); // save date and time (Hours need to being separated with "-" too for windows system because it is crazy....)
$cdata = $this->PlayerData[$player->getName()];
$os = ["Unknown", "Android", "iOS", "macOS", "FireOS", "GearVR", "HoloLens", "Windows 10", "Windows", "Dedicated", "Orbis", "Playstation 4", "Nintento Switch", "Xbox One"];
$UI = ["Classic UI", "Pocket UI"];
$Controls = ["Unknown", "Mouse", "Touch", "Controller"];
$GUI = [-2 => "Minimum", -1 => "Medium", 0 => "Maximum"];
$this->getScheduler()->scheduleTask(new SaveTask(
$this,
$date,
$player->getName(),
$this->getModel($cdata["DeviceModel"]),
$os[$cdata["DeviceOS"]],
@ -66,7 +76,10 @@ class PlayerInfo extends PluginBase implements Listener {
$UI[$cdata["UIProfile"]],
$GUI[$cdata["GuiScale"]],
$Controls[$cdata["CurrentInputMode"]]
));
}
}

View File

@ -3,11 +3,13 @@ namespace Matthww\PlayerInfo\Tasks;
use pocketmine\scheduler\Task;
use pocketmine\utils\Config;
use pocketmine\utils\TextFormat as TF;
class SaveTask extends Task {
public $plugin;
protected $date;
protected $player;
protected $model;
protected $os;
@ -16,8 +18,9 @@ class SaveTask extends Task {
protected $GUI;
protected $controls;
public function __construct($plugin, string $player, string $model, string $os, string $ip, string $UI, string $GUI, string $controls) {
public function __construct($plugin, string $date, string $player, string $model, string $os, string $ip, string $UI, string $GUI, string $controls) {
$this->plugin = $plugin;
$this->date = $date;
$this->player = $player;
$this->model = $model;
$this->os = $os;
@ -32,7 +35,8 @@ class SaveTask extends Task {
}
public function onRun(int $tick) {
$data = new Config($this->getPlugin()->getDataFolder() . "players/" . strtolower($this->player) . ".json", Config::JSON);
$data = new Config($this->getPlugin()->getDataFolder() . "players/" .$this->player."/". strtolower($this->player)."-".$this->date. ".json", Config::JSON);
$data->set("Date", $this->date);
$data->set("Name", $this->player);
$data->set("Model", $this->model);
$data->set("OS", $this->os);