Skip to content

Instantly share code, notes, and snippets.

@Kris-Driv
Created March 19, 2017 14:05
Show Gist options
  • Save Kris-Driv/d585b8fbc202dce8c5dded61102f496f to your computer and use it in GitHub Desktop.
Save Kris-Driv/d585b8fbc202dce8c5dded61102f496f to your computer and use it in GitHub Desktop.
Transfers PurePerms data saved in YAML format to MySQL database
<?php
/**
* @name zPPYML2MySQL
* @author Chris Prime
* @api 3.0.0
* @version 1.0.0
* @main ym\PPYML2MySQL
* @loadafter PurePerms
*/
namespace ym {
use _64FF00\PurePerms\PurePerms;
use _64FF00\PurePerms\provider\MySQLProvider;
use _64FF00\PurePerms\provider\YamlV1Provider;
use pocketmine\OfflinePlayer;
class PPYML2MySQL extends \pocketmine\plugin\PluginBase {
public function onEnable() {
$pp = $this->getServer()->getPluginManager()->getPlugin("PurePerms");
if($pp instanceof PurePerms && $pp->isEnabled()) {
if($pp->getProvider() instanceof MySQLProvider) {
if($this->transfer($pp)) {
$this->getLogger()->notice("Transfer successful");
} else {
$this->getLogger()->notice("Transfer failed");
}
} else {
$this->getLogger()->notice("PurePerms is not using MySQL");
}
} else {
$this->getLogger()->error("PurePerms not enabled");
}
}
public function transfer(PurePerms $pp) : bool {
$pdt = 0;
$gpt = 0;
$p = new YamlV1Provider($pp);
$gpt = count($p->getGroupsData());
$pp->getProvider()->setGroupsData($p->getGroupsData());
$playerFiles = glob($pp->getDataFolder()."players/*.yml");
foreach ($playerFiles as $file) {
$ps = explode("/", $file);
$name = substr($ps[count($ps) - 1], 0, -4);
$op = new OfflinePlayer($this->getServer(), $name);
$pp->getProvider()->setPlayerData($op, $p->getPlayerData($op));
$pdt++;
}
$this->getLogger()->notice("Players transfered: ".$pdt);
$this->getLogger()->notice("Groups transfered: ".$gpt);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment