Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Created April 26, 2020 15:55
Show Gist options
  • Save PJZ9n/614198b41734cbdab1a8405bd60929ed to your computer and use it in GitHub Desktop.
Save PJZ9n/614198b41734cbdab1a8405bd60929ed to your computer and use it in GitHub Desktop.
PluginBaseでConfigを使用する
<?php
declare(strict_types=1);
namespace sample;
use pocketmine\plugin\PluginBase;
class Main extends PluginBase
{
public function onEnable(): void
{
//あらかじめ、resources/config.ymlとしてファイルを置いておく(置かないこともできる)
$this->saveDefaultConfig();//$this->getConfig()でConfigを取得できるようにする
}
public function onDisable(): void
{
$this->saveConfig();//Configをセーブする(必要に応じて)
}
public function foo(): void
{
//適当な処理
echo $this->getConfig()->get("key1") . PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment