Skip to content

Commit

Permalink
Added config-version detect
Browse files Browse the repository at this point in the history
  • Loading branch information
KygekDev committed Aug 4, 2020
1 parent 8d87990 commit ae31ee6
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Kygekraqmak/KygekRulesUI/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,30 @@ class Main extends PluginBase implements Listener {
public function onEnable() {
$this->getServer()->getPluginManager()->registerEvents($this, $this);
@mkdir($this->getDataFolder());
$this->saveDefaultConfig();
$this->getResource("config.yml");
$this->saveResource("config.yml");
if (!$this->getConfig()->exists("config-version")) {
$this->getLogger()->notice("§eYour configuration file is from another version. Updating the Config...");
$this->getLogger()->notice("§eThe old configuration file can be found at config_old.yml");
rename($this->getDataFolder()."config.yml", $this->getDataFolder()."config_old.yml");
$this->saveResource("config.yml");
return;
}
if (version_compare("1.1", $this->getConfig()->get("config-version"))) {
$this->getLogger()->notice("§eYour configuration file is from another version. Updating the Config...");
$this->getLogger()->notice("§eThe old configuration file can be found at config_old.yml");
rename($this->getDataFolder()."config.yml", $this->getDataFolder()."config_old.yml");
$this->saveResource("config.yml");
return;
}
}

public function onCommand(CommandSender $player, Command $cmd, string $label, array $args) : bool {
switch($cmd->getName()) {
switch ($cmd->getName()) {
case "rules":
if(!$player instanceof Player) {
if (!$player instanceof Player) {
$player->sendMessage("[KygekRulesUI] This command only works in game!");
} else {
if(!$player->hasPermission("rules.command")) {
if (!$player->hasPermission("rules.command")) {
$player->sendMessage("[KygekRulesUI] You do not have permission to use this command!");
} else {
$this->getConfig()->reload();
Expand All @@ -61,10 +74,10 @@ public function onCommand(CommandSender $player, Command $cmd, string $label, ar

public function kygekRulesUI($player) {
$form = new SimpleForm(function (Player $player, int $data = null) {
if($data === null){
if ($data === null) {
return true;
}
switch($data){
switch ($data) {
case 0:
break;
}
Expand Down

0 comments on commit ae31ee6

Please sign in to comment.