SquadJS/squad-server/plugins/base-plugin.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-11-10 07:04:38 -06:00
import Logger from 'core/logger';
2020-10-05 12:52:01 -05:00
export default class BasePlugin {
2020-12-03 08:16:07 -06:00
constructor(server, options, connectors) {
this.server = server;
this.options = {};
this.rawOptions = options;
for (const [optionName, option] of Object.entries(this.constructor.optionsSpecification)) {
if (option.connector) {
this.options[optionName] = connectors[this.rawOptions[optionName]];
} else {
if (option.required) {
2020-12-06 15:23:05 -06:00
if (!(optionName in this.rawOptions))
throw new Error(`${this.constructor.name}: ${optionName} is required but missing.`);
if (option.default === this.rawOptions[optionName])
throw new Error(
`${this.constructor.name}: ${optionName} is required but is the default value.`
);
2020-12-03 08:16:07 -06:00
}
2020-12-08 10:40:56 -06:00
this.options[optionName] = typeof this.rawOptions[optionName] !== 'undefined' ? this.rawOptions[optionName] : option.default;
2020-12-03 08:16:07 -06:00
}
}
}
async prepareToMount() {}
2020-12-08 06:13:53 -06:00
async mount() {}
2020-12-03 08:16:07 -06:00
2020-12-08 06:13:53 -06:00
async unmount() {}
2020-12-03 08:16:07 -06:00
2020-10-05 12:52:01 -05:00
static get description() {
throw new Error('Plugin missing "static get description()" method.');
}
static get defaultEnabled() {
throw new Error('Plugin missing "static get defaultEnabled()" method.');
}
static get optionsSpecification() {
throw new Error('Plugin missing "static get optionSpecification()" method.');
}
2020-10-23 05:18:23 -05:00
2020-11-10 07:04:38 -06:00
verbose(...args) {
Logger.verbose(this.constructor.name, ...args);
}
2020-12-06 15:23:05 -06:00
}