49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
abstract class Plugin implements IPluggable
|
|
{
|
|
protected PluginContext $context;
|
|
protected array $config;
|
|
|
|
public function onServerStarted()
|
|
{
|
|
|
|
}
|
|
|
|
public function onSync($remote_config)
|
|
{
|
|
|
|
}
|
|
|
|
public function onInit(PluginContext $context): void
|
|
{
|
|
$this->context = $context;
|
|
$this->checkConfig();
|
|
$this->config = $this->context->getConfig()[$context->getName()];
|
|
}
|
|
|
|
protected function checkConfig(): void
|
|
{
|
|
$config = $this->context->getConfig();
|
|
$defaults = $this->context->getMetadata()["config"];
|
|
$name = $this->context->getName();
|
|
|
|
if (!isset($config[$name])) {
|
|
$config[$name] = $defaults;
|
|
return;
|
|
}
|
|
|
|
foreach ($defaults as $key => $value) {
|
|
if (!isset($config[$name][$key])) {
|
|
$config[$name][$key] = $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function saveConfig()
|
|
{
|
|
$wrapper = $this->context->getConfig();
|
|
$wrapper[$this->context->getName()] = $this->config;
|
|
$wrapper->save();
|
|
}
|
|
} |